diff options
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
| -rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index fae75125591..1dd413a2912 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/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 @@ namespace { // 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 @@ private: } 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 @@ private: const llvm::exegesis::LLVMState *State; std::string LastError; llvm::raw_string_ostream ErrorStream; + const llvm::StringMap<unsigned> OpcodeNameToOpcodeIdx; }; } // namespace |

