Index: unittests/tools/CMakeLists.txt =================================================================== --- unittests/tools/CMakeLists.txt +++ unittests/tools/CMakeLists.txt @@ -2,10 +2,9 @@ add_subdirectory( llvm-cfi-verify ) - if(LLVM_HOST_TRIPLE MATCHES "x86_64") - add_subdirectory( - llvm-exegesis - ) - endif() endif() +add_subdirectory( + llvm-exegesis +) + Index: unittests/tools/llvm-exegesis/CMakeLists.txt =================================================================== --- unittests/tools/llvm-exegesis/CMakeLists.txt +++ unittests/tools/llvm-exegesis/CMakeLists.txt @@ -1,6 +1,4 @@ include_directories( - ${LLVM_MAIN_SRC_DIR}/lib/Target/X86 - ${LLVM_BINARY_DIR}/lib/Target/X86 ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib ) @@ -10,13 +8,10 @@ Object Support Symbolize - native ) add_llvm_unittest(LLVMExegesisTests BenchmarkResultTest.cpp - InMemoryAssemblerTest.cpp - InstructionSnippetGeneratorTest.cpp OperandGraphTest.cpp PerfHelperTest.cpp ) @@ -25,3 +20,9 @@ if(LLVM_ENABLE_LIBPFM AND HAVE_LIBPFM) target_link_libraries(LLVMExegesisTests PRIVATE pfm) endif() + +if(LLVM_TARGETS_TO_BUILD MATCHES "X86") + add_subdirectory( + X86 + ) +endif() Index: unittests/tools/llvm-exegesis/X86/CMakeLists.txt =================================================================== --- unittests/tools/llvm-exegesis/X86/CMakeLists.txt +++ unittests/tools/llvm-exegesis/X86/CMakeLists.txt @@ -10,18 +10,15 @@ Object Support Symbolize - native + X86 ) -add_llvm_unittest(LLVMExegesisTests - BenchmarkResultTest.cpp +add_llvm_unittest(LLVMExegesisX86Tests InMemoryAssemblerTest.cpp InstructionSnippetGeneratorTest.cpp - OperandGraphTest.cpp - PerfHelperTest.cpp ) -target_link_libraries(LLVMExegesisTests PRIVATE LLVMExegesis) +target_link_libraries(LLVMExegesisX86Tests PRIVATE LLVMExegesis) -if(LLVM_ENABLE_LIBPFM AND HAVE_LIBPFM) - target_link_libraries(LLVMExegesisTests PRIVATE pfm) -endif() +#if(LLVM_HOST_TRIPLE MATCHES "x86_64") + # set(, 1) + #endif() Index: unittests/tools/llvm-exegesis/X86/InMemoryAssemblerTest.cpp =================================================================== --- unittests/tools/llvm-exegesis/X86/InMemoryAssemblerTest.cpp +++ unittests/tools/llvm-exegesis/X86/InMemoryAssemblerTest.cpp @@ -39,8 +39,10 @@ CpuName(llvm::sys::getHostCPUName().str()) {} static void SetUpTestCase() { - llvm::InitializeNativeTarget(); - llvm::InitializeNativeTargetAsmPrinter(); + LLVMInitializeX86TargetInfo(); + LLVMInitializeX86TargetMC(); + LLVMInitializeX86Target(); + LLVMInitializeX86AsmPrinter(); } std::unique_ptr createTargetMachine() { @@ -54,12 +56,26 @@ TT, CpuName, "", Options, llvm::Reloc::Model::Static))); } + bool IsSupportedTarget() const { + return llvm::StringRef(TT).startswith_lower("x86_64"); + } + private: const std::string TT; const std::string CpuName; }; -TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunction) { +// Used to skip tests on unsupported architectures and operating systems. +// To skip a test, add this macro at the top of a test-case. +#define SKIP_UNSUPPORTED_PLATFORM \ + do \ + if (!IsSupportedTarget()) \ + return; \ + while(0) + + +TEST_F(MachineFunctionGeneratorTest, JitFunction) { + SKIP_UNSUPPORTED_PLATFORM; JitFunctionContext Context(createTargetMachine()); JitFunction Function(std::move(Context), {}); ASSERT_THAT(Function.getFunctionBytes().str(), ElementsAre(0xc3)); @@ -68,7 +84,8 @@ // Function(); } -TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunctionXOR32rr) { +TEST_F(MachineFunctionGeneratorTest, JitFunctionXOR32rr) { + SKIP_UNSUPPORTED_PLATFORM; JitFunctionContext Context(createTargetMachine()); JitFunction Function( std::move(Context), @@ -77,7 +94,8 @@ // Function(); } -TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunctionMOV64ri) { +TEST_F(MachineFunctionGeneratorTest, JitFunctionMOV64ri) { + SKIP_UNSUPPORTED_PLATFORM; JitFunctionContext Context(createTargetMachine()); JitFunction Function(std::move(Context), {MCInstBuilder(MOV64ri32).addReg(RAX).addImm(42)}); @@ -86,7 +104,8 @@ // Function(); } -TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunctionMOV32ri) { +TEST_F(MachineFunctionGeneratorTest, JitFunctionMOV32ri) { + SKIP_UNSUPPORTED_PLATFORM; JitFunctionContext Context(createTargetMachine()); JitFunction Function(std::move(Context), {MCInstBuilder(MOV32ri).addReg(EAX).addImm(42)}); Index: unittests/tools/llvm-exegesis/X86/InstructionSnippetGeneratorTest.cpp =================================================================== --- unittests/tools/llvm-exegesis/X86/InstructionSnippetGeneratorTest.cpp +++ unittests/tools/llvm-exegesis/X86/InstructionSnippetGeneratorTest.cpp @@ -55,12 +55,15 @@ class MCInstrDescViewTest : public ::testing::Test { protected: MCInstrDescViewTest() - : TheTriple(llvm::sys::getProcessTriple()), - CpuName(llvm::sys::getHostCPUName().str()) {} + : TheTriple("x86_64") {} - void SetUp() override { - llvm::InitializeNativeTarget(); + static void SetUpTestCase() { + LLVMInitializeX86TargetInfo(); + LLVMInitializeX86TargetMC(); + LLVMInitializeX86Target(); + } + void SetUp() override { std::string Error; const auto *Target = llvm::TargetRegistry::lookupTarget(TheTriple, Error); InstrInfo.reset(Target->createMCInstrInfo()); @@ -68,7 +71,6 @@ } const std::string TheTriple; - const std::string CpuName; std::unique_ptr InstrInfo; std::unique_ptr RegInfo; };