[PATCH] D57657: [llvm-exegesis] Cut run time of analysis mode by -84% (*sic*) (YamlContext::getInstrOpcode())

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 4 01:12:45 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL353024: [llvm-exegesis] Cut run time of analysis mode by -84% (*sic*) (YamlContext… (authored by lebedevri, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57657?vs=184962&id=185002#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57657/new/

https://reviews.llvm.org/D57657

Files:
  llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp


Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
===================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -9,8 +9,9 @@
 #include "BenchmarkResult.h"
 #include "BenchmarkRunner.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/bit.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
@@ -29,7 +30,18 @@
 // serialization process to encode/decode registers and instructions.
 struct YamlContext {
   YamlContext(const exegesis::LLVMState &State)
-      : State(&State), ErrorStream(LastError) {}
+      : State(&State), ErrorStream(LastError),
+        OpcodeNameToOpcodeIdx(
+            generateOpcodeNameToOpcodeIdxMapping(State.getInstrInfo())) {}
+
+  static llvm::StringMap<unsigned>
+  generateOpcodeNameToOpcodeIdxMapping(const llvm::MCInstrInfo &InstrInfo) {
+    llvm::StringMap<unsigned> Map(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 Map;
+  };
 
   void serializeMCInst(const llvm::MCInst &MCInst, llvm::raw_ostream &OS) {
     OS << getInstrName(MCInst.getOpcode());
@@ -136,10 +148,9 @@
   }
 
   unsigned getInstrOpcode(llvm::StringRef InstrName) {
-    const llvm::MCInstrInfo &InstrInfo = State->getInstrInfo();
-    for (unsigned E = InstrInfo.getNumOpcodes(), I = 0; I < E; ++I)
-      if (InstrInfo.getName(I) == InstrName)
-        return I;
+    auto Iter = OpcodeNameToOpcodeIdx.find(InstrName);
+    if (Iter != OpcodeNameToOpcodeIdx.end())
+      return Iter->second;
     ErrorStream << "No opcode with name " << InstrName;
     return 0;
   }
@@ -147,6 +158,7 @@
   const llvm::exegesis::LLVMState *State;
   std::string LastError;
   llvm::raw_string_ostream ErrorStream;
+  const llvm::StringMap<unsigned> OpcodeNameToOpcodeIdx;
 };
 } // namespace
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57657.185002.patch
Type: text/x-patch
Size: 2176 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190204/2db522fc/attachment.bin>


More information about the llvm-commits mailing list