[llvm] [TableGen] Remove map CodeGenTarget::InstrToIntMap. (PR #81079)

Jason Eckhardt via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 18:39:17 PST 2024


https://github.com/nvjle created https://github.com/llvm/llvm-project/pull/81079

This patch removes CodeGenTarget::InstrToIntMap, using instead a new member CodeGenInstruction::EnumVal to store each enum value. This value is computed and set by CodeGenTarget::computeInstrsByEnum and queried by CodeGenTarget::getInstrIntValue.

>From 648d953c2b91658ba15bda18491206986dd44e20 Mon Sep 17 00:00:00 2001
From: Jason Eckhardt <jeckhardt at nvidia.com>
Date: Wed, 7 Feb 2024 20:28:18 -0600
Subject: [PATCH] [TableGen] Remove map CodeGenTarget::InstrToIntMap.

This patch removes CodeGenTarget::InstrToIntMap, using instead a new
member CodeGenInstruction::EnumVal to store each enum value. This
value is computed and set by CodeGenTarget::computeInstrsByEnum and
queried by CodeGenTarget::getInstrIntValue.
---
 llvm/utils/TableGen/CodeGenInstruction.h | 3 +++
 llvm/utils/TableGen/CodeGenTarget.cpp    | 6 ++----
 llvm/utils/TableGen/CodeGenTarget.h      | 7 ++-----
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/llvm/utils/TableGen/CodeGenInstruction.h b/llvm/utils/TableGen/CodeGenInstruction.h
index 8b3e670d3ff7cd..4a34c296517c50 100644
--- a/llvm/utils/TableGen/CodeGenInstruction.h
+++ b/llvm/utils/TableGen/CodeGenInstruction.h
@@ -303,6 +303,9 @@ namespace llvm {
     // have been inferred.
     Record *InferredFrom;
 
+    // The enum value assigned by CodeGenTarget::computeInstrsByEnum.
+    mutable unsigned EnumVal;
+
     CodeGenInstruction(Record *R);
 
     /// HasOneImplicitDefWithKnownVT - If the instruction has at least one
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index cf0049e6d33e3c..ceaa51b1dff36c 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -539,12 +539,10 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
                std::make_tuple(!D2.getValueAsBit("isPseudo"), D2.getName());
       });
 
-  // Build the instruction-to-int map using the same values emitted by
-  // InstrInfoEmitter::emitEnums.
-  assert(InstrToIntMap.empty());
+  // Assign an enum value to each instruction according to the sorted order.
   unsigned Num = 0;
   for (const CodeGenInstruction *Inst : InstrsByEnum)
-    InstrToIntMap[Inst->TheDef] = Num++;
+    Inst->EnumVal = Num++;
 }
 
 
diff --git a/llvm/utils/TableGen/CodeGenTarget.h b/llvm/utils/TableGen/CodeGenTarget.h
index 0bb8e45a56064e..f122cd0bcb9570 100644
--- a/llvm/utils/TableGen/CodeGenTarget.h
+++ b/llvm/utils/TableGen/CodeGenTarget.h
@@ -17,6 +17,7 @@
 #define LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
 
 #include "CodeGenHwModes.h"
+#include "CodeGenInstruction.h"
 #include "InfoByHwMode.h"
 #include "SDNodeProperties.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -34,7 +35,6 @@ namespace llvm {
 
 class RecordKeeper;
 class Record;
-class CodeGenInstruction;
 class CodeGenRegBank;
 class CodeGenRegister;
 class CodeGenRegisterClass;
@@ -74,7 +74,6 @@ class CodeGenTarget {
 
   mutable StringRef InstNamespace;
   mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
-  mutable DenseMap<const Record *, unsigned> InstrToIntMap;
   mutable unsigned NumPseudoInstructions = 0;
 public:
   CodeGenTarget(RecordKeeper &Records);
@@ -197,9 +196,7 @@ class CodeGenTarget {
   unsigned getInstrIntValue(const Record *R) const {
     if (InstrsByEnum.empty())
       ComputeInstrsByEnum();
-    auto V = InstrToIntMap.find(R);
-    assert(V != InstrToIntMap.end() && "instr not in InstrToIntMap");
-    return V->second;
+    return getInstruction(R).EnumVal;
   }
 
   typedef ArrayRef<const CodeGenInstruction *>::const_iterator inst_iterator;



More information about the llvm-commits mailing list