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
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index a872c75..2b77288 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -76,14 +76,23 @@
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 @@
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<BenchmarkRunner> Runner;
switch (BenchmarkMode) {
case BenchmarkModeE::Latency:
- Runner = llvm::make_unique<LatencyBenchmarkRunner>();
+ Runner = llvm::make_unique<LatencyBenchmarkRunner>(State);
break;
case BenchmarkModeE::Uops:
- Runner = llvm::make_unique<UopsBenchmarkRunner>();
+ Runner = llvm::make_unique<UopsBenchmarkRunner>(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();
}