[llvm-commits] [llvm] r150245 - in /llvm/trunk: include/llvm/MC/MCInstrDesc.h include/llvm/MC/MCInstrInfo.h lib/CodeGen/MachineInstr.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp utils/TableGen/InstrInfoEmitter.cpp

Benjamin Kramer benny.kra at googlemail.com
Fri Feb 10 05:18:44 PST 2012


Author: d0k
Date: Fri Feb 10 07:18:44 2012
New Revision: 150245

URL: http://llvm.org/viewvc/llvm-project?rev=150245&view=rev
Log:
Put instruction names into an indexed string table on the side, removing a pointer from MCInstrDesc.

Make them accessible through MCInstrInfo. They are only used for debugging purposes so this doesn't
have an impact on performance. X86MCTargetDesc.o goes from 630K to 461K on x86_64.

Modified:
    llvm/trunk/include/llvm/MC/MCInstrDesc.h
    llvm/trunk/include/llvm/MC/MCInstrInfo.h
    llvm/trunk/lib/CodeGen/MachineInstr.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp

Modified: llvm/trunk/include/llvm/MC/MCInstrDesc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInstrDesc.h?rev=150245&r1=150244&r2=150245&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCInstrDesc.h (original)
+++ llvm/trunk/include/llvm/MC/MCInstrDesc.h Fri Feb 10 07:18:44 2012
@@ -142,7 +142,6 @@
   const unsigned *ImplicitUses;  // Registers implicitly read by this instr
   const unsigned *ImplicitDefs;  // Registers implicitly defined by this instr
   const MCOperandInfo *OpInfo;   // 'NumOperands' entries about operands
-  const char     *Name;          // Name of the instruction record in td file
 
   /// getOperandConstraint - Returns the value of the specific constraint if
   /// it is set. Returns -1 if it is not set.
@@ -161,12 +160,6 @@
     return Opcode;
   }
 
-  /// getName - Return the name of the record in the .td file for this
-  /// instruction, for example "ADD8ri".
-  const char *getName() const {
-    return Name;
-  }
-
   /// getNumOperands - Return the number of declared MachineOperands for this
   /// MachineInstruction.  Note that variadic (isVariadic() returns true)
   /// instructions may have additional operands at the end of the list, and note

Modified: llvm/trunk/include/llvm/MC/MCInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInstrInfo.h?rev=150245&r1=150244&r2=150245&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCInstrInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCInstrInfo.h Fri Feb 10 07:18:44 2012
@@ -24,14 +24,19 @@
 /// MCInstrInfo - Interface to description of machine instruction set
 ///
 class MCInstrInfo {
-  const MCInstrDesc *Desc;  // Raw array to allow static init'n
-  unsigned NumOpcodes;      // Number of entries in the desc array
+  const MCInstrDesc *Desc;          // Raw array to allow static init'n
+  const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
+  const char *InstrNameData;        // Instruction name string pool
+  unsigned NumOpcodes;              // Number of entries in the desc array
 
 public:
   /// InitMCInstrInfo - Initialize MCInstrInfo, called by TableGen
   /// auto-generated routines. *DO NOT USE*.
-  void InitMCInstrInfo(const MCInstrDesc *D, unsigned NO) {
+  void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
+                       unsigned NO) {
     Desc = D;
+    InstrNameIndices = NI;
+    InstrNameData = ND;
     NumOpcodes = NO;
   }
 
@@ -44,6 +49,12 @@
     assert(Opcode < NumOpcodes && "Invalid opcode!");
     return Desc[Opcode];
   }
+
+  /// getName - Returns the name for the instructions with the given opcode.
+  const char *getName(unsigned Opcode) const {
+    assert(Opcode < NumOpcodes && "Invalid opcode!");
+    return &InstrNameData[InstrNameIndices[Opcode]];
+  }
 };
 
 } // End llvm namespace

Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=150245&r1=150244&r2=150245&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Fri Feb 10 07:18:44 2012
@@ -1484,7 +1484,10 @@
     OS << " = ";
 
   // Print the opcode name.
-  OS << getDesc().getName();
+  if (TM && TM->getInstrInfo())
+    OS << TM->getInstrInfo()->getName(getOpcode());
+  else
+    OS << "UNKNOWN";
 
   // Print the rest of the operands.
   bool OmittedAnyCallClobbers = false;

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=150245&r1=150244&r2=150245&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Feb 10 07:18:44 2012
@@ -5910,7 +5910,7 @@
       if (G)
         if (const TargetInstrInfo *TII = G->getTarget().getInstrInfo())
           if (getMachineOpcode() < TII->getNumOpcodes())
-            return TII->get(getMachineOpcode()).getName();
+            return TII->getName(getMachineOpcode());
       return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
     }
     if (G) {

Modified: llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp?rev=150245&r1=150244&r2=150245&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp Fri Feb 10 07:18:44 2012
@@ -14,6 +14,7 @@
 
 #include "InstrInfoEmitter.h"
 #include "CodeGenTarget.h"
+#include "StringToOffsetTable.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/ADT/StringExtras.h"
 #include <algorithm>
@@ -212,10 +213,26 @@
                OperandInfoIDs, OS);
   OS << "};\n\n";
 
+  OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {\n    ";
+  StringToOffsetTable StringTable;
+  for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
+    const CodeGenInstruction *Instr = NumberedInstructions[i];
+    OS << StringTable.GetOrAddStringOffset(Instr->TheDef->getName()) << "U, ";
+    if (i % 8 == 0)
+      OS << "\n    ";
+  }
+
+  OS << "\n};\n\n";
+
+  OS << "const char *" << TargetName << "InstrNameData =\n";
+  StringTable.EmitString(OS);
+  OS << ";\n\n";
+
   // MCInstrInfo initialization routine.
   OS << "static inline void Init" << TargetName
      << "MCInstrInfo(MCInstrInfo *II) {\n";
   OS << "  II->InitMCInstrInfo(" << TargetName << "Insts, "
+     << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, "
      << NumberedInstructions.size() << ");\n}\n\n";
 
   OS << "} // End llvm namespace \n";
@@ -240,9 +257,12 @@
 
   OS << "namespace llvm {\n";
   OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n";
+  OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n";
+  OS << "extern const char *" << TargetName << "InstrNameData;\n";
   OS << ClassName << "::" << ClassName << "(int SO, int DO)\n"
      << "  : TargetInstrInfoImpl(SO, DO) {\n"
      << "  InitMCInstrInfo(" << TargetName << "Insts, "
+     << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, "
      << NumberedInstructions.size() << ");\n}\n";
   OS << "} // End llvm namespace \n";
 
@@ -329,8 +349,6 @@
   else
     OS << "OperandInfo" << OpInfo.find(OperandInfo)->second;
 
-  OS << ", \"" << Inst.TheDef->getName() << '"';
-
   OS << " },  // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
 }
 





More information about the llvm-commits mailing list