xref: /aosp_15_r20/external/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- MCJITTestBase.h - Common base class for MCJIT Unit tests  ----------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This class implements functionality shared by both MCJIT C API tests, and
11*9880d681SAndroid Build Coastguard Worker // the C++ API tests.
12*9880d681SAndroid Build Coastguard Worker //
13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
16*9880d681SAndroid Build Coastguard Worker #define LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
17*9880d681SAndroid Build Coastguard Worker 
18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/Triple.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/LegacyPassManager.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/InitializePasses.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Host.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/TargetSelect.h"
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker // Used to skip tests on unsupported architectures and operating systems.
26*9880d681SAndroid Build Coastguard Worker // To skip a test, add this macro at the top of a test-case in a suite that
27*9880d681SAndroid Build Coastguard Worker // inherits from MCJITTestBase. See MCJITTest.cpp for examples.
28*9880d681SAndroid Build Coastguard Worker #define SKIP_UNSUPPORTED_PLATFORM \
29*9880d681SAndroid Build Coastguard Worker   do \
30*9880d681SAndroid Build Coastguard Worker     if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
31*9880d681SAndroid Build Coastguard Worker       return; \
32*9880d681SAndroid Build Coastguard Worker   while(0)
33*9880d681SAndroid Build Coastguard Worker 
34*9880d681SAndroid Build Coastguard Worker namespace llvm {
35*9880d681SAndroid Build Coastguard Worker 
36*9880d681SAndroid Build Coastguard Worker class MCJITTestAPICommon {
37*9880d681SAndroid Build Coastguard Worker protected:
MCJITTestAPICommon()38*9880d681SAndroid Build Coastguard Worker   MCJITTestAPICommon()
39*9880d681SAndroid Build Coastguard Worker     : HostTriple(sys::getProcessTriple())
40*9880d681SAndroid Build Coastguard Worker   {
41*9880d681SAndroid Build Coastguard Worker     InitializeNativeTarget();
42*9880d681SAndroid Build Coastguard Worker     InitializeNativeTargetAsmPrinter();
43*9880d681SAndroid Build Coastguard Worker 
44*9880d681SAndroid Build Coastguard Worker     // FIXME: It isn't at all clear why this is necesasry, but without it we
45*9880d681SAndroid Build Coastguard Worker     // fail to initialize the AssumptionCacheTracker.
46*9880d681SAndroid Build Coastguard Worker     initializeAssumptionCacheTrackerPass(*PassRegistry::getPassRegistry());
47*9880d681SAndroid Build Coastguard Worker 
48*9880d681SAndroid Build Coastguard Worker #ifdef LLVM_ON_WIN32
49*9880d681SAndroid Build Coastguard Worker     // On Windows, generate ELF objects by specifying "-elf" in triple
50*9880d681SAndroid Build Coastguard Worker     HostTriple += "-elf";
51*9880d681SAndroid Build Coastguard Worker #endif // LLVM_ON_WIN32
52*9880d681SAndroid Build Coastguard Worker     HostTriple = Triple::normalize(HostTriple);
53*9880d681SAndroid Build Coastguard Worker   }
54*9880d681SAndroid Build Coastguard Worker 
55*9880d681SAndroid Build Coastguard Worker   /// Returns true if the host architecture is known to support MCJIT
ArchSupportsMCJIT()56*9880d681SAndroid Build Coastguard Worker   bool ArchSupportsMCJIT() {
57*9880d681SAndroid Build Coastguard Worker     Triple Host(HostTriple);
58*9880d681SAndroid Build Coastguard Worker     // If ARCH is not supported, bail
59*9880d681SAndroid Build Coastguard Worker     if (std::find(SupportedArchs.begin(), SupportedArchs.end(), Host.getArch())
60*9880d681SAndroid Build Coastguard Worker         == SupportedArchs.end())
61*9880d681SAndroid Build Coastguard Worker       return false;
62*9880d681SAndroid Build Coastguard Worker 
63*9880d681SAndroid Build Coastguard Worker     // If ARCH is supported and has no specific sub-arch support
64*9880d681SAndroid Build Coastguard Worker     if (std::find(HasSubArchs.begin(), HasSubArchs.end(), Host.getArch())
65*9880d681SAndroid Build Coastguard Worker         == HasSubArchs.end())
66*9880d681SAndroid Build Coastguard Worker       return true;
67*9880d681SAndroid Build Coastguard Worker 
68*9880d681SAndroid Build Coastguard Worker     // If ARCH has sub-arch support, find it
69*9880d681SAndroid Build Coastguard Worker     SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin();
70*9880d681SAndroid Build Coastguard Worker     for(; I != SupportedSubArchs.end(); ++I)
71*9880d681SAndroid Build Coastguard Worker       if (Host.getArchName().startswith(I->c_str()))
72*9880d681SAndroid Build Coastguard Worker         return true;
73*9880d681SAndroid Build Coastguard Worker 
74*9880d681SAndroid Build Coastguard Worker     return false;
75*9880d681SAndroid Build Coastguard Worker   }
76*9880d681SAndroid Build Coastguard Worker 
77*9880d681SAndroid Build Coastguard Worker   /// Returns true if the host OS is known to support MCJIT
OSSupportsMCJIT()78*9880d681SAndroid Build Coastguard Worker   bool OSSupportsMCJIT() {
79*9880d681SAndroid Build Coastguard Worker     Triple Host(HostTriple);
80*9880d681SAndroid Build Coastguard Worker 
81*9880d681SAndroid Build Coastguard Worker     if (std::find(UnsupportedEnvironments.begin(), UnsupportedEnvironments.end(),
82*9880d681SAndroid Build Coastguard Worker                   Host.getEnvironment()) != UnsupportedEnvironments.end())
83*9880d681SAndroid Build Coastguard Worker       return false;
84*9880d681SAndroid Build Coastguard Worker 
85*9880d681SAndroid Build Coastguard Worker     if (std::find(UnsupportedOSs.begin(), UnsupportedOSs.end(), Host.getOS())
86*9880d681SAndroid Build Coastguard Worker         == UnsupportedOSs.end())
87*9880d681SAndroid Build Coastguard Worker       return true;
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker     return false;
90*9880d681SAndroid Build Coastguard Worker   }
91*9880d681SAndroid Build Coastguard Worker 
92*9880d681SAndroid Build Coastguard Worker   std::string HostTriple;
93*9880d681SAndroid Build Coastguard Worker   SmallVector<Triple::ArchType, 4> SupportedArchs;
94*9880d681SAndroid Build Coastguard Worker   SmallVector<Triple::ArchType, 1> HasSubArchs;
95*9880d681SAndroid Build Coastguard Worker   SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory
96*9880d681SAndroid Build Coastguard Worker   SmallVector<Triple::OSType, 4> UnsupportedOSs;
97*9880d681SAndroid Build Coastguard Worker   SmallVector<Triple::EnvironmentType, 1> UnsupportedEnvironments;
98*9880d681SAndroid Build Coastguard Worker };
99*9880d681SAndroid Build Coastguard Worker 
100*9880d681SAndroid Build Coastguard Worker } // namespace llvm
101*9880d681SAndroid Build Coastguard Worker 
102*9880d681SAndroid Build Coastguard Worker #endif
103*9880d681SAndroid Build Coastguard Worker 
104