1 //===- MCJITTestBase.h - Common base class for MCJIT Unit tests ----------===//
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
7 //===----------------------------------------------------------------------===//
9 // This class implements functionality shared by both MCJIT C API tests, and
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"
25 // Used to skip tests on unsupported architectures and operating systems.
26 // To skip a test, add this macro at the top of a test-case in a suite that
27 // inherits from MCJITTestBase. See MCJITTest.cpp for examples.
28 #define SKIP_UNSUPPORTED_PLATFORM \
30 if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
36 class MCJITTestAPICommon
{
39 : HostTriple(sys::getProcessTriple())
41 InitializeNativeTarget();
42 InitializeNativeTargetAsmPrinter();
44 // FIXME: It isn't at all clear why this is necesasry, but without it we
45 // fail to initialize the AssumptionCacheTracker.
46 initializeAssumptionCacheTrackerPass(*PassRegistry::getPassRegistry());
49 // On Windows, generate ELF objects by specifying "-elf" in triple
52 HostTriple
= Triple::normalize(HostTriple
);
55 /// Returns true if the host architecture is known to support MCJIT
56 bool ArchSupportsMCJIT() {
57 Triple
Host(HostTriple
);
58 // If ARCH is not supported, bail
59 if (!is_contained(SupportedArchs
, Host
.getArch()))
62 // If ARCH is supported and has no specific sub-arch support
63 if (!is_contained(HasSubArchs
, Host
.getArch()))
66 // If ARCH has sub-arch support, find it
67 SmallVectorImpl
<std::string
>::const_iterator I
= SupportedSubArchs
.begin();
68 for(; I
!= SupportedSubArchs
.end(); ++I
)
69 if (Host
.getArchName().startswith(*I
))
75 /// Returns true if the host OS is known to support MCJIT
76 bool OSSupportsMCJIT() {
77 Triple
Host(HostTriple
);
79 if (find(UnsupportedEnvironments
, Host
.getEnvironment()) !=
80 UnsupportedEnvironments
.end())
83 if (!is_contained(UnsupportedOSs
, Host
.getOS()))
89 std::string HostTriple
;
90 SmallVector
<Triple::ArchType
, 4> SupportedArchs
;
91 SmallVector
<Triple::ArchType
, 1> HasSubArchs
;
92 SmallVector
<std::string
, 2> SupportedSubArchs
; // We need to own the memory
93 SmallVector
<Triple::OSType
, 4> UnsupportedOSs
;
94 SmallVector
<Triple::EnvironmentType
, 1> UnsupportedEnvironments
;