[NFC][llvm-exegesis] LLVMState: only store references to reg/op names
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 17 Dec 2022 13:48:07 +0000 (16:48 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 17 Dec 2022 14:10:48 +0000 (17:10 +0300)
We know that the original reference from which we've built these maps
will persist, so we do not need to copy the names.

llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
llvm/tools/llvm-exegesis/lib/LlvmState.cpp
llvm/tools/llvm-exegesis/lib/LlvmState.h

index 3972bb3..593b41e 100644 (file)
@@ -152,8 +152,8 @@ private:
   const exegesis::LLVMState *State;
   std::string LastError;
   raw_string_ostream ErrorStream;
-  const StringMap<unsigned> &OpcodeNameToOpcodeIdx;
-  const StringMap<unsigned> &RegNameToRegNo;
+  const DenseMap<StringRef, unsigned> &OpcodeNameToOpcodeIdx;
+  const DenseMap<StringRef, unsigned> &RegNameToRegNo;
 };
 } // namespace
 
index 363ef82..d7940ce 100644 (file)
@@ -100,20 +100,22 @@ std::unique_ptr<LLVMTargetMachine> LLVMState::createTargetMachine() const {
           Reloc::Model::Static)));
 }
 
-std::unique_ptr<const StringMap<unsigned>>
+std::unique_ptr<const DenseMap<StringRef, unsigned>>
 LLVMState::createOpcodeNameToOpcodeIdxMapping() const {
   const MCInstrInfo &InstrInfo = getInstrInfo();
-  auto Map = std::make_unique<StringMap<unsigned>>(InstrInfo.getNumOpcodes());
+  auto Map = std::make_unique<DenseMap<StringRef, unsigned>>(
+      InstrInfo.getNumOpcodes());
   for (unsigned I = 0, E = InstrInfo.getNumOpcodes(); I < E; ++I)
     (*Map)[InstrInfo.getName(I)] = I;
   assert(Map->size() == InstrInfo.getNumOpcodes() && "Size prediction failed");
   return std::move(Map);
 }
 
-std::unique_ptr<const StringMap<unsigned>>
+std::unique_ptr<const DenseMap<StringRef, unsigned>>
 LLVMState::createRegNameToRegNoMapping() const {
   const MCRegisterInfo &RegInfo = getRegInfo();
-  auto Map = std::make_unique<StringMap<unsigned>>(RegInfo.getNumRegs());
+  auto Map =
+      std::make_unique<DenseMap<StringRef, unsigned>>(RegInfo.getNumRegs());
   // Special-case RegNo 0, which would otherwise be spelled as ''.
   (*Map)[kNoRegister] = 0;
   for (unsigned I = 1, E = RegInfo.getNumRegs(); I < E; ++I)
index f504e02..6039bdb 100644 (file)
@@ -68,21 +68,21 @@ public:
 
   const PfmCountersInfo &getPfmCounters() const { return *PfmCounters; }
 
-  const StringMap<unsigned> &getOpcodeNameToOpcodeIdxMapping() const {
+  const DenseMap<StringRef, unsigned> &getOpcodeNameToOpcodeIdxMapping() const {
     assert(OpcodeNameToOpcodeIdxMapping);
     return *OpcodeNameToOpcodeIdxMapping;
   };
 
-  const StringMap<unsigned> &getRegNameToRegNoMapping() const {
+  const DenseMap<StringRef, unsigned> &getRegNameToRegNoMapping() const {
     assert(RegNameToRegNoMapping);
     return *RegNameToRegNoMapping;
   }
 
 private:
-  std::unique_ptr<const StringMap<unsigned>>
+  std::unique_ptr<const DenseMap<StringRef, unsigned>>
   createOpcodeNameToOpcodeIdxMapping() const;
 
-  std::unique_ptr<const StringMap<unsigned>>
+  std::unique_ptr<const DenseMap<StringRef, unsigned>>
   createRegNameToRegNoMapping() const;
 
   LLVMState(std::unique_ptr<const TargetMachine> TM, const ExegesisTarget *ET,
@@ -93,8 +93,9 @@ private:
   std::unique_ptr<const RegisterAliasingTrackerCache> RATC;
   std::unique_ptr<const InstructionsCache> IC;
   const PfmCountersInfo *PfmCounters;
-  std::unique_ptr<const StringMap<unsigned>> OpcodeNameToOpcodeIdxMapping;
-  std::unique_ptr<const StringMap<unsigned>> RegNameToRegNoMapping;
+  std::unique_ptr<const DenseMap<StringRef, unsigned>>
+      OpcodeNameToOpcodeIdxMapping;
+  std::unique_ptr<const DenseMap<StringRef, unsigned>> RegNameToRegNoMapping;
 };
 
 } // namespace exegesis