Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -26,6 +26,17 @@ namespace exegesis { +// A collection of instructions that are to be assembled, executed and measured. +struct BenchmarkConfiguration { + // This code is run before the Snippet is iterated. Since it is part of the + // measurement it should be as short as possible. It is usually used to setup + // the content of the Registers. + std::vector SnippetSetup; + + // The sequence of instructions that are to be repeated. + std::vector Snippet; +}; + // Common code for all benchmark modes. class BenchmarkRunner { public: @@ -56,9 +67,9 @@ private: virtual InstructionBenchmark::ModeE getMode() const = 0; - virtual llvm::Expected> - createSnippet(RegisterAliasingTrackerCache &RATC, unsigned Opcode, - llvm::raw_ostream &Debug) const = 0; + virtual llvm::Expected + createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned Opcode, + llvm::raw_ostream &Debug) const = 0; virtual std::vector runMeasurements(const ExecutableFunction &EF, Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -52,13 +52,14 @@ return InstrBenchmark; } llvm::raw_string_ostream InfoStream(InstrBenchmark.Info); - llvm::Expected> SnippetOrError = - createSnippet(RATC, Opcode, InfoStream); - if (llvm::Error E = SnippetOrError.takeError()) { + llvm::Expected ConfigurationOrError = + createConfiguration(RATC, Opcode, InfoStream); + if (llvm::Error E = ConfigurationOrError.takeError()) { InstrBenchmark.Error = llvm::toString(std::move(E)); return InstrBenchmark; } - std::vector &Snippet = SnippetOrError.get(); + BenchmarkConfiguration &Configuration = ConfigurationOrError.get(); + const std::vector &Snippet = Configuration.Snippet; if (Snippet.empty()) { InstrBenchmark.Error = "Empty snippet"; return InstrBenchmark; Index: llvm/trunk/tools/llvm-exegesis/lib/Latency.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Latency.h +++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h @@ -27,9 +27,9 @@ private: InstructionBenchmark::ModeE getMode() const override; - llvm::Expected> - createSnippet(RegisterAliasingTrackerCache &RATC, unsigned OpcodeIndex, - llvm::raw_ostream &Info) const override; + llvm::Expected + createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned OpcodeIndex, + llvm::raw_ostream &Info) const override; std::vector runMeasurements(const ExecutableFunction &EF, Index: llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp +++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp @@ -56,11 +56,12 @@ return InstructionBenchmark::Latency; } -llvm::Expected> -LatencyBenchmarkRunner::createSnippet(RegisterAliasingTrackerCache &RATC, - unsigned Opcode, - llvm::raw_ostream &Info) const { - std::vector Snippet; +llvm::Expected +LatencyBenchmarkRunner::createConfiguration(RegisterAliasingTrackerCache &RATC, + unsigned Opcode, + llvm::raw_ostream &Info) const { + BenchmarkConfiguration Configuration; + std::vector &Snippet = Configuration.Snippet; const llvm::MCInstrDesc &MCInstrDesc = MCInstrInfo.get(Opcode); const Instruction ThisInstruction(MCInstrDesc, RATC); @@ -77,7 +78,7 @@ Info << "implicit Self cycles, picking random values.\n"; } Snippet.push_back(randomizeUnsetVariablesAndBuild(ThisInstruction)); - return Snippet; + return Configuration; } // Let's try to create a dependency through another opcode. @@ -102,7 +103,7 @@ << ".\n"; Snippet.push_back(randomizeUnsetVariablesAndBuild(ThisInstruction)); Snippet.push_back(randomizeUnsetVariablesAndBuild(OtherInstruction)); - return Snippet; + return Configuration; } return makeError( Index: llvm/trunk/tools/llvm-exegesis/lib/Uops.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Uops.h +++ llvm/trunk/tools/llvm-exegesis/lib/Uops.h @@ -27,9 +27,9 @@ private: InstructionBenchmark::ModeE getMode() const override; - llvm::Expected> - createSnippet(RegisterAliasingTrackerCache &RATC, unsigned Opcode, - llvm::raw_ostream &Info) const override; + llvm::Expected + createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned Opcode, + llvm::raw_ostream &Info) const override; std::vector runMeasurements(const ExecutableFunction &EF, Index: llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp +++ llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp @@ -145,11 +145,12 @@ return InstructionBenchmark::Uops; } -llvm::Expected> -UopsBenchmarkRunner::createSnippet(RegisterAliasingTrackerCache &RATC, - unsigned Opcode, - llvm::raw_ostream &Info) const { - std::vector Snippet; +llvm::Expected +UopsBenchmarkRunner::createConfiguration(RegisterAliasingTrackerCache &RATC, + unsigned Opcode, + llvm::raw_ostream &Info) const { + BenchmarkConfiguration Configuration; + std::vector &Snippet = Configuration.Snippet; const llvm::MCInstrDesc &MCInstrDesc = MCInstrInfo.get(Opcode); const Instruction Instruction(MCInstrDesc, RATC); @@ -162,12 +163,12 @@ if (SelfAliasing.empty()) { Info << "instruction is parallel, repeating a random one.\n"; Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction)); - return Snippet; + return Configuration; } if (SelfAliasing.hasImplicitAliasing()) { Info << "instruction is serial, repeating a random one.\n"; Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction)); - return Snippet; + return Configuration; } const auto TiedVariables = getTiedVariables(Instruction); if (!TiedVariables.empty()) { @@ -188,7 +189,7 @@ Var->AssignedValue = llvm::MCOperand::createReg(Reg); Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction)); } - return Snippet; + return Configuration; } // No tied variables, we pick random values for defs. llvm::BitVector Defs(MCRegisterInfo.getNumRegs()); @@ -219,7 +220,7 @@ Info << "instruction has no tied variables picking Uses different from defs\n"; Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction)); - return Snippet; + return Configuration; } std::vector