[llvm] [Exegesis] Add supports to serialize/deserialize object files into benchmarks (PR #121993)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 13 16:00:11 PST 2025
================
@@ -520,77 +565,94 @@ void benchmarkMain() {
ExitWithError("cannot create benchmark runner");
}
- const auto Opcodes = getOpcodesOrDie(State);
- std::vector<BenchmarkCode> Configurations;
-
- unsigned LoopRegister =
- State.getExegesisTarget().getDefaultLoopCounterRegister(
- State.getTargetMachine().getTargetTriple());
-
- if (Opcodes.empty()) {
- Configurations = ExitOnErr(readSnippets(State, SnippetsFile));
- for (const auto &Configuration : Configurations) {
- if (ExecutionMode != BenchmarkRunner::ExecutionModeE::SubProcess &&
- (Configuration.Key.MemoryMappings.size() != 0 ||
- Configuration.Key.MemoryValues.size() != 0 ||
- Configuration.Key.SnippetAddress != 0))
- ExitWithError("Memory and snippet address annotations are only "
- "supported in subprocess "
- "execution mode");
- }
- LoopRegister = Configurations[0].Key.LoopRegister;
- }
+ std::vector<BenchmarkRunner::RunnableConfiguration> RunnableConfigs;
+ SmallVector<unsigned> Repetitions;
- SmallVector<std::unique_ptr<const SnippetRepetitor>, 2> Repetitors;
- if (RepetitionMode != Benchmark::RepetitionModeE::AggregateMin)
- Repetitors.emplace_back(
- SnippetRepetitor::Create(RepetitionMode, State, LoopRegister));
- else {
- for (Benchmark::RepetitionModeE RepMode :
- {Benchmark::RepetitionModeE::Duplicate,
- Benchmark::RepetitionModeE::Loop})
- Repetitors.emplace_back(
- SnippetRepetitor::Create(RepMode, State, LoopRegister));
- }
+ // Write to standard output if file is not set.
+ if (BenchmarkFile.empty())
+ BenchmarkFile = "-";
- BitVector AllReservedRegs;
- for (const std::unique_ptr<const SnippetRepetitor> &Repetitor : Repetitors)
- AllReservedRegs |= Repetitor->getReservedRegs();
-
- if (!Opcodes.empty()) {
- for (const unsigned Opcode : Opcodes) {
- // Ignore instructions without a sched class if
- // -ignore-invalid-sched-class is passed.
- if (IgnoreInvalidSchedClass &&
- State.getInstrInfo().get(Opcode).getSchedClass() == 0) {
- errs() << State.getInstrInfo().getName(Opcode)
- << ": ignoring instruction without sched class\n";
- continue;
+ if (!RunMeasurement.empty()) {
+ // Right now we only support resuming before the measurement phase.
+ auto ErrOrBuffer =
+ MemoryBuffer::getFileOrSTDIN(RunMeasurement, /*IsText=*/true);
+ if (!ErrOrBuffer)
+ report_fatal_error(errorCodeToError(ErrOrBuffer.getError()));
+
+ std::vector<Benchmark> Benchmarks =
+ ExitOnErr(Benchmark::readYamls(State, **ErrOrBuffer));
+ deserializeRunnableConfigurations(Benchmarks, *Runner, RunnableConfigs,
+ Repetitions);
+ } else {
+ const auto Opcodes = getOpcodesOrDie(State);
+ std::vector<BenchmarkCode> Configurations;
+
+ unsigned LoopRegister =
+ State.getExegesisTarget().getDefaultLoopCounterRegister(
+ State.getTargetMachine().getTargetTriple());
+
+ if (Opcodes.empty()) {
+ Configurations = ExitOnErr(readSnippets(State, SnippetsFile));
+ for (const auto &Configuration : Configurations) {
+ if (ExecutionMode != BenchmarkRunner::ExecutionModeE::SubProcess &&
+ (Configuration.Key.MemoryMappings.size() != 0 ||
----------------
topperc wrote:
!empty()?
https://github.com/llvm/llvm-project/pull/121993
More information about the llvm-commits
mailing list