Skip to content

Commit d4edd1d

Browse files
committed
[Exegesis] Add --dry-run-measurement
This flag will make llvm-exegesis run everything except the actual snippet execution.
1 parent d40235a commit d4edd1d

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

llvm/docs/CommandGuide/llvm-exegesis.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ OPTIONS
449449
crash when hardware performance counters are unavailable and for
450450
debugging :program:`llvm-exegesis` itself.
451451

452+
.. option:: --dry-run-measurement
453+
If set, llvm-exegesis runs everything except the actual snippet execution.
454+
This is useful if we want to test some part of the code without actually
455+
running on native platforms.
456+
452457
.. option:: --execution-mode=[inprocess,subprocess]
453458

454459
This option specifies what execution mode to use. The `inprocess` execution
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: llvm-exegesis --mtriple=riscv64 --mcpu=sifive-p470 --mode=latency --opcode-name=ADD --use-dummy-perf-counters --dry-run-measurement | FileCheck %s
2+
# REQUIRES: riscv-registered-target
3+
4+
# This test makes sure that llvm-exegesis doesn't execute "cross-compiled" snippets in the presence of
5+
# --dry-run-measurement. RISC-V was chosen simply because most of the time we run tests on X86 machines.
6+
7+
# Should not contain misleading results.
8+
# CHECK: measurements: []
9+
10+
# Should not contain error messages like "snippet crashed while running: Segmentation fault".
11+
# CHECK: error: ''

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
namespace llvm {
5454
namespace exegesis {
5555

56+
static cl::opt<bool>
57+
DryRunMeasurement("dry-run-measurement",
58+
cl::desc("Run every steps in the measurement phase "
59+
"except executing the snippet."),
60+
cl::init(false), cl::Hidden);
61+
5662
BenchmarkRunner::BenchmarkRunner(const LLVMState &State, Benchmark::ModeE Mode,
5763
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
5864
ExecutionModeE ExecutionMode,
@@ -140,13 +146,21 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
140146
Scratch->clear();
141147
{
142148
auto PS = ET.withSavedState();
149+
// We can't directly capture DryRunMeasurement in the lambda below.
150+
bool DryRun = DryRunMeasurement;
143151
CrashRecoveryContext CRC;
144152
CrashRecoveryContext::Enable();
145-
const bool Crashed = !CRC.RunSafely([this, Counter, ScratchPtr]() {
146-
Counter->start();
147-
this->Function(ScratchPtr);
148-
Counter->stop();
149-
});
153+
const bool Crashed =
154+
!CRC.RunSafely([this, Counter, ScratchPtr, DryRun]() {
155+
if (DryRun) {
156+
Counter->start();
157+
Counter->stop();
158+
} else {
159+
Counter->start();
160+
this->Function(ScratchPtr);
161+
Counter->stop();
162+
}
163+
});
150164
CrashRecoveryContext::Disable();
151165
PS.reset();
152166
if (Crashed) {

0 commit comments

Comments
 (0)