Skip to content

[NFC][TableGen] Use StringRef in X86RecognizableInstr #139648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented May 13, 2025

  • Use StringRef instead of std::string in several functions.
  • Fix some variable names to conform to LLVM coding standard.
  • Use llvm::function_ref instead of function pointer for handleOperand argument.

@jurahul jurahul marked this pull request as ready for review May 13, 2025 05:22
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-backend-x86

Author: Rahul Joshi (jurahul)

Changes
  • Use StringRef instead of std::string in several functions.
  • Fix some variable names to conform to LLVM coding standard.

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

2 Files Affected:

  • (modified) llvm/utils/TableGen/X86RecognizableInstr.cpp (+30-36)
  • (modified) llvm/utils/TableGen/X86RecognizableInstr.h (+14-16)
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.cpp b/llvm/utils/TableGen/X86RecognizableInstr.cpp
index 402fc93703228..9e49ac2ad8377 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.cpp
+++ b/llvm/utils/TableGen/X86RecognizableInstr.cpp
@@ -440,8 +440,7 @@ void RecognizableInstr::adjustOperandEncoding(OperandEncoding &encoding) {
 void RecognizableInstr::handleOperand(
     bool optional, unsigned &operandIndex, unsigned &physicalOperandIndex,
     unsigned numPhysicalOperands, const unsigned *operandMapping,
-    OperandEncoding (*encodingFromString)(const std::string &,
-                                          uint8_t OpSize)) {
+    OperandEncoding (*encodingFromString)(StringRef, uint8_t OpSize)) {
   if (optional) {
     if (physicalOperandIndex >= numPhysicalOperands)
       return;
@@ -458,12 +457,12 @@ void RecognizableInstr::handleOperand(
 
   StringRef typeName = (*Operands)[operandIndex].Rec->getName();
 
-  OperandEncoding encoding = encodingFromString(typeName.str(), OpSize);
+  OperandEncoding encoding = encodingFromString(typeName, OpSize);
   // Adjust the encoding type for an operand based on the instruction.
   adjustOperandEncoding(encoding);
   Spec->operands[operandIndex].encoding = encoding;
   Spec->operands[operandIndex].type =
-      typeFromString(typeName.str(), HasREX_W, OpSize);
+      typeFromString(typeName, HasREX_W, OpSize);
 
   ++operandIndex;
   ++physicalOperandIndex;
@@ -1020,11 +1019,11 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
 #undef MAP
 }
 
-#define TYPE(str, type)                                                        \
-  if (s == str)                                                                \
-    return type;
-OperandType RecognizableInstr::typeFromString(const std::string &s,
-                                              bool hasREX_W, uint8_t OpSize) {
+#define TYPE(Expected, Type)                                                   \
+  if (Str == Expected)                                                         \
+    return Type;
+OperandType RecognizableInstr::typeFromString(StringRef Str, bool hasREX_W,
+                                              uint8_t OpSize) {
   if (hasREX_W) {
     // For instructions with a REX_W prefix, a declared 32-bit register encoding
     // is special.
@@ -1163,17 +1162,16 @@ OperandType RecognizableInstr::typeFromString(const std::string &s,
   TYPE("BNDR", TYPE_BNDR)
   TYPE("TILE", TYPE_TMM)
   TYPE("TILEPair", TYPE_TMM_PAIR)
-  errs() << "Unhandled type string " << s << "\n";
+  errs() << "Unhandled type string " << Str << "\n";
   llvm_unreachable("Unhandled type string");
 }
 #undef TYPE
 
-#define ENCODING(str, encoding)                                                \
-  if (s == str)                                                                \
-    return encoding;
-OperandEncoding
-RecognizableInstr::immediateEncodingFromString(const std::string &s,
-                                               uint8_t OpSize) {
+#define ENCODING(Expected, Encoding)                                           \
+  if (Str == Expected)                                                         \
+    return Encoding;
+OperandEncoding RecognizableInstr::immediateEncodingFromString(StringRef Str,
+                                                               uint8_t OpSize) {
   if (OpSize != X86Local::OpSize16) {
     // For instructions without an OpSize prefix, a declared 16-bit register or
     // immediate encoding is special.
@@ -1208,13 +1206,12 @@ RecognizableInstr::immediateEncodingFromString(const std::string &s,
   ENCODING("VR256X", ENCODING_IB)
   ENCODING("VR512", ENCODING_IB)
   ENCODING("TILE", ENCODING_IB)
-  errs() << "Unhandled immediate encoding " << s << "\n";
+  errs() << "Unhandled immediate encoding " << Str << "\n";
   llvm_unreachable("Unhandled immediate encoding");
 }
 
 OperandEncoding
-RecognizableInstr::rmRegisterEncodingFromString(const std::string &s,
-                                                uint8_t OpSize) {
+RecognizableInstr::rmRegisterEncodingFromString(StringRef Str, uint8_t OpSize) {
   ENCODING("RST", ENCODING_FP)
   ENCODING("RSTi", ENCODING_FP)
   ENCODING("GR16", ENCODING_RM)
@@ -1245,13 +1242,12 @@ RecognizableInstr::rmRegisterEncodingFromString(const std::string &s,
   ENCODING("BNDR", ENCODING_RM)
   ENCODING("TILE", ENCODING_RM)
   ENCODING("TILEPair", ENCODING_RM)
-  errs() << "Unhandled R/M register encoding " << s << "\n";
+  errs() << "Unhandled R/M register encoding " << Str << "\n";
   llvm_unreachable("Unhandled R/M register encoding");
 }
 
 OperandEncoding
-RecognizableInstr::roRegisterEncodingFromString(const std::string &s,
-                                                uint8_t OpSize) {
+RecognizableInstr::roRegisterEncodingFromString(StringRef Str, uint8_t OpSize) {
   ENCODING("GR16", ENCODING_REG)
   ENCODING("GR16orGR32orGR64", ENCODING_REG)
   ENCODING("GR32", ENCODING_REG)
@@ -1295,12 +1291,12 @@ RecognizableInstr::roRegisterEncodingFromString(const std::string &s,
   ENCODING("BNDR", ENCODING_REG)
   ENCODING("TILE", ENCODING_REG)
   ENCODING("TILEPair", ENCODING_REG)
-  errs() << "Unhandled reg/opcode register encoding " << s << "\n";
+  errs() << "Unhandled reg/opcode register encoding " << Str << "\n";
   llvm_unreachable("Unhandled reg/opcode register encoding");
 }
 
 OperandEncoding
-RecognizableInstr::vvvvRegisterEncodingFromString(const std::string &s,
+RecognizableInstr::vvvvRegisterEncodingFromString(StringRef Str,
                                                   uint8_t OpSize) {
   ENCODING("GR8", ENCODING_VVVV)
   ENCODING("GR16", ENCODING_VVVV)
@@ -1326,12 +1322,12 @@ RecognizableInstr::vvvvRegisterEncodingFromString(const std::string &s,
   ENCODING("VK64", ENCODING_VVVV)
   ENCODING("TILE", ENCODING_VVVV)
   ENCODING("TILEPair", ENCODING_VVVV)
-  errs() << "Unhandled VEX.vvvv register encoding " << s << "\n";
+  errs() << "Unhandled VEX.vvvv register encoding " << Str << "\n";
   llvm_unreachable("Unhandled VEX.vvvv register encoding");
 }
 
 OperandEncoding
-RecognizableInstr::writemaskRegisterEncodingFromString(const std::string &s,
+RecognizableInstr::writemaskRegisterEncodingFromString(StringRef Str,
                                                        uint8_t OpSize) {
   ENCODING("VK1WM", ENCODING_WRITEMASK)
   ENCODING("VK2WM", ENCODING_WRITEMASK)
@@ -1340,13 +1336,12 @@ RecognizableInstr::writemaskRegisterEncodingFromString(const std::string &s,
   ENCODING("VK16WM", ENCODING_WRITEMASK)
   ENCODING("VK32WM", ENCODING_WRITEMASK)
   ENCODING("VK64WM", ENCODING_WRITEMASK)
-  errs() << "Unhandled mask register encoding " << s << "\n";
+  errs() << "Unhandled mask register encoding " << Str << "\n";
   llvm_unreachable("Unhandled mask register encoding");
 }
 
-OperandEncoding
-RecognizableInstr::memoryEncodingFromString(const std::string &s,
-                                            uint8_t OpSize) {
+OperandEncoding RecognizableInstr::memoryEncodingFromString(StringRef Str,
+                                                            uint8_t OpSize) {
   ENCODING("i16mem", ENCODING_RM)
   ENCODING("i32mem", ENCODING_RM)
   ENCODING("i64mem", ENCODING_RM)
@@ -1384,13 +1379,12 @@ RecognizableInstr::memoryEncodingFromString(const std::string &s,
   ENCODING("vy64xmem", ENCODING_VSIB)
   ENCODING("vz32mem", ENCODING_VSIB)
   ENCODING("vz64mem", ENCODING_VSIB)
-  errs() << "Unhandled memory encoding " << s << "\n";
+  errs() << "Unhandled memory encoding " << Str << "\n";
   llvm_unreachable("Unhandled memory encoding");
 }
 
 OperandEncoding
-RecognizableInstr::relocationEncodingFromString(const std::string &s,
-                                                uint8_t OpSize) {
+RecognizableInstr::relocationEncodingFromString(StringRef Str, uint8_t OpSize) {
   if (OpSize != X86Local::OpSize16) {
     // For instructions without an OpSize prefix, a declared 16-bit register or
     // immediate encoding is special.
@@ -1434,19 +1428,19 @@ RecognizableInstr::relocationEncodingFromString(const std::string &s,
   ENCODING("dstidx16", ENCODING_DI)
   ENCODING("dstidx32", ENCODING_DI)
   ENCODING("dstidx64", ENCODING_DI)
-  errs() << "Unhandled relocation encoding " << s << "\n";
+  errs() << "Unhandled relocation encoding " << Str << "\n";
   llvm_unreachable("Unhandled relocation encoding");
 }
 
 OperandEncoding
-RecognizableInstr::opcodeModifierEncodingFromString(const std::string &s,
+RecognizableInstr::opcodeModifierEncodingFromString(StringRef Str,
                                                     uint8_t OpSize) {
   ENCODING("GR32", ENCODING_Rv)
   ENCODING("GR64", ENCODING_RO)
   ENCODING("GR16", ENCODING_Rv)
   ENCODING("GR8", ENCODING_RB)
   ENCODING("ccode", ENCODING_CC)
-  errs() << "Unhandled opcode modifier encoding " << s << "\n";
+  errs() << "Unhandled opcode modifier encoding " << Str << "\n";
   llvm_unreachable("Unhandled opcode modifier encoding");
 }
 #undef ENCODING
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.h b/llvm/utils/TableGen/X86RecognizableInstr.h
index eb2cee7bbbf87..8f28aedb235b8 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.h
+++ b/llvm/utils/TableGen/X86RecognizableInstr.h
@@ -281,7 +281,7 @@ class RecognizableInstr : public RecognizableInstrBase {
   ///                         If register size does not match OpSize, then
   ///                         register sizes keep their size.
   /// @return               - The operand's type.
-  static OperandType typeFromString(const std::string &s, bool hasREX_W,
+  static OperandType typeFromString(StringRef Str, bool hasREX_W,
                                     uint8_t OpSize);
 
   /// immediateEncodingFromString - Translates an immediate encoding from the
@@ -292,28 +292,28 @@ class RecognizableInstr : public RecognizableInstrBase {
   /// @param OpSize  - Indicates whether this is an OpSize16 instruction.
   ///                  If it is not, then 16-bit immediate operands stay 16-bit.
   /// @return        - The operand's encoding.
-  static OperandEncoding immediateEncodingFromString(const std::string &s,
+  static OperandEncoding immediateEncodingFromString(StringRef Str,
                                                      uint8_t OpSize);
 
   /// rmRegisterEncodingFromString - Like immediateEncodingFromString, but
   ///   handles operands that are in the REG field of the ModR/M byte.
-  static OperandEncoding rmRegisterEncodingFromString(const std::string &s,
+  static OperandEncoding rmRegisterEncodingFromString(StringRef Str,
                                                       uint8_t OpSize);
 
   /// rmRegisterEncodingFromString - Like immediateEncodingFromString, but
   ///   handles operands that are in the REG field of the ModR/M byte.
-  static OperandEncoding roRegisterEncodingFromString(const std::string &s,
+  static OperandEncoding roRegisterEncodingFromString(StringRef Str,
                                                       uint8_t OpSize);
-  static OperandEncoding memoryEncodingFromString(const std::string &s,
+  static OperandEncoding memoryEncodingFromString(StringRef Str,
                                                   uint8_t OpSize);
-  static OperandEncoding relocationEncodingFromString(const std::string &s,
+  static OperandEncoding relocationEncodingFromString(StringRef Str,
                                                       uint8_t OpSize);
-  static OperandEncoding opcodeModifierEncodingFromString(const std::string &s,
+  static OperandEncoding opcodeModifierEncodingFromString(StringRef Str,
                                                           uint8_t OpSize);
-  static OperandEncoding vvvvRegisterEncodingFromString(const std::string &s,
+  static OperandEncoding vvvvRegisterEncodingFromString(StringRef Str,
                                                         uint8_t OpSize);
-  static OperandEncoding
-  writemaskRegisterEncodingFromString(const std::string &s, uint8_t OpSize);
+  static OperandEncoding writemaskRegisterEncodingFromString(StringRef Str,
+                                                             uint8_t OpSize);
 
   /// Adjust the encoding type for an operand based on the instruction.
   void adjustOperandEncoding(OperandEncoding &encoding);
@@ -336,12 +336,10 @@ class RecognizableInstr : public RecognizableInstrBase {
   /// @param operandMapping       - The operand mapping, which has an entry for
   ///                               each operand that indicates whether it is a
   ///                               duplicate, and of what.
-  void handleOperand(bool optional, unsigned &operandIndex,
-                     unsigned &physicalOperandIndex,
-                     unsigned numPhysicalOperands,
-                     const unsigned *operandMapping,
-                     OperandEncoding (*encodingFromString)(const std::string &,
-                                                           uint8_t OpSize));
+  void handleOperand(
+      bool optional, unsigned &operandIndex, unsigned &physicalOperandIndex,
+      unsigned numPhysicalOperands, const unsigned *operandMapping,
+      OperandEncoding (*encodingFromString)(StringRef s, uint8_t OpSize));
 
   /// emitInstructionSpecifier - Loads the instruction specifier for the current
   ///   instruction into a DisassemblerTables.

@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes
  • Use StringRef instead of std::string in several functions.
  • Fix some variable names to conform to LLVM coding standard.

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

2 Files Affected:

  • (modified) llvm/utils/TableGen/X86RecognizableInstr.cpp (+30-36)
  • (modified) llvm/utils/TableGen/X86RecognizableInstr.h (+14-16)
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.cpp b/llvm/utils/TableGen/X86RecognizableInstr.cpp
index 402fc93703228..9e49ac2ad8377 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.cpp
+++ b/llvm/utils/TableGen/X86RecognizableInstr.cpp
@@ -440,8 +440,7 @@ void RecognizableInstr::adjustOperandEncoding(OperandEncoding &encoding) {
 void RecognizableInstr::handleOperand(
     bool optional, unsigned &operandIndex, unsigned &physicalOperandIndex,
     unsigned numPhysicalOperands, const unsigned *operandMapping,
-    OperandEncoding (*encodingFromString)(const std::string &,
-                                          uint8_t OpSize)) {
+    OperandEncoding (*encodingFromString)(StringRef, uint8_t OpSize)) {
   if (optional) {
     if (physicalOperandIndex >= numPhysicalOperands)
       return;
@@ -458,12 +457,12 @@ void RecognizableInstr::handleOperand(
 
   StringRef typeName = (*Operands)[operandIndex].Rec->getName();
 
-  OperandEncoding encoding = encodingFromString(typeName.str(), OpSize);
+  OperandEncoding encoding = encodingFromString(typeName, OpSize);
   // Adjust the encoding type for an operand based on the instruction.
   adjustOperandEncoding(encoding);
   Spec->operands[operandIndex].encoding = encoding;
   Spec->operands[operandIndex].type =
-      typeFromString(typeName.str(), HasREX_W, OpSize);
+      typeFromString(typeName, HasREX_W, OpSize);
 
   ++operandIndex;
   ++physicalOperandIndex;
@@ -1020,11 +1019,11 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
 #undef MAP
 }
 
-#define TYPE(str, type)                                                        \
-  if (s == str)                                                                \
-    return type;
-OperandType RecognizableInstr::typeFromString(const std::string &s,
-                                              bool hasREX_W, uint8_t OpSize) {
+#define TYPE(Expected, Type)                                                   \
+  if (Str == Expected)                                                         \
+    return Type;
+OperandType RecognizableInstr::typeFromString(StringRef Str, bool hasREX_W,
+                                              uint8_t OpSize) {
   if (hasREX_W) {
     // For instructions with a REX_W prefix, a declared 32-bit register encoding
     // is special.
@@ -1163,17 +1162,16 @@ OperandType RecognizableInstr::typeFromString(const std::string &s,
   TYPE("BNDR", TYPE_BNDR)
   TYPE("TILE", TYPE_TMM)
   TYPE("TILEPair", TYPE_TMM_PAIR)
-  errs() << "Unhandled type string " << s << "\n";
+  errs() << "Unhandled type string " << Str << "\n";
   llvm_unreachable("Unhandled type string");
 }
 #undef TYPE
 
-#define ENCODING(str, encoding)                                                \
-  if (s == str)                                                                \
-    return encoding;
-OperandEncoding
-RecognizableInstr::immediateEncodingFromString(const std::string &s,
-                                               uint8_t OpSize) {
+#define ENCODING(Expected, Encoding)                                           \
+  if (Str == Expected)                                                         \
+    return Encoding;
+OperandEncoding RecognizableInstr::immediateEncodingFromString(StringRef Str,
+                                                               uint8_t OpSize) {
   if (OpSize != X86Local::OpSize16) {
     // For instructions without an OpSize prefix, a declared 16-bit register or
     // immediate encoding is special.
@@ -1208,13 +1206,12 @@ RecognizableInstr::immediateEncodingFromString(const std::string &s,
   ENCODING("VR256X", ENCODING_IB)
   ENCODING("VR512", ENCODING_IB)
   ENCODING("TILE", ENCODING_IB)
-  errs() << "Unhandled immediate encoding " << s << "\n";
+  errs() << "Unhandled immediate encoding " << Str << "\n";
   llvm_unreachable("Unhandled immediate encoding");
 }
 
 OperandEncoding
-RecognizableInstr::rmRegisterEncodingFromString(const std::string &s,
-                                                uint8_t OpSize) {
+RecognizableInstr::rmRegisterEncodingFromString(StringRef Str, uint8_t OpSize) {
   ENCODING("RST", ENCODING_FP)
   ENCODING("RSTi", ENCODING_FP)
   ENCODING("GR16", ENCODING_RM)
@@ -1245,13 +1242,12 @@ RecognizableInstr::rmRegisterEncodingFromString(const std::string &s,
   ENCODING("BNDR", ENCODING_RM)
   ENCODING("TILE", ENCODING_RM)
   ENCODING("TILEPair", ENCODING_RM)
-  errs() << "Unhandled R/M register encoding " << s << "\n";
+  errs() << "Unhandled R/M register encoding " << Str << "\n";
   llvm_unreachable("Unhandled R/M register encoding");
 }
 
 OperandEncoding
-RecognizableInstr::roRegisterEncodingFromString(const std::string &s,
-                                                uint8_t OpSize) {
+RecognizableInstr::roRegisterEncodingFromString(StringRef Str, uint8_t OpSize) {
   ENCODING("GR16", ENCODING_REG)
   ENCODING("GR16orGR32orGR64", ENCODING_REG)
   ENCODING("GR32", ENCODING_REG)
@@ -1295,12 +1291,12 @@ RecognizableInstr::roRegisterEncodingFromString(const std::string &s,
   ENCODING("BNDR", ENCODING_REG)
   ENCODING("TILE", ENCODING_REG)
   ENCODING("TILEPair", ENCODING_REG)
-  errs() << "Unhandled reg/opcode register encoding " << s << "\n";
+  errs() << "Unhandled reg/opcode register encoding " << Str << "\n";
   llvm_unreachable("Unhandled reg/opcode register encoding");
 }
 
 OperandEncoding
-RecognizableInstr::vvvvRegisterEncodingFromString(const std::string &s,
+RecognizableInstr::vvvvRegisterEncodingFromString(StringRef Str,
                                                   uint8_t OpSize) {
   ENCODING("GR8", ENCODING_VVVV)
   ENCODING("GR16", ENCODING_VVVV)
@@ -1326,12 +1322,12 @@ RecognizableInstr::vvvvRegisterEncodingFromString(const std::string &s,
   ENCODING("VK64", ENCODING_VVVV)
   ENCODING("TILE", ENCODING_VVVV)
   ENCODING("TILEPair", ENCODING_VVVV)
-  errs() << "Unhandled VEX.vvvv register encoding " << s << "\n";
+  errs() << "Unhandled VEX.vvvv register encoding " << Str << "\n";
   llvm_unreachable("Unhandled VEX.vvvv register encoding");
 }
 
 OperandEncoding
-RecognizableInstr::writemaskRegisterEncodingFromString(const std::string &s,
+RecognizableInstr::writemaskRegisterEncodingFromString(StringRef Str,
                                                        uint8_t OpSize) {
   ENCODING("VK1WM", ENCODING_WRITEMASK)
   ENCODING("VK2WM", ENCODING_WRITEMASK)
@@ -1340,13 +1336,12 @@ RecognizableInstr::writemaskRegisterEncodingFromString(const std::string &s,
   ENCODING("VK16WM", ENCODING_WRITEMASK)
   ENCODING("VK32WM", ENCODING_WRITEMASK)
   ENCODING("VK64WM", ENCODING_WRITEMASK)
-  errs() << "Unhandled mask register encoding " << s << "\n";
+  errs() << "Unhandled mask register encoding " << Str << "\n";
   llvm_unreachable("Unhandled mask register encoding");
 }
 
-OperandEncoding
-RecognizableInstr::memoryEncodingFromString(const std::string &s,
-                                            uint8_t OpSize) {
+OperandEncoding RecognizableInstr::memoryEncodingFromString(StringRef Str,
+                                                            uint8_t OpSize) {
   ENCODING("i16mem", ENCODING_RM)
   ENCODING("i32mem", ENCODING_RM)
   ENCODING("i64mem", ENCODING_RM)
@@ -1384,13 +1379,12 @@ RecognizableInstr::memoryEncodingFromString(const std::string &s,
   ENCODING("vy64xmem", ENCODING_VSIB)
   ENCODING("vz32mem", ENCODING_VSIB)
   ENCODING("vz64mem", ENCODING_VSIB)
-  errs() << "Unhandled memory encoding " << s << "\n";
+  errs() << "Unhandled memory encoding " << Str << "\n";
   llvm_unreachable("Unhandled memory encoding");
 }
 
 OperandEncoding
-RecognizableInstr::relocationEncodingFromString(const std::string &s,
-                                                uint8_t OpSize) {
+RecognizableInstr::relocationEncodingFromString(StringRef Str, uint8_t OpSize) {
   if (OpSize != X86Local::OpSize16) {
     // For instructions without an OpSize prefix, a declared 16-bit register or
     // immediate encoding is special.
@@ -1434,19 +1428,19 @@ RecognizableInstr::relocationEncodingFromString(const std::string &s,
   ENCODING("dstidx16", ENCODING_DI)
   ENCODING("dstidx32", ENCODING_DI)
   ENCODING("dstidx64", ENCODING_DI)
-  errs() << "Unhandled relocation encoding " << s << "\n";
+  errs() << "Unhandled relocation encoding " << Str << "\n";
   llvm_unreachable("Unhandled relocation encoding");
 }
 
 OperandEncoding
-RecognizableInstr::opcodeModifierEncodingFromString(const std::string &s,
+RecognizableInstr::opcodeModifierEncodingFromString(StringRef Str,
                                                     uint8_t OpSize) {
   ENCODING("GR32", ENCODING_Rv)
   ENCODING("GR64", ENCODING_RO)
   ENCODING("GR16", ENCODING_Rv)
   ENCODING("GR8", ENCODING_RB)
   ENCODING("ccode", ENCODING_CC)
-  errs() << "Unhandled opcode modifier encoding " << s << "\n";
+  errs() << "Unhandled opcode modifier encoding " << Str << "\n";
   llvm_unreachable("Unhandled opcode modifier encoding");
 }
 #undef ENCODING
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.h b/llvm/utils/TableGen/X86RecognizableInstr.h
index eb2cee7bbbf87..8f28aedb235b8 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.h
+++ b/llvm/utils/TableGen/X86RecognizableInstr.h
@@ -281,7 +281,7 @@ class RecognizableInstr : public RecognizableInstrBase {
   ///                         If register size does not match OpSize, then
   ///                         register sizes keep their size.
   /// @return               - The operand's type.
-  static OperandType typeFromString(const std::string &s, bool hasREX_W,
+  static OperandType typeFromString(StringRef Str, bool hasREX_W,
                                     uint8_t OpSize);
 
   /// immediateEncodingFromString - Translates an immediate encoding from the
@@ -292,28 +292,28 @@ class RecognizableInstr : public RecognizableInstrBase {
   /// @param OpSize  - Indicates whether this is an OpSize16 instruction.
   ///                  If it is not, then 16-bit immediate operands stay 16-bit.
   /// @return        - The operand's encoding.
-  static OperandEncoding immediateEncodingFromString(const std::string &s,
+  static OperandEncoding immediateEncodingFromString(StringRef Str,
                                                      uint8_t OpSize);
 
   /// rmRegisterEncodingFromString - Like immediateEncodingFromString, but
   ///   handles operands that are in the REG field of the ModR/M byte.
-  static OperandEncoding rmRegisterEncodingFromString(const std::string &s,
+  static OperandEncoding rmRegisterEncodingFromString(StringRef Str,
                                                       uint8_t OpSize);
 
   /// rmRegisterEncodingFromString - Like immediateEncodingFromString, but
   ///   handles operands that are in the REG field of the ModR/M byte.
-  static OperandEncoding roRegisterEncodingFromString(const std::string &s,
+  static OperandEncoding roRegisterEncodingFromString(StringRef Str,
                                                       uint8_t OpSize);
-  static OperandEncoding memoryEncodingFromString(const std::string &s,
+  static OperandEncoding memoryEncodingFromString(StringRef Str,
                                                   uint8_t OpSize);
-  static OperandEncoding relocationEncodingFromString(const std::string &s,
+  static OperandEncoding relocationEncodingFromString(StringRef Str,
                                                       uint8_t OpSize);
-  static OperandEncoding opcodeModifierEncodingFromString(const std::string &s,
+  static OperandEncoding opcodeModifierEncodingFromString(StringRef Str,
                                                           uint8_t OpSize);
-  static OperandEncoding vvvvRegisterEncodingFromString(const std::string &s,
+  static OperandEncoding vvvvRegisterEncodingFromString(StringRef Str,
                                                         uint8_t OpSize);
-  static OperandEncoding
-  writemaskRegisterEncodingFromString(const std::string &s, uint8_t OpSize);
+  static OperandEncoding writemaskRegisterEncodingFromString(StringRef Str,
+                                                             uint8_t OpSize);
 
   /// Adjust the encoding type for an operand based on the instruction.
   void adjustOperandEncoding(OperandEncoding &encoding);
@@ -336,12 +336,10 @@ class RecognizableInstr : public RecognizableInstrBase {
   /// @param operandMapping       - The operand mapping, which has an entry for
   ///                               each operand that indicates whether it is a
   ///                               duplicate, and of what.
-  void handleOperand(bool optional, unsigned &operandIndex,
-                     unsigned &physicalOperandIndex,
-                     unsigned numPhysicalOperands,
-                     const unsigned *operandMapping,
-                     OperandEncoding (*encodingFromString)(const std::string &,
-                                                           uint8_t OpSize));
+  void handleOperand(
+      bool optional, unsigned &operandIndex, unsigned &physicalOperandIndex,
+      unsigned numPhysicalOperands, const unsigned *operandMapping,
+      OperandEncoding (*encodingFromString)(StringRef s, uint8_t OpSize));
 
   /// emitInstructionSpecifier - Loads the instruction specifier for the current
   ///   instruction into a DisassemblerTables.

@jurahul jurahul force-pushed the tablegen_use_stringref_X86RecognizableInstr branch from f77eda8 to 4b036ca Compare May 13, 2025 13:02
@jurahul jurahul requested a review from wangpc-pp May 13, 2025 14:42
@jurahul jurahul force-pushed the tablegen_use_stringref_X86RecognizableInstr branch from 4b036ca to 833d836 Compare May 14, 2025 04:52
@jurahul jurahul requested a review from wangpc-pp May 14, 2025 04:53
@KanRobert KanRobert requested review from phoebewang and KanRobert May 14, 2025 04:55
- Use `StringRef` instead of `std::string` in several functions.
- Fix some variable names to conform to LLVM coding standard.
@jurahul jurahul force-pushed the tablegen_use_stringref_X86RecognizableInstr branch from 833d836 to 46edb8d Compare May 14, 2025 05:48
@jurahul jurahul requested a review from KanRobert May 14, 2025 05:49
Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jurahul jurahul merged commit 2f2c327 into llvm:main May 14, 2025
11 checks passed
@jurahul jurahul deleted the tablegen_use_stringref_X86RecognizableInstr branch May 14, 2025 13:06
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 14, 2025

LLVM Buildbot has detected a new failure on builder lldb-x86_64-debian running on lldb-x86_64-debian while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/22374

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test (2911 of 2922)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Python/Crashlog/text.test (2912 of 2922)
UNSUPPORTED: lldb-shell :: SymbolFile/PDB/enums-layout.test (2913 of 2922)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/io.test (2914 of 2922)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Python/Crashlog/no_threadState.test (2915 of 2922)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Python/Crashlog/parser_text.test (2916 of 2922)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/persistent_state.test (2917 of 2922)
PASS: lldb-api :: api/multithreaded/TestMultithreaded.py (2918 of 2922)
PASS: lldb-api :: terminal/TestEditlineCompletions.py (2919 of 2922)
UNRESOLVED: lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py (2920 of 2922)
******************** TEST 'lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py' FAILED ********************
Script:
--
/usr/bin/python3 /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 --build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex --lldb-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./lib -t /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch -p TestDAP_launch.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 2f2c327017598b16045b66c49e9a4c333d3b9dfe)
  clang revision 2f2c327017598b16045b66c49e9a4c333d3b9dfe
  llvm revision 2f2c327017598b16045b66c49e9a4c333d3b9dfe
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
Change dir to: /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch
runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 

runCmd: settings set target.auto-apply-fixits false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants