5353namespace llvm {
5454namespace 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-
6256BenchmarkRunner::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
119114private:
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>>
678673BenchmarkRunner::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)
0 commit comments