Skip to content

Commit a540385

Browse files
committed
Use benchmark phase instead of command line flag to select dry-run-measurement
1 parent d4edd1d commit a540385

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

llvm/docs/CommandGuide/llvm-exegesis.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ OPTIONS
301301
* ``prepare-and-assemble-snippet``: Same as ``prepare-snippet``, but also dumps an excerpt of the sequence (hex encoded).
302302
* ``assemble-measured-code``: Same as ``prepare-and-assemble-snippet``. but also creates the full sequence that can be dumped to a file using ``--dump-object-to-disk``.
303303
* ``measure``: Same as ``assemble-measured-code``, but also runs the measurement.
304+
* ``dry-run-measurement``: Same as measure, but does not actually execute the snippet.
304305

305306
.. option:: --x86-lbr-sample-period=<nBranches/sample>
306307

@@ -449,11 +450,6 @@ OPTIONS
449450
crash when hardware performance counters are unavailable and for
450451
debugging :program:`llvm-exegesis` itself.
451452

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-
457453
.. option:: --execution-mode=[inprocess,subprocess]
458454

459455
This option specifies what execution mode to use. The `inprocess` execution

llvm/test/tools/llvm-exegesis/dry-run-measurement.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: llvm-exegesis --mtriple=riscv64 --mcpu=sifive-p470 --mode=latency --opcode-name=ADD --use-dummy-perf-counters --dry-run-measurement | FileCheck %s
1+
# RUN: llvm-exegesis --mtriple=riscv64 --mcpu=sifive-p470 --mode=latency --opcode-name=ADD --use-dummy-perf-counters --benchmark-phase=dry-run-measurement | FileCheck %s
22
# REQUIRES: riscv-registered-target
33

44
# This test makes sure that llvm-exegesis doesn't execute "cross-compiled" snippets in the presence of

llvm/tools/llvm-exegesis/lib/BenchmarkResult.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum class BenchmarkPhaseSelectorE {
3838
PrepareAndAssembleSnippet,
3939
AssembleMeasuredCode,
4040
Measure,
41+
DryRunMeasure,
4142
};
4243

4344
enum class BenchmarkFilter { All, RegOnly, WithMem };

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@
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-
6256
BenchmarkRunner::BenchmarkRunner(const LLVMState &State, Benchmark::ModeE Mode,
6357
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
6458
ExecutionModeE ExecutionMode,
@@ -105,22 +99,25 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
10599
static Expected<std::unique_ptr<InProcessFunctionExecutorImpl>>
106100
create(const LLVMState &State, object::OwningBinary<object::ObjectFile> Obj,
107101
BenchmarkRunner::ScratchSpace *Scratch,
108-
std::optional<int> BenchmarkProcessCPU) {
102+
std::optional<int> BenchmarkProcessCPU, bool DryRun) {
109103
Expected<ExecutableFunction> EF =
110104
ExecutableFunction::create(State.createTargetMachine(), std::move(Obj));
111105

112106
if (!EF)
113107
return EF.takeError();
114108

115109
return std::unique_ptr<InProcessFunctionExecutorImpl>(
116-
new InProcessFunctionExecutorImpl(State, std::move(*EF), Scratch));
110+
new InProcessFunctionExecutorImpl(State, std::move(*EF), Scratch,
111+
DryRun));
117112
}
118113

119114
private:
120115
InProcessFunctionExecutorImpl(const LLVMState &State,
121116
ExecutableFunction Function,
122-
BenchmarkRunner::ScratchSpace *Scratch)
123-
: State(State), Function(std::move(Function)), Scratch(Scratch) {}
117+
BenchmarkRunner::ScratchSpace *Scratch,
118+
bool DryRun)
119+
: State(State), Function(std::move(Function)), Scratch(Scratch),
120+
DryRun(DryRun) {}
124121

125122
static void accumulateCounterValues(const SmallVector<int64_t, 4> &NewValues,
126123
SmallVector<int64_t, 4> *Result) {
@@ -146,21 +143,18 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
146143
Scratch->clear();
147144
{
148145
auto PS = ET.withSavedState();
149-
// We can't directly capture DryRunMeasurement in the lambda below.
150-
bool DryRun = DryRunMeasurement;
151146
CrashRecoveryContext CRC;
152147
CrashRecoveryContext::Enable();
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-
});
148+
const bool Crashed = !CRC.RunSafely([this, Counter, ScratchPtr]() {
149+
if (DryRun) {
150+
Counter->start();
151+
Counter->stop();
152+
} else {
153+
Counter->start();
154+
this->Function(ScratchPtr);
155+
Counter->stop();
156+
}
157+
});
164158
CrashRecoveryContext::Disable();
165159
PS.reset();
166160
if (Crashed) {
@@ -191,6 +185,7 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
191185
const LLVMState &State;
192186
const ExecutableFunction Function;
193187
BenchmarkRunner::ScratchSpace *const Scratch;
188+
bool DryRun = false;
194189
};
195190

196191
#ifdef __linux__
@@ -678,21 +673,29 @@ Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
678673
BenchmarkRunner::createFunctionExecutor(
679674
object::OwningBinary<object::ObjectFile> ObjectFile,
680675
const BenchmarkKey &Key, std::optional<int> BenchmarkProcessCPU) const {
676+
bool DryRun =
677+
BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::DryRunMeasure;
678+
681679
switch (ExecutionMode) {
682680
case ExecutionModeE::InProcess: {
683681
if (BenchmarkProcessCPU.has_value())
684682
return make_error<Failure>("The inprocess execution mode does not "
685683
"support benchmark core pinning.");
686684

687685
auto InProcessExecutorOrErr = InProcessFunctionExecutorImpl::create(
688-
State, std::move(ObjectFile), Scratch.get(), BenchmarkProcessCPU);
686+
State, std::move(ObjectFile), Scratch.get(), BenchmarkProcessCPU,
687+
DryRun);
689688
if (!InProcessExecutorOrErr)
690689
return InProcessExecutorOrErr.takeError();
691690

692691
return std::move(*InProcessExecutorOrErr);
693692
}
694693
case ExecutionModeE::SubProcess: {
695694
#ifdef __linux__
695+
if (DryRun)
696+
return make_error<Failure>("The subprocess execution mode cannot "
697+
"dry-run measurement at this moment.");
698+
696699
auto SubProcessExecutorOrErr = SubProcessFunctionExecutorImpl::create(
697700
State, std::move(ObjectFile), Key, BenchmarkProcessCPU);
698701
if (!SubProcessExecutorOrErr)

llvm/tools/llvm-exegesis/llvm-exegesis.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ static cl::opt<BenchmarkPhaseSelectorE> BenchmarkPhaseSelector(
132132
clEnumValN(
133133
BenchmarkPhaseSelectorE::Measure, "measure",
134134
"Same as prepare-measured-code, but also runs the measurement "
135-
"(default)")),
135+
"(default)"),
136+
clEnumValN(
137+
BenchmarkPhaseSelectorE::DryRunMeasure, "dry-run-measurement",
138+
"Same as measure, but does not actually execute the snippet")),
136139
cl::init(BenchmarkPhaseSelectorE::Measure));
137140

138141
static cl::opt<bool>

0 commit comments

Comments
 (0)