From c6268f3ba2c5c3d33e32534f7b602aa396982cdb Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Mon, 1 Oct 2018 11:46:06 +0000 Subject: [PATCH] [llvm-exegesis][NFC] Make randomizeUnsetVariables a free function. Summary: This is prelimineary to moving random functions to SnippetGenerator. Reviewers: courbet Subscribers: tschuett, llvm-commits Differential Revision: https://reviews.llvm.org/D52718 llvm-svn: 343456 --- llvm/tools/llvm-exegesis/lib/CodeTemplate.cpp | 18 +++++++++--------- llvm/tools/llvm-exegesis/lib/CodeTemplate.h | 9 +++++---- llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp | 9 +++++---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/CodeTemplate.cpp b/llvm/tools/llvm-exegesis/lib/CodeTemplate.cpp index f311179..677bddd 100644 --- a/llvm/tools/llvm-exegesis/lib/CodeTemplate.cpp +++ b/llvm/tools/llvm-exegesis/lib/CodeTemplate.cpp @@ -67,15 +67,6 @@ bool InstructionTemplate::hasImmediateVariables() const { }); } -void InstructionTemplate::randomizeUnsetVariables( - const llvm::BitVector &ForbiddenRegs) { - for (const Variable &Var : Instr.Variables) { - llvm::MCOperand &AssignedValue = getValueFor(Var); - if (!AssignedValue.isValid()) - randomize(Instr, Var, AssignedValue, ForbiddenRegs); - } -} - llvm::MCInst InstructionTemplate::build() const { llvm::MCInst Result; Result.setOpcode(Instr.Description->Opcode); @@ -161,4 +152,13 @@ void setRandomAliasing(const AliasingConfigurations &AliasingConfigurations, setRegisterOperandValue(randomElement(RandomConf.Uses), UseIB); } +void randomizeUnsetVariables(const llvm::BitVector &ForbiddenRegs, + InstructionTemplate &IT) { + for (const Variable &Var : IT.Instr.Variables) { + llvm::MCOperand &AssignedValue = IT.getValueFor(Var); + if (!AssignedValue.isValid()) + randomize(IT.Instr, Var, AssignedValue, ForbiddenRegs); + } +} + } // namespace exegesis diff --git a/llvm/tools/llvm-exegesis/lib/CodeTemplate.h b/llvm/tools/llvm-exegesis/lib/CodeTemplate.h index b11ef16..e330c6d 100644 --- a/llvm/tools/llvm-exegesis/lib/CodeTemplate.h +++ b/llvm/tools/llvm-exegesis/lib/CodeTemplate.h @@ -36,10 +36,6 @@ struct InstructionTemplate { const llvm::MCOperand &getValueFor(const Operand &Op) const; bool hasImmediateVariables() const; - // Assigns a Random Value to all Variables that are still Invalid. - // Do not use any of the registers in `ForbiddenRegs`. - void randomizeUnsetVariables(const llvm::BitVector &ForbiddenRegs); - // Builds an llvm::MCInst from this InstructionTemplate setting its operands // to the corresponding variable values. Precondition: All VariableValues must // be set. @@ -84,6 +80,11 @@ size_t randomBit(const llvm::BitVector &Vector); void setRandomAliasing(const AliasingConfigurations &AliasingConfigurations, InstructionTemplate &DefIB, InstructionTemplate &UseIB); +// Assigns a Random Value to all Variables in IT that are still Invalid. +// Do not use any of the registers in `ForbiddenRegs`. +void randomizeUnsetVariables(const llvm::BitVector &ForbiddenRegs, + InstructionTemplate &IT); + } // namespace exegesis #endif // LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H diff --git a/llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp b/llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp index 6bfef1e..de57bf3 100644 --- a/llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp @@ -35,16 +35,17 @@ llvm::Expected> SnippetGenerator::generateConfigurations(unsigned Opcode) const { if (auto E = generateCodeTemplate(Opcode)) { CodeTemplate &CT = E.get(); + const llvm::BitVector &ForbiddenRegs = + CT.ScratchSpacePointerInReg + ? RATC.getRegister(CT.ScratchSpacePointerInReg).aliasedBits() + : RATC.emptyRegisters(); std::vector Output; // TODO: Generate as many BenchmarkCode as needed. { BenchmarkCode BC; BC.Info = CT.Info; for (InstructionTemplate &IT : CT.Instructions) { - IT.randomizeUnsetVariables( - CT.ScratchSpacePointerInReg - ? RATC.getRegister(CT.ScratchSpacePointerInReg).aliasedBits() - : RATC.emptyRegisters()); + randomizeUnsetVariables(ForbiddenRegs, IT); BC.Instructions.push_back(IT.build()); } if (CT.ScratchSpacePointerInReg) -- 2.7.4