[llvm] 96f4990 - [MC] Store target Insts table in reverse order. NFC.

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 13:42:20 PST 2023


Author: Jay Foad
Date: 2023-01-24T21:42:13Z
New Revision: 96f49905de25730c6efe1bef26e0bb60b4b1a583

URL: https://github.com/llvm/llvm-project/commit/96f49905de25730c6efe1bef26e0bb60b4b1a583
DIFF: https://github.com/llvm/llvm-project/commit/96f49905de25730c6efe1bef26e0bb60b4b1a583.diff

LOG: [MC] Store target Insts table in reverse order. NFC.

This will allow an entry in the table to access data that is stored
immediately after the end of the table, by adding its opcode value
to its address.

Differential Revision: https://reviews.llvm.org/D142217

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCInstrInfo.h
    llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
    llvm/utils/TableGen/InstrInfoEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCInstrInfo.h b/llvm/include/llvm/MC/MCInstrInfo.h
index 84995b1e93fef..35ec1b7970516 100644
--- a/llvm/include/llvm/MC/MCInstrInfo.h
+++ b/llvm/include/llvm/MC/MCInstrInfo.h
@@ -30,7 +30,7 @@ class MCInstrInfo {
                                                std::string &);
 
 private:
-  const MCInstrDesc *Desc;          // Raw array to allow static init'n
+  const MCInstrDesc *LastDesc;      // Raw array to allow static init'n
   const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
   const char *InstrNameData;        // Instruction name string pool
   // Subtarget feature that an instruction is deprecated on, if any
@@ -48,7 +48,7 @@ class MCInstrInfo {
   void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
                        const uint8_t *DF,
                        const ComplexDeprecationPredicate *CDI, unsigned NO) {
-    Desc = D;
+    LastDesc = D + NO - 1;
     InstrNameIndices = NI;
     InstrNameData = ND;
     DeprecatedFeatures = DF;
@@ -62,7 +62,8 @@ class MCInstrInfo {
   /// specified instruction opcode.
   const MCInstrDesc &get(unsigned Opcode) const {
     assert(Opcode < NumOpcodes && "Invalid opcode!");
-    return Desc[Opcode];
+    // The table is indexed backwards from the last entry.
+    return *(LastDesc - Opcode);
   }
 
   /// Returns the name for the instructions with the given opcode.

diff  --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 268f25bef89ca..207cf32590cbd 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -2503,7 +2503,8 @@ class ARMOperand : public MCParsedAsmOperand {
       RegNum = 0;
     } else {
       unsigned NextOpIndex = Inst.getNumOperands();
-      const MCInstrDesc &MCID = ARMInsts[Inst.getOpcode()];
+      const MCInstrDesc &MCID =
+          ARMInsts[ARM::INSTRUCTION_LIST_END - 1 - Inst.getOpcode()];
       int TiedOp = MCID.getOperandConstraint(NextOpIndex, MCOI::TIED_TO);
       assert(TiedOp >= 0 &&
              "Inactive register in vpred_r is not tied to an output!");

diff  --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index aafbe932a212f..564c3ed64e269 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -924,20 +924,19 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
   Records.startTimer("Emit operand info");
   EmitOperandInfo(OS, OperandInfoIDs);
 
-  // Emit all of the MCInstrDesc records in their ENUM ordering.
-  //
+  // Emit all of the MCInstrDesc records in reverse ENUM ordering.
   Records.startTimer("Emit InstrDesc records");
   OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n";
   ArrayRef<const CodeGenInstruction*> NumberedInstructions =
     Target.getInstructionsByEnumValue();
 
   SequenceToOffsetTable<std::string> InstrNames;
-  unsigned Num = 0;
-  for (const CodeGenInstruction *Inst : NumberedInstructions) {
+  unsigned Num = NumberedInstructions.size();
+  for (const CodeGenInstruction *Inst : reverse(NumberedInstructions)) {
     // Keep a list of the instruction names.
     InstrNames.add(std::string(Inst->TheDef->getName()));
     // Emit the record into the table.
-    emitRecord(*Inst, Num++, InstrInfo, EmittedLists, OperandInfoIDs, OS);
+    emitRecord(*Inst, --Num, InstrInfo, EmittedLists, OperandInfoIDs, OS);
   }
   OS << "};\n\n";
 


        


More information about the llvm-commits mailing list