diff options
author | Clement Courbet <courbet@google.com> | 2018-05-15 07:40:21 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-05-15 07:40:21 +0000 |
commit | 559d1e34df710a0c88dc775b014413c8f80804f7 (patch) | |
tree | 8dfdec9fe097dc8b6613bc0c3c5eeb18fa493172 /llvm/unittests/tools/llvm-exegesis | |
parent | 27d4ca2df9333ac38046628f7cae752b00077892 (diff) | |
download | bcm5719-llvm-559d1e34df710a0c88dc775b014413c8f80804f7.tar.gz bcm5719-llvm-559d1e34df710a0c88dc775b014413c8f80804f7.zip |
[llvm-exegesis] InMemoryAssembler: handle return-less targets (e.g. arm).
Summary: Arm does not have a ret code per se.
Reviewers: gchatelet
Subscribers: mgorny, javed.absar, kristof.beyls, tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D45672
llvm-svn: 332331
Diffstat (limited to 'llvm/unittests/tools/llvm-exegesis')
3 files changed, 103 insertions, 3 deletions
diff --git a/llvm/unittests/tools/llvm-exegesis/ARM/CMakeLists.txt b/llvm/unittests/tools/llvm-exegesis/ARM/CMakeLists.txt new file mode 100644 index 00000000000..aacb23b55b4 --- /dev/null +++ b/llvm/unittests/tools/llvm-exegesis/ARM/CMakeLists.txt @@ -0,0 +1,20 @@ +include_directories( + ${LLVM_MAIN_SRC_DIR}/lib/Target/ARM + ${LLVM_BINARY_DIR}/lib/Target/ARM + ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib + ) + +set(LLVM_LINK_COMPONENTS + MC + MCParser + Object + Support + Symbolize + ARM + ) + +add_llvm_unittest(LLVMExegesisARMTests + InMemoryAssemblerTest.cpp + ) +target_link_libraries(LLVMExegesisARMTests PRIVATE LLVMExegesis) + diff --git a/llvm/unittests/tools/llvm-exegesis/ARM/InMemoryAssemblerTest.cpp b/llvm/unittests/tools/llvm-exegesis/ARM/InMemoryAssemblerTest.cpp new file mode 100644 index 00000000000..50564e56ba0 --- /dev/null +++ b/llvm/unittests/tools/llvm-exegesis/ARM/InMemoryAssemblerTest.cpp @@ -0,0 +1,79 @@ +//===-- InMemoryAssemblerTest.cpp -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "InMemoryAssembler.h" +#include "ARMInstrInfo.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/TargetInstrInfo.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/MC/MCInstBuilder.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include <memory> + +namespace exegesis { +namespace { + +using llvm::MCInstBuilder; +using testing::ElementsAre; + +class MachineFunctionGeneratorTest : public ::testing::Test { +protected: + MachineFunctionGeneratorTest() + : TT("armv7-none-linux-gnueabi"), CpuName("") {} + + static void SetUpTestCase() { + LLVMInitializeARMTargetInfo(); + LLVMInitializeARMTargetMC(); + LLVMInitializeARMTarget(); + LLVMInitializeARMAsmPrinter(); + } + + std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() { + std::string Error; + const llvm::Target *TheTarget = + llvm::TargetRegistry::lookupTarget(TT, Error); + assert(TheTarget); + const llvm::TargetOptions Options; + return std::unique_ptr<llvm::LLVMTargetMachine>( + static_cast<llvm::LLVMTargetMachine *>(TheTarget->createTargetMachine( + TT, CpuName, "", Options, llvm::Reloc::Model::Static))); + } + +private: + const std::string TT; + const std::string CpuName; +}; + +TEST_F(MachineFunctionGeneratorTest, JitFunction) { + JitFunctionContext Context(createTargetMachine()); + JitFunction Function(std::move(Context), {}); + ASSERT_THAT(Function.getFunctionBytes().str(), + ElementsAre(0x1e, 0xff, 0x2f, 0xe1)); +} + +TEST_F(MachineFunctionGeneratorTest, JitFunctionADDrr) { + JitFunctionContext Context(createTargetMachine()); + JitFunction Function(std::move(Context), {MCInstBuilder(llvm::ARM::ADDrr) + .addReg(llvm::ARM::R0) + .addReg(llvm::ARM::R0) + .addReg(llvm::ARM::R0) + .addImm(llvm::ARMCC::AL) + .addReg(0) + .addReg(0)}); + ASSERT_THAT(Function.getFunctionBytes().str(), + ElementsAre(0x00, 0x00, 0x80, 0xe0, 0x1e, 0xff, 0x2f, 0xe1)); +} + +} // namespace +} // namespace exegesis diff --git a/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt b/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt index 6f12bb1c163..22b5f1d79c3 100644 --- a/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt +++ b/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt @@ -23,7 +23,8 @@ if(LLVM_ENABLE_LIBPFM AND HAVE_LIBPFM) endif() if(LLVM_TARGETS_TO_BUILD MATCHES "X86") - add_subdirectory( - X86 - ) + add_subdirectory(X86) +endif() +if(LLVM_TARGETS_TO_BUILD MATCHES "ARM") + add_subdirectory(ARM) endif() |