From 53d35d2dc4a6ef270d1407d0ea0717d8ccf6fccd Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Tue, 5 Jun 2018 10:56:19 +0000 Subject: [llvm-exegesis] Add instructions to BenchmarkResult Key. We want llvm-exegesis to explore instructions (effect of initial register values, effect of operand selection). To enable this a BenchmarkResult muststore all the relevant data in its key. This patch starts adding such data. Here we simply allow to store the generated instructions, following patches will add operands and initial values for registers. https://reviews.llvm.org/D47764 Authored by: Guilluame Chatelet llvm-svn: 334008 --- llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'llvm/tools/llvm-exegesis/llvm-exegesis.cpp') diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp index 3c57706a255..a1848c3f14f 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -92,6 +92,21 @@ static unsigned GetOpcodeOrDie(const llvm::MCInstrInfo &MCInstrInfo) { llvm::report_fatal_error(llvm::Twine("unknown opcode ").concat(OpcodeName)); } +static BenchmarkResultContext +getBenchmarkResultContext(const LLVMState &State) { + BenchmarkResultContext Ctx; + + const llvm::MCInstrInfo &InstrInfo = State.getInstrInfo(); + for (unsigned E = InstrInfo.getNumOpcodes(), I = 0; I < E; ++I) + Ctx.addInstrEntry(I, InstrInfo.getName(I).data()); + + const llvm::MCRegisterInfo &RegInfo = State.getRegInfo(); + for (unsigned E = RegInfo.getNumRegs(), I = 0; I < E; ++I) + Ctx.addRegEntry(I, RegInfo.getName(I)); + + return Ctx; +} + void benchmarkMain() { if (exegesis::pfm::pfmInitialize()) llvm::report_fatal_error("cannot initialize libpfm"); @@ -124,7 +139,7 @@ void benchmarkMain() { llvm::report_fatal_error("--num-repetitions must be greater than zero"); Runner->run(GetOpcodeOrDie(State.getInstrInfo()), Filter, NumRepetitions) - .writeYamlOrDie(BenchmarkFile); + .writeYamlOrDie(getBenchmarkResultContext(State), BenchmarkFile); exegesis::pfm::pfmTerminate(); } @@ -132,7 +147,7 @@ void benchmarkMain() { // if OutputFilename is non-empty. template static void maybeRunAnalysis(const Analysis &Analyzer, const std::string &Name, - const std::string &OutputFilename) { + const std::string &OutputFilename) { if (OutputFilename.empty()) return; if (OutputFilename != "-") { @@ -149,9 +164,14 @@ static void maybeRunAnalysis(const Analysis &Analyzer, const std::string &Name, } static void analysisMain() { + llvm::InitializeNativeTarget(); + llvm::InitializeNativeTargetAsmPrinter(); + // Read benchmarks. + const LLVMState State; const std::vector Points = - InstructionBenchmark::readYamlsOrDie(BenchmarkFile); + InstructionBenchmark::readYamlsOrDie(getBenchmarkResultContext(State), + BenchmarkFile); llvm::outs() << "Parsed " << Points.size() << " benchmark points\n"; if (Points.empty()) { llvm::errs() << "no benchmarks to analyze\n"; @@ -160,9 +180,6 @@ static void analysisMain() { // FIXME: Check that all points have the same triple/cpu. // FIXME: Merge points from several runs (latency and uops). - llvm::InitializeNativeTarget(); - llvm::InitializeNativeTargetAsmPrinter(); - std::string Error; const auto *TheTarget = llvm::TargetRegistry::lookupTarget(Points[0].LLVMTriple, Error); -- cgit v1.2.3