Skip to content

Commit 3f3c5e5

Browse files
[NFC][llvm-exegesis] Refactor InstrBenchmark to BenchmarkResult (#76388)
This patch refactors InstrBenchmark to BenchmarkResult. Most of the renaming away from things prefixed with Instr was performed in a previous commit, but this specific instance was missed.
1 parent 250e98e commit 3f3c5e5

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,20 @@ BenchmarkRunner::getRunnableConfiguration(
499499
const SnippetRepetitor &Repetitor) const {
500500
RunnableConfiguration RC;
501501

502-
Benchmark &InstrBenchmark = RC.InstrBenchmark;
503-
InstrBenchmark.Mode = Mode;
504-
InstrBenchmark.CpuName = std::string(State.getTargetMachine().getTargetCPU());
505-
InstrBenchmark.LLVMTriple =
502+
Benchmark &BenchmarkResult = RC.BenchmarkResult;
503+
BenchmarkResult.Mode = Mode;
504+
BenchmarkResult.CpuName =
505+
std::string(State.getTargetMachine().getTargetCPU());
506+
BenchmarkResult.LLVMTriple =
506507
State.getTargetMachine().getTargetTriple().normalize();
507-
InstrBenchmark.NumRepetitions = NumRepetitions;
508-
InstrBenchmark.Info = BC.Info;
508+
BenchmarkResult.NumRepetitions = NumRepetitions;
509+
BenchmarkResult.Info = BC.Info;
509510

510511
const std::vector<MCInst> &Instructions = BC.Key.Instructions;
511512

512513
bool GenerateMemoryInstructions = ExecutionMode == ExecutionModeE::SubProcess;
513514

514-
InstrBenchmark.Key = BC.Key;
515+
BenchmarkResult.Key = BC.Key;
515516

516517
// Assemble at least kMinInstructionsForSnippet instructions by repeating
517518
// the snippet for debug/analysis. This is so that the user clearly
@@ -526,16 +527,17 @@ BenchmarkRunner::getRunnableConfiguration(
526527
return std::move(E);
527528

528529
if (auto Err = getBenchmarkFunctionBytes(*Snippet,
529-
InstrBenchmark.AssembledSnippet))
530+
BenchmarkResult.AssembledSnippet))
530531
return std::move(Err);
531532
}
532533

533534
// Assemble NumRepetitions instructions repetitions of the snippet for
534535
// measurements.
535536
if (BenchmarkPhaseSelector >
536537
BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) {
537-
auto Snippet = assembleSnippet(BC, Repetitor, InstrBenchmark.NumRepetitions,
538-
LoopBodySize, GenerateMemoryInstructions);
538+
auto Snippet =
539+
assembleSnippet(BC, Repetitor, BenchmarkResult.NumRepetitions,
540+
LoopBodySize, GenerateMemoryInstructions);
539541
if (Error E = Snippet.takeError())
540542
return std::move(E);
541543
RC.ObjectFile = getObjectFromBuffer(*Snippet);
@@ -577,46 +579,46 @@ BenchmarkRunner::createFunctionExecutor(
577579
std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
578580
RunnableConfiguration &&RC,
579581
const std::optional<StringRef> &DumpFile) const {
580-
Benchmark &InstrBenchmark = RC.InstrBenchmark;
582+
Benchmark &BenchmarkResult = RC.BenchmarkResult;
581583
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile;
582584

583585
if (DumpFile && BenchmarkPhaseSelector >
584586
BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) {
585587
auto ObjectFilePath =
586588
writeObjectFile(ObjectFile.getBinary()->getData(), *DumpFile);
587589
if (Error E = ObjectFilePath.takeError()) {
588-
return {std::move(E), std::move(InstrBenchmark)};
590+
return {std::move(E), std::move(BenchmarkResult)};
589591
}
590592
outs() << "Check generated assembly with: /usr/bin/objdump -d "
591593
<< *ObjectFilePath << "\n";
592594
}
593595

594596
if (BenchmarkPhaseSelector < BenchmarkPhaseSelectorE::Measure) {
595-
InstrBenchmark.Error = "actual measurements skipped.";
596-
return {Error::success(), std::move(InstrBenchmark)};
597+
BenchmarkResult.Error = "actual measurements skipped.";
598+
return {Error::success(), std::move(BenchmarkResult)};
597599
}
598600

599601
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>> Executor =
600-
createFunctionExecutor(std::move(ObjectFile), RC.InstrBenchmark.Key);
602+
createFunctionExecutor(std::move(ObjectFile), RC.BenchmarkResult.Key);
601603
if (!Executor)
602-
return {Executor.takeError(), std::move(InstrBenchmark)};
604+
return {Executor.takeError(), std::move(BenchmarkResult)};
603605
auto NewMeasurements = runMeasurements(**Executor);
604606

605607
if (Error E = NewMeasurements.takeError()) {
606-
return {std::move(E), std::move(InstrBenchmark)};
608+
return {std::move(E), std::move(BenchmarkResult)};
607609
}
608-
assert(InstrBenchmark.NumRepetitions > 0 && "invalid NumRepetitions");
610+
assert(BenchmarkResult.NumRepetitions > 0 && "invalid NumRepetitions");
609611
for (BenchmarkMeasure &BM : *NewMeasurements) {
610612
// Scale the measurements by instruction.
611-
BM.PerInstructionValue /= InstrBenchmark.NumRepetitions;
613+
BM.PerInstructionValue /= BenchmarkResult.NumRepetitions;
612614
// Scale the measurements by snippet.
613615
BM.PerSnippetValue *=
614-
static_cast<double>(InstrBenchmark.Key.Instructions.size()) /
615-
InstrBenchmark.NumRepetitions;
616+
static_cast<double>(BenchmarkResult.Key.Instructions.size()) /
617+
BenchmarkResult.NumRepetitions;
616618
}
617-
InstrBenchmark.Measurements = std::move(*NewMeasurements);
619+
BenchmarkResult.Measurements = std::move(*NewMeasurements);
618620

619-
return {Error::success(), std::move(InstrBenchmark)};
621+
return {Error::success(), std::move(BenchmarkResult)};
620622
}
621623

622624
Expected<std::string>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BenchmarkRunner {
5656
private:
5757
RunnableConfiguration() = default;
5858

59-
Benchmark InstrBenchmark;
59+
Benchmark BenchmarkResult;
6060
object::OwningBinary<object::ObjectFile> ObjectFile;
6161
};
6262

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static void runBenchmarkConfigurations(
410410
std::optional<StringRef> DumpFile;
411411
if (DumpObjectToDisk.getNumOccurrences())
412412
DumpFile = DumpObjectToDisk;
413-
auto [Err, InstrBenchmark] =
413+
auto [Err, BenchmarkResult] =
414414
Runner.runConfiguration(std::move(RC), DumpFile);
415415
if (Err) {
416416
// Errors from executing the snippets are fine.
@@ -419,9 +419,9 @@ static void runBenchmarkConfigurations(
419419
llvm::errs() << "llvm-exegesis error: " << toString(std::move(Err));
420420
exit(1);
421421
}
422-
InstrBenchmark.Error = toString(std::move(Err));
422+
BenchmarkResult.Error = toString(std::move(Err));
423423
}
424-
AllResults.push_back(std::move(InstrBenchmark));
424+
AllResults.push_back(std::move(BenchmarkResult));
425425
}
426426
Benchmark &Result = AllResults.front();
427427

0 commit comments

Comments
 (0)