diff options
Diffstat (limited to 'llvm/unittests/tools')
6 files changed, 97 insertions, 18 deletions
diff --git a/llvm/unittests/tools/llvm-exegesis/ARM/AssemblerTest.cpp b/llvm/unittests/tools/llvm-exegesis/ARM/AssemblerTest.cpp index 8c70b9eaaad..cca846354df 100644 --- a/llvm/unittests/tools/llvm-exegesis/ARM/AssemblerTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/ARM/AssemblerTest.cpp @@ -30,11 +30,13 @@ protected: }; TEST_F(ARMMachineFunctionGeneratorTest, DISABLED_JitFunction) { - Check(llvm::MCInst(), 0x1e, 0xff, 0x2f, 0xe1); + Check(ExegesisTarget::getDefault(), {}, llvm::MCInst(), 0x1e, 0xff, 0x2f, + 0xe1); } TEST_F(ARMMachineFunctionGeneratorTest, DISABLED_JitFunctionADDrr) { - Check(MCInstBuilder(llvm::ARM::ADDrr) + Check(ExegesisTarget::getDefault(), {llvm::ARM::R0}, + MCInstBuilder(llvm::ARM::ADDrr) .addReg(llvm::ARM::R0) .addReg(llvm::ARM::R0) .addReg(llvm::ARM::R0) diff --git a/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp b/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp new file mode 100644 index 00000000000..05b36a31b9e --- /dev/null +++ b/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp @@ -0,0 +1,31 @@ +//===-- BenchmarkRunnerTest.cpp ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "BenchmarkRunner.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace exegesis { + +namespace { + +TEST(ScratchSpaceTest, Works) { + BenchmarkRunner::ScratchSpace Space; + EXPECT_EQ(reinterpret_cast<intptr_t>(Space.ptr()) % + BenchmarkRunner::ScratchSpace::kAlignment, + 0u); + Space.ptr()[0] = 42; + Space.ptr()[BenchmarkRunner::ScratchSpace::kSize - 1] = 43; + Space.clear(); + EXPECT_EQ(Space.ptr()[0], 0); + EXPECT_EQ(Space.ptr()[BenchmarkRunner::ScratchSpace::kSize - 1], 0); +} + +} // namespace +} // namespace exegesis diff --git a/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt b/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt index 9afa17a8e80..387f8a58ebd 100644 --- a/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt +++ b/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt @@ -12,6 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_unittest(LLVMExegesisTests BenchmarkResultTest.cpp + BenchmarkRunnerTest.cpp ClusteringTest.cpp PerfHelperTest.cpp ) diff --git a/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h b/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h index a0cfb1d86c7..f0559494798 100644 --- a/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h +++ b/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "Assembler.h" +#include "BenchmarkRunner.h" #include "Target.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/CodeGen/MachineInstrBuilder.h" @@ -36,21 +37,19 @@ protected: } } - template <class... Bs> inline void Check(llvm::MCInst MCInst, Bs... Bytes) { - CheckWithSetup(ExegesisTarget::getDefault(), {}, MCInst, Bytes...); - } - template <class... Bs> - inline void CheckWithSetup(const ExegesisTarget &ET, - llvm::ArrayRef<unsigned> RegsToDef, - llvm::MCInst MCInst, Bs... Bytes) { + inline void Check(const ExegesisTarget &ET, + llvm::ArrayRef<unsigned> RegsToDef, llvm::MCInst MCInst, + Bs... Bytes) { ExecutableFunction Function = (MCInst.getOpcode() == 0) ? assembleToFunction(ET, RegsToDef, {}) : assembleToFunction(ET, RegsToDef, {MCInst}); ASSERT_THAT(Function.getFunctionBytes().str(), testing::ElementsAre(Bytes...)); - if (CanExecute) - Function(); + if (CanExecute) { + BenchmarkRunner::ScratchSpace Scratch; + Function(Scratch.ptr()); + } } private: @@ -73,7 +72,8 @@ private: llvm::ArrayRef<llvm::MCInst> Instructions) { llvm::SmallString<256> Buffer; llvm::raw_svector_ostream AsmStream(Buffer); - assembleToStream(ET, createTargetMachine(), RegsToDef, Instructions, + assembleToStream(ET, createTargetMachine(), /*LiveIns=*/{}, + RegsToDef, Instructions, AsmStream); return ExecutableFunction(createTargetMachine(), getObjectFromBuffer(AsmStream.str())); 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 {}; } |