[llvm-branch-commits] [llvm] [MIR2Vec] Handle Operands (PR #163281)

Mircea Trofin via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Oct 15 07:22:44 PDT 2025


================
@@ -122,22 +155,74 @@ unsigned MIRVocabulary::getCanonicalOpcodeIndex(unsigned Opcode) const {
   return getCanonicalIndexForBaseName(BaseOpcode);
 }
 
+unsigned
+MIRVocabulary::getCanonicalIndexForOperandName(StringRef OperandName) const {
+  auto It = std::find(std::begin(CommonOperandNames),
+                      std::end(CommonOperandNames), OperandName);
+  assert(It != std::end(CommonOperandNames) &&
+         "Operand name not found in common operands");
+  return Layout.CommonOperandBase +
+         std::distance(std::begin(CommonOperandNames), It);
+}
+
+unsigned
+MIRVocabulary::getCanonicalIndexForRegisterName(StringRef RegName,
+                                                bool IsPhysical) const {
+  auto It = std::find(RegisterOperandNames.begin(), RegisterOperandNames.end(),
+                      RegName);
+  assert(It != RegisterOperandNames.end() &&
+         "Register name not found in register operands");
+  unsigned LocalIndex = std::distance(RegisterOperandNames.begin(), It);
+  return (IsPhysical ? Layout.PhyRegBase : Layout.VirtRegBase) + LocalIndex;
+}
+
 std::string MIRVocabulary::getStringKey(unsigned Pos) const {
----------------
mtrofin wrote:

why is this returning a copy?

https://github.com/llvm/llvm-project/pull/163281


More information about the llvm-branch-commits mailing list