11#include < llvm/IR/DIBuilder.h>
22#include < llvm/IR/IRBuilder.h>
33#include < llvm/IR/DebugLoc.h>
4- #include < llvm/ExecutionEngine/ExecutionEngine .h>
5- #include < llvm/ExecutionEngine/RTDyldMemoryManager .h>
4+ #include < llvm/Target/TargetMachine .h>
5+ #include < llvm-c/TargetMachine .h>
66
77using namespace llvm ;
88
@@ -15,8 +15,6 @@ using namespace llvm;
1515#define LLVM_VERSION_LE (major, minor ) \
1616 (LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
1717
18- #include < llvm/Target/CodeGenCWrappers.h>
19-
2018#if LLVM_VERSION_GE(16, 0)
2119#define makeArrayRef ArrayRef
2220#endif
@@ -89,75 +87,4 @@ void LLVMExtTargetMachineEnableGlobalIsel(LLVMTargetMachineRef T, LLVMBool Enabl
8987 unwrap (T)->setGlobalISel (Enable);
9088}
9189
92- // Copy paste of https://github.com/llvm/llvm-project/blob/dace8224f38a31636a02fe9c2af742222831f70c/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp#L160-L214
93- // but with a parameter to set global isel state
94- LLVMBool LLVMExtCreateMCJITCompilerForModule (
95- LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
96- LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions,
97- LLVMBool EnableGlobalISel,
98- char **OutError) {
99- LLVMMCJITCompilerOptions options;
100- // If the user passed a larger sized options struct, then they were compiled
101- // against a newer LLVM. Tell them that something is wrong.
102- if (SizeOfPassedOptions > sizeof (options)) {
103- *OutError = strdup (
104- " Refusing to use options struct that is larger than my own; assuming "
105- " LLVM library mismatch." );
106- return 1 ;
107- }
108-
109-
110- // Defend against the user having an old version of the API by ensuring that
111- // any fields they didn't see are cleared. We must defend against fields being
112- // set to the bitwise equivalent of zero, and assume that this means "do the
113- // default" as if that option hadn't been available.
114- LLVMInitializeMCJITCompilerOptions (&options, sizeof (options));
115- memcpy (&options, PassedOptions, SizeOfPassedOptions);
116-
117-
118- TargetOptions targetOptions;
119- targetOptions.EnableFastISel = options.EnableFastISel ;
120- targetOptions.EnableGlobalISel = EnableGlobalISel;
121- std::unique_ptr<Module> Mod (unwrap (M));
122-
123- if (Mod)
124- // Set function attribute "frame-pointer" based on
125- // NoFramePointerElim.
126- for (auto &F : *Mod) {
127- auto Attrs = F.getAttributes ();
128- StringRef Value = options.NoFramePointerElim ? " all" : " none" ;
129- #if LLVM_VERSION_GE(14, 0)
130- Attrs = Attrs.addFnAttribute (F.getContext (), " frame-pointer" , Value);
131- #else
132- Attrs = Attrs.addAttribute (F.getContext (), AttributeList::FunctionIndex,
133- " frame-pointer" , Value);
134- #endif
135- F.setAttributes (Attrs);
136- }
137-
138-
139- std::string Error;
140- EngineBuilder builder (std::move (Mod));
141- builder.setEngineKind (EngineKind::JIT)
142- .setErrorStr (&Error)
143- .setOptLevel ((CodeGenOpt::Level)options.OptLevel )
144- .setTargetOptions (targetOptions);
145- bool JIT;
146- if (auto CM = unwrap (options.CodeModel , JIT))
147- builder.setCodeModel (*CM);
148- if (options.MCJMM )
149- builder.setMCJITMemoryManager (
150- std::unique_ptr<RTDyldMemoryManager>(unwrap (options.MCJMM )));
151-
152- TargetMachine* tm = builder.selectTarget ();
153- tm->setGlobalISel (EnableGlobalISel);
154-
155- if (ExecutionEngine *JIT = builder.create (tm)) {
156- *OutJIT = wrap (JIT);
157- return 0 ;
158- }
159- *OutError = strdup (Error.c_str ());
160- return 1 ;
161- }
162-
16390} // extern "C"
0 commit comments