summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2016-10-12 09:00:44 +0000
committerDiana Picus <diana.picus@linaro.org>2016-10-12 09:00:44 +0000
commit40f93411541772fd35f40e37df3aabdb029a1e38 (patch)
tree0d2d73125f32168bed21064165c8d3d907f8c3d7 /llvm/unittests
parentcb8f2ef644df255196a78c8ea6981f38e9aa6f0c (diff)
downloadbcm5719-llvm-40f93411541772fd35f40e37df3aabdb029a1e38.tar.gz
bcm5719-llvm-40f93411541772fd35f40e37df3aabdb029a1e38.zip
Add AArch64 unit tests
Add unit tests for checking a few tricky instruction sizes. Also remove the old tests for the instruction sizes, which were clunky and brittle. Since this is the first set of target-specific unit tests, we need to add some CMake plumbing. In the future, adding unit tests for a given target will be as simple as creating a directory with the same name as the target under unittests/Target. The tests are only run if the target is enabled in LLVM_TARGETS_TO_BUILD. Differential Revision: https://reviews.llvm.org/D24548 llvm-svn: 283990
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/CMakeLists.txt1
-rw-r--r--llvm/unittests/Target/AArch64/CMakeLists.txt23
-rw-r--r--llvm/unittests/Target/AArch64/InstSizes.cpp122
-rw-r--r--llvm/unittests/Target/CMakeLists.txt5
4 files changed, 151 insertions, 0 deletions
diff --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt
index 1758d2b2704..67cf8bbd6ba 100644
--- a/llvm/unittests/CMakeLists.txt
+++ b/llvm/unittests/CMakeLists.txt
@@ -25,4 +25,5 @@ add_subdirectory(ObjectYAML)
add_subdirectory(Option)
add_subdirectory(ProfileData)
add_subdirectory(Support)
+add_subdirectory(Target)
add_subdirectory(Transforms)
diff --git a/llvm/unittests/Target/AArch64/CMakeLists.txt b/llvm/unittests/Target/AArch64/CMakeLists.txt
new file mode 100644
index 00000000000..ec1dafc1f2f
--- /dev/null
+++ b/llvm/unittests/Target/AArch64/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(
+ ${CMAKE_SOURCE_DIR}/lib/Target/AArch64
+ ${CMAKE_BINARY_DIR}/lib/Target/AArch64
+ )
+
+# FIXME: We're really requiring way too many components here, and a lot of it is
+# because of the TargetOptions
+set(LLVM_LINK_COMPONENTS
+ AArch64CodeGen
+ AArch64Desc
+ AArch64Info
+ CodeGen
+ Core
+ MC
+ MIRParser
+ SelectionDAG
+ Support
+ Target
+ )
+
+add_llvm_unittest(AArch64Tests
+ InstSizes.cpp
+ )
diff --git a/llvm/unittests/Target/AArch64/InstSizes.cpp b/llvm/unittests/Target/AArch64/InstSizes.cpp
new file mode 100644
index 00000000000..22b47c6852a
--- /dev/null
+++ b/llvm/unittests/Target/AArch64/InstSizes.cpp
@@ -0,0 +1,122 @@
+#include "AArch64Subtarget.h"
+#include "AArch64TargetMachine.h"
+#include "llvm/CodeGen/MIRParser/MIRParser.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+std::unique_ptr<TargetMachine> createTargetMachine() {
+ auto TT(Triple::normalize("aarch64--"));
+ std::string CPU("generic");
+ std::string FS("");
+
+ LLVMInitializeAArch64TargetInfo();
+ LLVMInitializeAArch64Target();
+ LLVMInitializeAArch64TargetMC();
+
+ std::string Error;
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
+ assert(TheTarget && "Target not registered");
+
+ return std::unique_ptr<TargetMachine>(
+ TheTarget->createTargetMachine(TT, CPU, FS, TargetOptions(), None,
+ CodeModel::Default, CodeGenOpt::Default));
+}
+
+std::unique_ptr<AArch64InstrInfo> createInstrInfo(TargetMachine *TM) {
+ AArch64Subtarget ST(TM->getTargetTriple(), TM->getTargetCPU(),
+ TM->getTargetFeatureString(), *TM, /* isLittle */ false);
+ return llvm::make_unique<AArch64InstrInfo>(ST);
+}
+
+/// The \p InputIRSnippet is only needed for things that can't be expressed in
+/// the \p InputMIRSnippet (global variables etc)
+/// TODO: Some of this might be useful for other architectures as well - extract
+/// the platform-independent parts somewhere they can be reused.
+void runChecks(
+ TargetMachine *TM, AArch64InstrInfo *II, const StringRef InputIRSnippet,
+ const StringRef InputMIRSnippet,
+ std::function<void(AArch64InstrInfo &, MachineFunction &)> Checks) {
+ LLVMContext Context;
+
+ auto MIRString =
+ "--- |\n"
+ " declare void @sizes()\n"
+ + InputIRSnippet.str() +
+ "...\n"
+ "---\n"
+ "name: sizes\n"
+ "body: |\n"
+ " bb.0:\n"
+ + InputMIRSnippet.str();
+
+ std::unique_ptr<MemoryBuffer> MBuffer = MemoryBuffer::getMemBuffer(MIRString);
+ std::unique_ptr<MIRParser> MParser =
+ createMIRParser(std::move(MBuffer), Context);
+ assert(MParser && "Couldn't create MIR parser");
+
+ std::unique_ptr<Module> M = MParser->parseLLVMModule();
+ assert(M && "Couldn't parse module");
+
+ M->setTargetTriple(TM->getTargetTriple().getTriple());
+ M->setDataLayout(TM->createDataLayout());
+
+ auto F = M->getFunction("sizes");
+ assert(F && "Couldn't find intended function");
+
+ MachineModuleInfo MMI(TM);
+ MMI.setMachineFunctionInitializer(MParser.get());
+ auto &MF = MMI.getMachineFunction(*F);
+
+ Checks(*II, MF);
+}
+
+} // anonymous namespace
+
+TEST(InstSizes, STACKMAP) {
+ std::unique_ptr<TargetMachine> TM = createTargetMachine();
+ std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());
+
+ runChecks(TM.get(), II.get(), "", " STACKMAP 0, 16\n"
+ " STACKMAP 1, 32\n",
+ [](AArch64InstrInfo &II, MachineFunction &MF) {
+ auto I = MF.begin()->begin();
+ EXPECT_EQ(16u, II.getInstSizeInBytes(*I));
+ ++I;
+ EXPECT_EQ(32u, II.getInstSizeInBytes(*I));
+ });
+}
+
+TEST(InstSizes, PATCHPOINT) {
+ std::unique_ptr<TargetMachine> TM = createTargetMachine();
+ std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());
+
+ runChecks(TM.get(), II.get(), "",
+ " PATCHPOINT 0, 16, 0, 0, 0, csr_aarch64_aapcs\n"
+ " PATCHPOINT 1, 32, 0, 0, 0, csr_aarch64_aapcs\n",
+ [](AArch64InstrInfo &II, MachineFunction &MF) {
+ auto I = MF.begin()->begin();
+ EXPECT_EQ(16u, II.getInstSizeInBytes(*I));
+ ++I;
+ EXPECT_EQ(32u, II.getInstSizeInBytes(*I));
+ });
+}
+
+TEST(InstSizes, TLSDESC_CALLSEQ) {
+ std::unique_ptr<TargetMachine> TM = createTargetMachine();
+ std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());
+
+ runChecks(
+ TM.get(), II.get(),
+ " @ThreadLocalGlobal = external thread_local global i32, align 8\n",
+ " TLSDESC_CALLSEQ target-flags(aarch64-tls) @ThreadLocalGlobal\n",
+ [](AArch64InstrInfo &II, MachineFunction &MF) {
+ auto I = MF.begin()->begin();
+ EXPECT_EQ(16u, II.getInstSizeInBytes(*I));
+ });
+}
diff --git a/llvm/unittests/Target/CMakeLists.txt b/llvm/unittests/Target/CMakeLists.txt
new file mode 100644
index 00000000000..9015029b097
--- /dev/null
+++ b/llvm/unittests/Target/CMakeLists.txt
@@ -0,0 +1,5 @@
+foreach(t ${LLVM_TARGETS_TO_BUILD})
+ if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${t})
+ add_subdirectory(${t})
+ endif()
+endforeach()
OpenPOWER on IntegriCloud