diff options
Diffstat (limited to 'llvm/unittests/tools/llvm-exegesis/X86')
-rw-r--r-- | llvm/unittests/tools/llvm-exegesis/X86/AssemblerTest.cpp | 27 | ||||
-rw-r--r-- | llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp | 30 |
2 files changed, 51 insertions, 6 deletions
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/AssemblerTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/AssemblerTest.cpp index 4e3c54accac..e83d004e8a6 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/AssemblerTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/AssemblerTest.cpp @@ -11,6 +11,9 @@ #include "X86InstrInfo.h" namespace exegesis { + +void InitializeX86ExegesisTarget(); + namespace { using llvm::MCInstBuilder; @@ -31,25 +34,39 @@ protected: LLVMInitializeX86TargetMC(); LLVMInitializeX86Target(); LLVMInitializeX86AsmPrinter(); + InitializeX86ExegesisTarget(); } }; TEST_F(X86MachineFunctionGeneratorTest, DISABLED_JitFunction) { - Check(llvm::MCInst(), 0xc3); + Check(ExegesisTarget::getDefault(), {}, llvm::MCInst(), 0xc3); } -TEST_F(X86MachineFunctionGeneratorTest, DISABLED_JitFunctionXOR32rr) { - Check(MCInstBuilder(XOR32rr).addReg(EAX).addReg(EAX).addReg(EAX), 0x31, 0xc0, +TEST_F(X86MachineFunctionGeneratorTest, DISABLED_JitFunctionXOR32rr_Default) { + Check(ExegesisTarget::getDefault(), {EAX}, + MCInstBuilder(XOR32rr).addReg(EAX).addReg(EAX).addReg(EAX), 0x31, 0xc0, 0xc3); } +TEST_F(X86MachineFunctionGeneratorTest, DISABLED_JitFunctionXOR32rr_X86) { + const auto *ET = ExegesisTarget::lookup(llvm::Triple("x86_64-unknown-linux")); + ASSERT_NE(ET, nullptr); + Check(*ET, {EAX}, MCInstBuilder(XOR32rr).addReg(EAX).addReg(EAX).addReg(EAX), + // mov eax, 1 + 0xb8, 0x01, 0x00, 0x00, 0x00, + // xor eax, eax + 0x31, 0xc0, 0xc3); +} + TEST_F(X86MachineFunctionGeneratorTest, DISABLED_JitFunctionMOV64ri) { - Check(MCInstBuilder(MOV64ri32).addReg(RAX).addImm(42), 0x48, 0xc7, 0xc0, 0x2a, + Check(ExegesisTarget::getDefault(), {}, + MCInstBuilder(MOV64ri32).addReg(RAX).addImm(42), 0x48, 0xc7, 0xc0, 0x2a, 0x00, 0x00, 0x00, 0xc3); } TEST_F(X86MachineFunctionGeneratorTest, DISABLED_JitFunctionMOV32ri) { - Check(MCInstBuilder(MOV32ri).addReg(EAX).addImm(42), 0xb8, 0x2a, 0x00, 0x00, + Check(ExegesisTarget::getDefault(), {}, + MCInstBuilder(MOV32ri).addReg(EAX).addImm(42), 0xb8, 0x2a, 0x00, 0x00, 0x00, 0xc3); } diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp index edacd7fe629..7467222db13 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp @@ -18,6 +18,9 @@ #include <unordered_set> namespace exegesis { + +void InitializeX86ExegesisTarget(); + namespace { using testing::AnyOf; @@ -41,6 +44,7 @@ protected: LLVMInitializeX86TargetMC(); LLVMInitializeX86Target(); LLVMInitializeX86AsmPrinter(); + InitializeX86ExegesisTarget(); } const LLVMState State; @@ -215,6 +219,30 @@ TEST_F(UopsSnippetGeneratorTest, NoTiedVariables) { EXPECT_THAT(II.VariableValues[3], IsInvalid()); } +TEST_F(UopsSnippetGeneratorTest, MemoryUse) { + // Mov32rm reads from memory. + const unsigned Opcode = llvm::X86::MOV32rm; + const SnippetPrototype Proto = checkAndGetConfigurations(Opcode); + EXPECT_THAT(Proto.Explanation, HasSubstr("no tied variables")); + ASSERT_THAT(Proto.Snippet, + SizeIs(UopsBenchmarkRunner::kMinNumDifferentAddresses)); + const InstructionInstance &II = Proto.Snippet[0]; + EXPECT_THAT(II.getOpcode(), Opcode); + ASSERT_THAT(II.VariableValues, SizeIs(6)); + EXPECT_EQ(II.VariableValues[2].getImm(), 1); + EXPECT_EQ(II.VariableValues[3].getReg(), 0u); + EXPECT_EQ(II.VariableValues[4].getImm(), 0); + EXPECT_EQ(II.VariableValues[5].getReg(), 0u); +} + +TEST_F(UopsSnippetGeneratorTest, MemoryUse_Movsb) { + // MOVSB writes to scratch memory register. + const unsigned Opcode = llvm::X86::MOVSB; + auto Error = Runner.generatePrototype(Opcode).takeError(); + EXPECT_TRUE((bool)Error); + llvm::consumeError(std::move(Error)); +} + class FakeBenchmarkRunner : public BenchmarkRunner { public: FakeBenchmarkRunner(const LLVMState &State) @@ -232,7 +260,7 @@ private: } std::vector<BenchmarkMeasure> - runMeasurements(const ExecutableFunction &EF, + runMeasurements(const ExecutableFunction &EF, ScratchSpace &Scratch, const unsigned NumRepetitions) const override { return {}; } |