forked from OSchip/llvm-project
[llvm-exegesis] Run unit tests on more platforms.
Summary: - Target-independent tests are run all the time. - Tests that codegen X86 code are run when X86 is in build targets. - Tests that run X86 jitted code are run only on X86 hosts. Reviewers: gchatelet Subscribers: mgorny, llvm-commits, tschuett Differential Revision: https://reviews.llvm.org/D45614 llvm-svn: 330008
This commit is contained in:
parent
53e423ed1e
commit
e1ae337cd5
|
@ -2,10 +2,9 @@ if(LLVM_TARGETS_TO_BUILD MATCHES "X86")
|
|||
add_subdirectory(
|
||||
llvm-cfi-verify
|
||||
)
|
||||
if(LLVM_HOST_TRIPLE MATCHES "x86_64")
|
||||
add_subdirectory(
|
||||
llvm-exegesis
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(
|
||||
llvm-exegesis
|
||||
)
|
||||
|
||||
|
|
|
@ -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 @@ set(LLVM_LINK_COMPONENTS
|
|||
Object
|
||||
Support
|
||||
Symbolize
|
||||
native
|
||||
)
|
||||
|
||||
add_llvm_unittest(LLVMExegesisTests
|
||||
BenchmarkResultTest.cpp
|
||||
InMemoryAssemblerTest.cpp
|
||||
InstructionSnippetGeneratorTest.cpp
|
||||
OperandGraphTest.cpp
|
||||
PerfHelperTest.cpp
|
||||
)
|
||||
|
@ -25,3 +20,9 @@ target_link_libraries(LLVMExegesisTests PRIVATE LLVMExegesis)
|
|||
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()
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
include_directories(
|
||||
${LLVM_MAIN_SRC_DIR}/lib/Target/X86
|
||||
${LLVM_BINARY_DIR}/lib/Target/X86
|
||||
${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib
|
||||
)
|
||||
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
MC
|
||||
MCParser
|
||||
Object
|
||||
Support
|
||||
Symbolize
|
||||
X86
|
||||
)
|
||||
|
||||
add_llvm_unittest(LLVMExegesisX86Tests
|
||||
InMemoryAssemblerTest.cpp
|
||||
InstructionSnippetGeneratorTest.cpp
|
||||
)
|
||||
target_link_libraries(LLVMExegesisX86Tests PRIVATE LLVMExegesis)
|
||||
|
|
@ -39,8 +39,10 @@ protected:
|
|||
CpuName(llvm::sys::getHostCPUName().str()) {}
|
||||
|
||||
static void SetUpTestCase() {
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
LLVMInitializeX86TargetInfo();
|
||||
LLVMInitializeX86TargetMC();
|
||||
LLVMInitializeX86Target();
|
||||
LLVMInitializeX86AsmPrinter();
|
||||
}
|
||||
|
||||
std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() {
|
||||
|
@ -54,12 +56,26 @@ protected:
|
|||
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 @@ TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunction) {
|
|||
// 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 @@ TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunctionXOR32rr) {
|
|||
// 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 @@ TEST_F(MachineFunctionGeneratorTest, DISABLED_JitFunctionMOV64ri) {
|
|||
// 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)});
|
|
@ -55,12 +55,15 @@ using llvm::X86::RAX;
|
|||
class MCInstrDescViewTest : public ::testing::Test {
|
||||
protected:
|
||||
MCInstrDescViewTest()
|
||||
: TheTriple(llvm::sys::getProcessTriple()),
|
||||
CpuName(llvm::sys::getHostCPUName().str()) {}
|
||||
: TheTriple("x86_64") {}
|
||||
|
||||
static void SetUpTestCase() {
|
||||
LLVMInitializeX86TargetInfo();
|
||||
LLVMInitializeX86TargetMC();
|
||||
LLVMInitializeX86Target();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
llvm::InitializeNativeTarget();
|
||||
|
||||
std::string Error;
|
||||
const auto *Target = llvm::TargetRegistry::lookupTarget(TheTriple, Error);
|
||||
InstrInfo.reset(Target->createMCInstrInfo());
|
||||
|
@ -68,7 +71,6 @@ protected:
|
|||
}
|
||||
|
||||
const std::string TheTriple;
|
||||
const std::string CpuName;
|
||||
std::unique_ptr<const llvm::MCInstrInfo> InstrInfo;
|
||||
std::unique_ptr<const llvm::MCRegisterInfo> RegInfo;
|
||||
};
|
Loading…
Reference in New Issue