From 0e69e2d74739a119a78d131c29b92c25787ec2f3 Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Thu, 17 May 2018 10:52:18 +0000 Subject: reland r332579: [llvm-exegesis] Update to cover latency through another opcode. Restructuring the code to measure latency and uops. The end goal is to have this program spawn another process to deal with SIGILL and other malformed programs. It is not yet the case in this redesign, it is still the main program that runs the code (and may crash). It now uses BitVector instead of Graph for performance reasons. https://reviews.llvm.org/D46821 (with fixed ARM tests) Authored by Guillaume Chatelet llvm-svn: 332592 --- llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 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 a872c759093..2b77288d288 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -76,14 +76,23 @@ static llvm::cl::opt AnalysisClustersFile("analysis-clusters-file", namespace exegesis { +static unsigned GetOpcodeOrDie(const llvm::MCInstrInfo &MCInstrInfo) { + if (OpcodeName.empty() && (OpcodeIndex == 0)) + llvm::report_fatal_error( + "please provide one and only one of 'opcode-index' or 'opcode-name'"); + if (OpcodeIndex > 0) + return OpcodeIndex; + // Resolve opcode name -> opcode. + for (unsigned I = 0, E = MCInstrInfo.getNumOpcodes(); I < E; ++I) + if (MCInstrInfo.getName(I) == OpcodeName) + return I; + llvm::report_fatal_error(llvm::Twine("unknown opcode ").concat(OpcodeName)); +} + void benchmarkMain() { if (exegesis::pfm::pfmInitialize()) llvm::report_fatal_error("cannot initialize libpfm"); - if (OpcodeName.empty() == (OpcodeIndex == 0)) - llvm::report_fatal_error( - "please provide one and only one of 'opcode-index' or 'opcode-name'"); - llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); @@ -92,37 +101,26 @@ void benchmarkMain() { const LLVMState State; + // FIXME: Do not require SchedModel for latency. if (!State.getSubtargetInfo().getSchedModel().hasExtraProcessorInfo()) llvm::report_fatal_error("sched model is missing extra processor info!"); - unsigned Opcode = OpcodeIndex; - if (Opcode == 0) { - // Resolve opcode name -> opcode. - for (unsigned I = 0, E = State.getInstrInfo().getNumOpcodes(); I < E; ++I) { - if (State.getInstrInfo().getName(I) == OpcodeName) { - Opcode = I; - break; - } - } - if (Opcode == 0) { - llvm::report_fatal_error( - llvm::Twine("unknown opcode ").concat(OpcodeName)); - } - } - std::unique_ptr Runner; switch (BenchmarkMode) { case BenchmarkModeE::Latency: - Runner = llvm::make_unique(); + Runner = llvm::make_unique(State); break; case BenchmarkModeE::Uops: - Runner = llvm::make_unique(); + Runner = llvm::make_unique(State); break; case BenchmarkModeE::Analysis: llvm_unreachable("not a benchmark"); } - Runner->run(State, Opcode, NumRepetitions > 0 ? NumRepetitions : 1, Filter) + if (NumRepetitions == 0) + llvm::report_fatal_error("--num-repetitions must be greater than zero"); + + Runner->run(GetOpcodeOrDie(State.getInstrInfo()), Filter, NumRepetitions) .writeYamlOrDie(BenchmarkFile); exegesis::pfm::pfmTerminate(); } -- cgit v1.2.3