1 //===- MCJITTestBase.h - Common base class for MCJIT Unit tests ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class implements functionality shared by both MCJIT C API tests, and
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
16 #define LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/IR/LegacyPassManager.h"
22 #include "llvm/InitializePasses.h"
23 #include "llvm/Support/Host.h"
24 #include "llvm/Support/TargetSelect.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 \
31 if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
37 class 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());
50 // On Windows, generate ELF objects by specifying "-elf" in triple
53 HostTriple
= Triple::normalize(HostTriple
);
56 /// Returns true if the host architecture is known to support MCJIT
57 bool ArchSupportsMCJIT() {
58 Triple
Host(HostTriple
);
59 // If ARCH is not supported, bail
60 if (!is_contained(SupportedArchs
, Host
.getArch()))
63 // If ARCH is supported and has no specific sub-arch support
64 if (!is_contained(HasSubArchs
, Host
.getArch()))
67 // If ARCH has sub-arch support, find it
68 SmallVectorImpl
<std::string
>::const_iterator I
= SupportedSubArchs
.begin();
69 for(; I
!= SupportedSubArchs
.end(); ++I
)
70 if (Host
.getArchName().startswith(*I
))
76 /// Returns true if the host OS is known to support MCJIT
77 bool OSSupportsMCJIT() {
78 Triple
Host(HostTriple
);
80 if (find(UnsupportedEnvironments
, Host
.getEnvironment()) !=
81 UnsupportedEnvironments
.end())
84 if (!is_contained(UnsupportedOSs
, Host
.getOS()))
90 std::string HostTriple
;
91 SmallVector
<Triple::ArchType
, 4> SupportedArchs
;
92 SmallVector
<Triple::ArchType
, 1> HasSubArchs
;
93 SmallVector
<std::string
, 2> SupportedSubArchs
; // We need to own the memory
94 SmallVector
<Triple::OSType
, 4> UnsupportedOSs
;
95 SmallVector
<Triple::EnvironmentType
, 1> UnsupportedEnvironments
;