diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2022-12-13 00:02:05 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2022-12-13 01:03:38 +0300 |
commit | 079cd4a52f398ccf4a04cf47f2c3c536a5011585 (patch) | |
tree | a4c89225adf79aa20abf051daaf4059ba3e05c80 /llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | |
parent | 79909c031d43de21ce9c10394a5aac08bec0a874 (diff) | |
download | llvm-079cd4a52f398ccf4a04cf47f2c3c536a5011585.zip llvm-079cd4a52f398ccf4a04cf47f2c3c536a5011585.tar.gz llvm-079cd4a52f398ccf4a04cf47f2c3c536a5011585.tar.bz2 |
[NFC][Exegesis] Don't recompute opcode/reg names on each YAML write (-38% runtime)
This reducer runtime of
```
$ ./bin/llvm-exegesis -mode=inverse_throughput --opcode-index=-1 --benchmarks-file=/dev/null --dump-object-to-disk=0 --measurements-print-progress --skip-measurements
```
from 3m44s to 2m17s, aka -38%.
But more importantly, we go from 400 *million* memory allocations
down to just 100 million, aka -75%.
But really, the big missing thing is doing everything in a single thread.
Sure, we can't do anything when measuring, but when we are not measuring,
we should just prepare (codegen) everything via all threads.
That should parallelize quite well.
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index 99c6567..81adaf0 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -23,7 +23,6 @@ static constexpr const char kIntegerPrefix[] = "i_0x"; static constexpr const char kDoublePrefix[] = "f_"; static constexpr const char kInvalidOperand[] = "INVALID"; -static constexpr llvm::StringLiteral kNoRegister("%noreg"); namespace llvm { @@ -34,29 +33,8 @@ namespace { struct YamlContext { YamlContext(const exegesis::LLVMState &State) : State(&State), ErrorStream(LastError), - OpcodeNameToOpcodeIdx( - generateOpcodeNameToOpcodeIdxMapping(State.getInstrInfo())), - RegNameToRegNo(generateRegNameToRegNoMapping(State.getRegInfo())) {} - - static StringMap<unsigned> - generateOpcodeNameToOpcodeIdxMapping(const MCInstrInfo &InstrInfo) { - 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; - }; - - StringMap<unsigned> - generateRegNameToRegNoMapping(const MCRegisterInfo &RegInfo) { - StringMap<unsigned> Map(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) - Map[RegInfo.getName(I)] = I; - assert(Map.size() == RegInfo.getNumRegs() && "Size prediction failed"); - return Map; - }; + OpcodeNameToOpcodeIdx(State.getOpcodeNameToOpcodeIdxMapping()), + RegNameToRegNo(State.getRegNameToRegNoMapping()) {} void serializeMCInst(const MCInst &MCInst, raw_ostream &OS) { OS << getInstrName(MCInst.getOpcode()); @@ -174,8 +152,8 @@ private: const exegesis::LLVMState *State; std::string LastError; raw_string_ostream ErrorStream; - const StringMap<unsigned> OpcodeNameToOpcodeIdx; - const StringMap<unsigned> RegNameToRegNo; + const StringMap<unsigned> &OpcodeNameToOpcodeIdx; + const StringMap<unsigned> &RegNameToRegNo; }; } // namespace |