[llvm] r347209 - [llvm-exegesis][NFC] More tests for ExegesisTarget::fillMemoryOperands().
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 19 06:31:43 PST 2018
Author: courbet
Date: Mon Nov 19 06:31:43 2018
New Revision: 347209
URL: http://llvm.org/viewvc/llvm-project?rev=347209&view=rev
Log:
[llvm-exegesis][NFC] More tests for ExegesisTarget::fillMemoryOperands().
Reviewers: gchatelet
Subscribers: tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D54304
Modified:
llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp
llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h
llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Modified: llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp?rev=347209&r1=347208&r2=347209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp Mon Nov 19 06:31:43 2018
@@ -22,15 +22,16 @@
namespace llvm {
namespace exegesis {
-LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName) {
+LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName,
+ const std::string &Features) {
std::string Error;
const llvm::Target *const TheTarget =
llvm::TargetRegistry::lookupTarget(Triple, Error);
assert(TheTarget && "unknown target for host");
const llvm::TargetOptions Options;
- TargetMachine.reset(static_cast<llvm::LLVMTargetMachine *>(
- TheTarget->createTargetMachine(Triple, CpuName, /*Features*/ "", Options,
- llvm::Reloc::Model::Static)));
+ TargetMachine.reset(
+ static_cast<llvm::LLVMTargetMachine *>(TheTarget->createTargetMachine(
+ Triple, CpuName, Features, Options, llvm::Reloc::Model::Static)));
TheExegesisTarget = ExegesisTarget::lookup(TargetMachine->getTargetTriple());
if (!TheExegesisTarget) {
llvm::errs() << "no exegesis target for " << Triple << ", using default\n";
@@ -45,8 +46,8 @@ LLVMState::LLVMState(const std::string &
LLVMState::LLVMState(const std::string &CpuName)
: LLVMState(llvm::sys::getProcessTriple(),
- CpuName.empty() ? llvm::sys::getHostCPUName().str() : CpuName) {
-}
+ CpuName.empty() ? llvm::sys::getHostCPUName().str() : CpuName,
+ "") {}
std::unique_ptr<llvm::LLVMTargetMachine>
LLVMState::createTargetMachine() const {
Modified: llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h?rev=347209&r1=347208&r2=347209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h Mon Nov 19 06:31:43 2018
@@ -40,7 +40,8 @@ public:
LLVMState(const std::string &CpuName);
LLVMState(const std::string &Triple,
- const std::string &CpuName); // For tests.
+ const std::string &CpuName,
+ const std::string &Features = ""); // For tests.
const llvm::TargetMachine &getTargetMachine() const { return *TargetMachine; }
std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() const;
Modified: llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp?rev=347209&r1=347208&r2=347209&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/X86/TargetTest.cpp Mon Nov 19 06:31:43 2018
@@ -104,14 +104,7 @@ constexpr const char kTriple[] = "x86_64
class X86TargetTest : public ::testing::Test {
protected:
- X86TargetTest(const char *Features)
- : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) {
- EXPECT_THAT(ExegesisTarget_, NotNull());
- std::string error;
- Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error);
- EXPECT_THAT(Target_, NotNull());
- STI_.reset(Target_->createMCSubtargetInfo(kTriple, "core2", Features));
- }
+ X86TargetTest(const char *Features) : State(kTriple, "core2", Features) {}
static void SetUpTestCase() {
LLVMInitializeX86TargetInfo();
@@ -121,12 +114,11 @@ protected:
}
std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) {
- return ExegesisTarget_->setRegTo(*STI_, Reg, Value);
+ return State.getExegesisTarget().setRegTo(State.getSubtargetInfo(), Reg,
+ Value);
}
- const llvm::Target *Target_;
- const ExegesisTarget *const ExegesisTarget_;
- std::unique_ptr<llvm::MCSubtargetInfo> STI_;
+ LLVMState State;
};
class Core2TargetTest : public X86TargetTest {
@@ -360,8 +352,7 @@ TEST_F(Core2TargetTest, SetRegToFP1_32Bi
IsMovValueToStack(llvm::X86::MOV32mi, 0x11112222UL, 0),
IsMovValueToStack(llvm::X86::MOV32mi, 0x00000000UL, 4),
IsMovValueToStack(llvm::X86::MOV16mi, 0x0000UL, 8),
- OpcodeIs(llvm::X86::LD_Fp80m),
- IsStackDeallocate(10)));
+ OpcodeIs(llvm::X86::LD_Fp80m), IsStackDeallocate(10)));
}
TEST_F(Core2TargetTest, SetRegToFP1_4Bits) {
@@ -371,8 +362,33 @@ TEST_F(Core2TargetTest, SetRegToFP1_4Bit
IsMovValueToStack(llvm::X86::MOV32mi, 0x00000001UL, 0),
IsMovValueToStack(llvm::X86::MOV32mi, 0x00000000UL, 4),
IsMovValueToStack(llvm::X86::MOV16mi, 0x0000UL, 8),
- OpcodeIs(llvm::X86::LD_Fp80m),
- IsStackDeallocate(10)));
+ OpcodeIs(llvm::X86::LD_Fp80m), IsStackDeallocate(10)));
+}
+
+TEST_F(Core2Avx512TargetTest, FillMemoryOperands_ADD64rm) {
+ Instruction I(State.getInstrInfo(), State.getRATC(), X86::ADD64rm);
+ InstructionTemplate IT(I);
+ constexpr const int kOffset = 42;
+ State.getExegesisTarget().fillMemoryOperands(IT, X86::RDI, kOffset);
+ // Memory is operands 2-6.
+ EXPECT_THAT(IT.getValueFor(I.Operands[2]), IsReg(X86::RDI));
+ EXPECT_THAT(IT.getValueFor(I.Operands[3]), IsImm(1));
+ EXPECT_THAT(IT.getValueFor(I.Operands[4]), IsReg(0));
+ EXPECT_THAT(IT.getValueFor(I.Operands[5]), IsImm(kOffset));
+ EXPECT_THAT(IT.getValueFor(I.Operands[6]), IsReg(0));
+}
+
+TEST_F(Core2Avx512TargetTest, FillMemoryOperands_VGATHERDPSZ128rm) {
+ Instruction I(State.getInstrInfo(), State.getRATC(), X86::VGATHERDPSZ128rm);
+ InstructionTemplate IT(I);
+ constexpr const int kOffset = 42;
+ State.getExegesisTarget().fillMemoryOperands(IT, X86::RDI, kOffset);
+ // Memory is operands 4-8.
+ EXPECT_THAT(IT.getValueFor(I.Operands[4]), IsReg(X86::RDI));
+ EXPECT_THAT(IT.getValueFor(I.Operands[5]), IsImm(1));
+ EXPECT_THAT(IT.getValueFor(I.Operands[6]), IsReg(0));
+ EXPECT_THAT(IT.getValueFor(I.Operands[7]), IsImm(kOffset));
+ EXPECT_THAT(IT.getValueFor(I.Operands[8]), IsReg(0));
}
} // namespace
More information about the llvm-commits
mailing list