[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / unittests / ExecutionEngine / MCJIT / MCJITTestAPICommon.h
blobf47de56d3e40ab9261f2ab173841cc46d2900783
1 //===- MCJITTestBase.h - Common base class for MCJIT Unit tests ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This class implements functionality shared by both MCJIT C API tests, and
10 // the C++ API tests.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
15 #define LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/IR/LegacyPassManager.h"
21 #include "llvm/InitializePasses.h"
22 #include "llvm/Support/Host.h"
23 #include "llvm/Support/TargetSelect.h"
24 #include "llvm/Support/TargetRegistry.h"
26 // Used to skip tests on unsupported architectures and operating systems.
27 // To skip a test, add this macro at the top of a test-case in a suite that
28 // inherits from MCJITTestBase. See MCJITTest.cpp for examples.
29 #define SKIP_UNSUPPORTED_PLATFORM \
30 do \
31 if (!ArchSupportsMCJIT() || !OSSupportsMCJIT() || !HostCanBeTargeted()) \
32 return; \
33 while(0)
35 namespace llvm {
37 class MCJITTestAPICommon {
38 protected:
39 MCJITTestAPICommon()
40 : HostTriple(sys::getProcessTriple())
42 InitializeNativeTarget();
43 InitializeNativeTargetAsmPrinter();
45 // FIXME: It isn't at all clear why this is necesasry, but without it we
46 // fail to initialize the AssumptionCacheTracker.
47 initializeAssumptionCacheTrackerPass(*PassRegistry::getPassRegistry());
49 #ifdef _WIN32
50 // On Windows, generate ELF objects by specifying "-elf" in triple
51 HostTriple += "-elf";
52 #endif // _WIN32
53 HostTriple = Triple::normalize(HostTriple);
56 bool HostCanBeTargeted() {
57 std::string Error;
58 return TargetRegistry::lookupTarget(HostTriple, Error) != nullptr;
61 /// Returns true if the host architecture is known to support MCJIT
62 bool ArchSupportsMCJIT() {
63 Triple Host(HostTriple);
64 // If ARCH is not supported, bail
65 if (!is_contained(SupportedArchs, Host.getArch()))
66 return false;
68 // If ARCH is supported and has no specific sub-arch support
69 if (!is_contained(HasSubArchs, Host.getArch()))
70 return true;
72 // If ARCH has sub-arch support, find it
73 SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin();
74 for(; I != SupportedSubArchs.end(); ++I)
75 if (Host.getArchName().startswith(*I))
76 return true;
78 return false;
81 /// Returns true if the host OS is known to support MCJIT
82 bool OSSupportsMCJIT() {
83 Triple Host(HostTriple);
85 if (find(UnsupportedEnvironments, Host.getEnvironment()) !=
86 UnsupportedEnvironments.end())
87 return false;
89 if (!is_contained(UnsupportedOSs, Host.getOS()))
90 return true;
92 return false;
95 std::string HostTriple;
96 SmallVector<Triple::ArchType, 4> SupportedArchs;
97 SmallVector<Triple::ArchType, 1> HasSubArchs;
98 SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory
99 SmallVector<Triple::OSType, 4> UnsupportedOSs;
100 SmallVector<Triple::EnvironmentType, 1> UnsupportedEnvironments;
103 } // namespace llvm
105 #endif