[llvm] r357841 - [llvm-exegesis][X86] Handle CMOVcc/SETcc OPERAND_COND_CODE OperandType
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 6 07:16:26 PDT 2019
Author: lebedevri
Date: Sat Apr 6 07:16:26 2019
New Revision: 357841
URL: http://llvm.org/viewvc/llvm-project?rev=357841&view=rev
Log:
[llvm-exegesis][X86] Handle CMOVcc/SETcc OPERAND_COND_CODE OperandType
Summary:
D60041 / D60138 refactoring changed how CMOV/SETcc opcodes
are handled. concode is now an immediate, with it's own operand type.
This at least allows to not crash on the opcode.
However, this still won't generate all the snippets
with all the condcode enumerators. D60066 does that.
Reviewers: courbet, gchatelet
Reviewed By: gchatelet
Subscribers: tschuett, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60057
Added:
llvm/trunk/test/tools/llvm-exegesis/X86/latency-CMOV32rr.s
Modified:
llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp
llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h
llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
llvm/trunk/tools/llvm-exegesis/lib/Target.h
llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
Added: llvm/trunk/test/tools/llvm-exegesis/X86/latency-CMOV32rr.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-exegesis/X86/latency-CMOV32rr.s?rev=357841&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-exegesis/X86/latency-CMOV32rr.s (added)
+++ llvm/trunk/test/tools/llvm-exegesis/X86/latency-CMOV32rr.s Sat Apr 6 07:16:26 2019
@@ -0,0 +1,9 @@
+# RUN: llvm-exegesis -mode=latency -opcode-name=CMOV32rr | FileCheck %s
+
+CHECK: ---
+CHECK-NEXT: mode: latency
+CHECK-NEXT: key:
+CHECK-NEXT: instructions:
+CHECK-NEXT: CMOV32rr
+CHECK-NEXT: config: ''
+CHECK-LAST: ...
Modified: llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp?rev=357841&r1=357840&r2=357841&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp Sat Apr 6 07:16:26 2019
@@ -12,6 +12,7 @@
#include "Assembler.h"
#include "MCInstrDescView.h"
#include "SnippetGenerator.h"
+#include "Target.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
@@ -50,7 +51,7 @@ SnippetGenerator::generateConfigurations
BenchmarkCode BC;
BC.Info = CT.Info;
for (InstructionTemplate &IT : CT.Instructions) {
- randomizeUnsetVariables(ForbiddenRegs, IT);
+ randomizeUnsetVariables(State.getExegesisTarget(), ForbiddenRegs, IT);
BC.Instructions.push_back(IT.build());
}
if (CT.ScratchSpacePointerInReg)
@@ -156,29 +157,6 @@ static auto randomElement(const C &Conta
return Container[randomIndex(Container.size())];
}
-static void randomize(const Instruction &Instr, const Variable &Var,
- llvm::MCOperand &AssignedValue,
- const llvm::BitVector &ForbiddenRegs) {
- const Operand &Op = Instr.getPrimaryOperand(Var);
- switch (Op.getExplicitOperandInfo().OperandType) {
- case llvm::MCOI::OperandType::OPERAND_IMMEDIATE:
- // FIXME: explore immediate values too.
- AssignedValue = llvm::MCOperand::createImm(1);
- break;
- case llvm::MCOI::OperandType::OPERAND_REGISTER: {
- assert(Op.isReg());
- auto AllowedRegs = Op.getRegisterAliasing().sourceBits();
- assert(AllowedRegs.size() == ForbiddenRegs.size());
- for (auto I : ForbiddenRegs.set_bits())
- AllowedRegs.reset(I);
- AssignedValue = llvm::MCOperand::createReg(randomBit(AllowedRegs));
- break;
- }
- default:
- break;
- }
-}
-
static void setRegisterOperandValue(const RegisterOperandAssignment &ROV,
InstructionTemplate &IB) {
assert(ROV.Op);
@@ -212,12 +190,13 @@ void setRandomAliasing(const AliasingCon
setRegisterOperandValue(randomElement(RandomConf.Uses), UseIB);
}
-void randomizeUnsetVariables(const llvm::BitVector &ForbiddenRegs,
+void randomizeUnsetVariables(const ExegesisTarget &Target,
+ 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);
+ Target.randomizeMCOperand(IT.Instr, Var, AssignedValue, ForbiddenRegs);
}
}
Modified: llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h?rev=357841&r1=357840&r2=357841&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h Sat Apr 6 07:16:26 2019
@@ -88,7 +88,8 @@ void setRandomAliasing(const AliasingCon
// 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,
+void randomizeUnsetVariables(const ExegesisTarget &Target,
+ const llvm::BitVector &ForbiddenRegs,
InstructionTemplate &IT);
} // namespace exegesis
Modified: llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.cpp?rev=357841&r1=357840&r2=357841&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.cpp Sat Apr 6 07:16:26 2019
@@ -86,6 +86,30 @@ ExegesisTarget::createUopsBenchmarkRunne
return llvm::make_unique<UopsBenchmarkRunner>(State);
}
+void ExegesisTarget::randomizeMCOperand(
+ const Instruction &Instr, const Variable &Var,
+ llvm::MCOperand &AssignedValue,
+ const llvm::BitVector &ForbiddenRegs) const {
+ const Operand &Op = Instr.getPrimaryOperand(Var);
+ switch (Op.getExplicitOperandInfo().OperandType) {
+ case llvm::MCOI::OperandType::OPERAND_IMMEDIATE:
+ // FIXME: explore immediate values too.
+ AssignedValue = llvm::MCOperand::createImm(1);
+ break;
+ case llvm::MCOI::OperandType::OPERAND_REGISTER: {
+ assert(Op.isReg());
+ auto AllowedRegs = Op.getRegisterAliasing().sourceBits();
+ assert(AllowedRegs.size() == ForbiddenRegs.size());
+ for (auto I : ForbiddenRegs.set_bits())
+ AllowedRegs.reset(I);
+ AssignedValue = llvm::MCOperand::createReg(randomBit(AllowedRegs));
+ break;
+ }
+ default:
+ break;
+ }
+}
+
static_assert(std::is_pod<PfmCountersInfo>::value,
"We shouldn't have dynamic initialization here");
const PfmCountersInfo PfmCountersInfo::Default = {nullptr, nullptr, nullptr,
Modified: llvm/trunk/tools/llvm-exegesis/lib/Target.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.h?rev=357841&r1=357840&r2=357841&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.h Sat Apr 6 07:16:26 2019
@@ -102,6 +102,14 @@ public:
// matter as long as it's large enough.
virtual unsigned getMaxMemoryAccessSize() const { return 0; }
+ // Assigns a random operand of the right type to variable Var.
+ // The default implementation only handles generic operand types.
+ // The target is responsible for handling any operand
+ // starting from OPERAND_FIRST_TARGET.
+ virtual void randomizeMCOperand(const Instruction &Instr, const Variable &Var,
+ llvm::MCOperand &AssignedValue,
+ const llvm::BitVector &ForbiddenRegs) const;
+
// Creates a snippet generator for the given mode.
std::unique_ptr<SnippetGenerator>
createSnippetGenerator(InstructionBenchmark::ModeE Mode,
Modified: llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp?rev=357841&r1=357840&r2=357841&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp Sat Apr 6 07:16:26 2019
@@ -433,6 +433,10 @@ private:
unsigned getMaxMemoryAccessSize() const override { return 64; }
+ void randomizeMCOperand(const Instruction &Instr, const Variable &Var,
+ llvm::MCOperand &AssignedValue,
+ const llvm::BitVector &ForbiddenRegs) const override;
+
void fillMemoryOperands(InstructionTemplate &IT, unsigned Reg,
unsigned Offset) const override;
@@ -485,6 +489,23 @@ ExegesisX86Target::getScratchMemoryRegis
return TT.isOSWindows() ? llvm::X86::RCX : llvm::X86::RDI;
}
+void ExegesisX86Target::randomizeMCOperand(
+ const Instruction &Instr, const Variable &Var,
+ llvm::MCOperand &AssignedValue,
+ const llvm::BitVector &ForbiddenRegs) const {
+ ExegesisTarget::randomizeMCOperand(Instr, Var, AssignedValue, ForbiddenRegs);
+
+ const Operand &Op = Instr.getPrimaryOperand(Var);
+ switch (Op.getExplicitOperandInfo().OperandType) {
+ case llvm::X86::OperandType::OPERAND_COND_CODE:
+ // FIXME: explore all CC variants.
+ AssignedValue = llvm::MCOperand::createImm(1);
+ break;
+ default:
+ break;
+ }
+}
+
void ExegesisX86Target::fillMemoryOperands(InstructionTemplate &IT,
unsigned Reg,
unsigned Offset) const {
More information about the llvm-commits
mailing list