Skip to content

Commit 27f06dd

Browse files
authored
[NFC][IR2Vec] Change getSlotIndex parameter from Value* to Value& (#155700)
1 parent 62232e8 commit 27f06dd

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

llvm/include/llvm/Analysis/IR2Vec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class Vocabulary {
227227
/// or OperandKind in the vocabulary.
228228
LLVM_ABI static unsigned getSlotIndex(unsigned Opcode);
229229
LLVM_ABI static unsigned getSlotIndex(Type::TypeID TypeID);
230-
LLVM_ABI static unsigned getSlotIndex(const Value *Op);
230+
LLVM_ABI static unsigned getSlotIndex(const Value &Op);
231231

232232
/// Accessors to get the embedding for a given entity.
233233
LLVM_ABI const ir2vec::Embedding &operator[](unsigned Opcode) const;

llvm/lib/Analysis/IR2Vec.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ unsigned Vocabulary::getSlotIndex(Type::TypeID TypeID) {
282282
return MaxOpcodes + static_cast<unsigned>(getCanonicalTypeID(TypeID));
283283
}
284284

285-
unsigned Vocabulary::getSlotIndex(const Value *Op) {
286-
unsigned Index = static_cast<unsigned>(getOperandKind(Op));
285+
unsigned Vocabulary::getSlotIndex(const Value &Op) {
286+
unsigned Index = static_cast<unsigned>(getOperandKind(&Op));
287287
assert(Index < MaxOperandKinds && "Invalid OperandKind");
288288
return MaxOpcodes + MaxCanonicalTypeIDs + Index;
289289
}
@@ -297,7 +297,7 @@ const Embedding &Vocabulary::operator[](Type::TypeID TypeID) const {
297297
}
298298

299299
const ir2vec::Embedding &Vocabulary::operator[](const Value &Arg) const {
300-
return Vocab[getSlotIndex(&Arg)];
300+
return Vocab[getSlotIndex(Arg)];
301301
}
302302

303303
StringRef Vocabulary::getVocabKeyForOpcode(unsigned Opcode) {

llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class IR2VecTool {
184184
// Add "Arg" relationships
185185
unsigned ArgIndex = 0;
186186
for (const Use &U : I.operands()) {
187-
unsigned OperandID = Vocabulary::getSlotIndex(U.get());
187+
unsigned OperandID = Vocabulary::getSlotIndex(*U);
188188
unsigned RelationID = ArgRelation + ArgIndex;
189189
OS << Opcode << '\t' << OperandID << '\t' << RelationID << '\n';
190190

llvm/unittests/Analysis/IR2VecTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,23 +507,23 @@ TEST(IR2VecVocabularyTest, SlotIdxMapping) {
507507
#define EXPECTED_VOCAB_OPERAND_SLOT(X) \
508508
MaxOpcodes + MaxCanonicalTypeIDs + static_cast<unsigned>(X)
509509
// Test Function operand
510-
EXPECT_EQ(Vocabulary::getSlotIndex(F),
510+
EXPECT_EQ(Vocabulary::getSlotIndex(*F),
511511
EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::FunctionID));
512512

513513
// Test Constant operand
514514
Constant *C = ConstantInt::get(Type::getInt32Ty(Ctx), 42);
515-
EXPECT_EQ(Vocabulary::getSlotIndex(C),
515+
EXPECT_EQ(Vocabulary::getSlotIndex(*C),
516516
EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::ConstantID));
517517

518518
// Test Pointer operand
519519
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);
520520
AllocaInst *PtrVal = new AllocaInst(Type::getInt32Ty(Ctx), 0, "ptr", BB);
521-
EXPECT_EQ(Vocabulary::getSlotIndex(PtrVal),
521+
EXPECT_EQ(Vocabulary::getSlotIndex(*PtrVal),
522522
EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::PointerID));
523523

524524
// Test Variable operand (function argument)
525525
Argument *Arg = F->getArg(0);
526-
EXPECT_EQ(Vocabulary::getSlotIndex(Arg),
526+
EXPECT_EQ(Vocabulary::getSlotIndex(*Arg),
527527
EXPECTED_VOCAB_OPERAND_SLOT(Vocabulary::OperandKind::VariableID));
528528
#undef EXPECTED_VOCAB_OPERAND_SLOT
529529
}

0 commit comments

Comments
 (0)