Skip to content

Conversation

svkeerthy
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@svkeerthy svkeerthy changed the title Change [NFC][IR2Vec] Change getSlotIndex parameter from Value* to Value& Aug 27, 2025
@svkeerthy svkeerthy marked this pull request as ready for review August 27, 2025 21:22
@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Aug 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-analysis

Author: S. VenkataKeerthy (svkeerthy)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/155700.diff

3 Files Affected:

  • (modified) llvm/include/llvm/Analysis/IR2Vec.h (+1-1)
  • (modified) llvm/lib/Analysis/IR2Vec.cpp (+3-3)
  • (modified) llvm/unittests/Analysis/IR2VecTest.cpp (+4-4)
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h
index c42ca779e097c..d9a07f73a4068 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -227,7 +227,7 @@ class Vocabulary {
   /// or OperandKind in the vocabulary.
   LLVM_ABI static unsigned getSlotIndex(unsigned Opcode);
   LLVM_ABI static unsigned getSlotIndex(Type::TypeID TypeID);
-  LLVM_ABI static unsigned getSlotIndex(const Value *Op);
+  LLVM_ABI static unsigned getSlotIndex(const Value &Op);
 
   /// Accessors to get the embedding for a given entity.
   LLVM_ABI const ir2vec::Embedding &operator[](unsigned Opcode) const;
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 565ec2a6287b7..21dc2e6530d2c 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -282,8 +282,8 @@ unsigned Vocabulary::getSlotIndex(Type::TypeID TypeID) {
   return MaxOpcodes + static_cast<unsigned>(getCanonicalTypeID(TypeID));
 }
 
-unsigned Vocabulary::getSlotIndex(const Value *Op) {
-  unsigned Index = static_cast<unsigned>(getOperandKind(Op));
+unsigned Vocabulary::getSlotIndex(const Value &Op) {
+  unsigned Index = static_cast<unsigned>(getOperandKind(&Op));
   assert(Index < MaxOperandKinds && "Invalid OperandKind");
   return MaxOpcodes + MaxCanonicalTypeIDs + Index;
 }
@@ -297,7 +297,7 @@ const Embedding &Vocabulary::operator[](Type::TypeID TypeID) const {
 }
 
 const ir2vec::Embedding &Vocabulary::operator[](const Value &Arg) const {
-  return Vocab[getSlotIndex(&Arg)];
+  return Vocab[getSlotIndex(Arg)];
 }
 
 StringRef Vocabulary::getVocabKeyForOpcode(unsigned Opcode) {
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index 9f5428758d64c..9c106329b2195 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -507,23 +507,23 @@ TEST(IR2VecVocabularyTest, SlotIdxMapping) {
 #define EXPECTED_VOCAB_OPERAND_SLOT(X)                                         \
   MaxOpcodes + MaxCanonicalTypeIDs + static_cast<unsigned>(X)
   // Test Function operand
-  EXPECT_EQ(Vocabulary::getSlotIndex(F),
+  EXPECT_EQ(Vocabulary::getSlotIndex(*F),
             EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::FunctionID));
 
   // Test Constant operand
   Constant *C = ConstantInt::get(Type::getInt32Ty(Ctx), 42);
-  EXPECT_EQ(Vocabulary::getSlotIndex(C),
+  EXPECT_EQ(Vocabulary::getSlotIndex(*C),
             EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::ConstantID));
 
   // Test Pointer operand
   BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);
   AllocaInst *PtrVal = new AllocaInst(Type::getInt32Ty(Ctx), 0, "ptr", BB);
-  EXPECT_EQ(Vocabulary::getSlotIndex(PtrVal),
+  EXPECT_EQ(Vocabulary::getSlotIndex(*PtrVal),
             EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::PointerID));
 
   // Test Variable operand (function argument)
   Argument *Arg = F->getArg(0);
-  EXPECT_EQ(Vocabulary::getSlotIndex(Arg),
+  EXPECT_EQ(Vocabulary::getSlotIndex(*Arg),
             EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::VariableID));
 #undef EXPECTED_VOCAB_OPERAND_SLOT
 }

@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-change branch from 0a36370 to 1ad2eb0 Compare August 27, 2025 21:23
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-25-canonicalized_type branch from fe1463e to d70182f Compare August 28, 2025 19:59
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-change branch 2 times, most recently from e788f65 to c783a53 Compare August 28, 2025 23:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-25-canonicalized_type branch from d70182f to 01b9019 Compare August 28, 2025 23:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-25-canonicalized_type branch from 01b9019 to 2fd070b Compare August 28, 2025 23:53
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-change branch 2 times, most recently from bcff777 to bd7c537 Compare August 29, 2025 00:37
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-25-canonicalized_type branch 2 times, most recently from 2dd49e7 to a73389b Compare August 29, 2025 18:51
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-change branch from bd7c537 to dc257e4 Compare August 29, 2025 18:53
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-25-canonicalized_type branch from a73389b to 3c6e312 Compare August 29, 2025 20:07
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-change branch from dc257e4 to 49b6cf1 Compare August 29, 2025 20:09
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-25-canonicalized_type branch from 3c6e312 to 1f5c4ac Compare August 29, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding mlgo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants