blob: 3be4bec566a0bd5c6da6c9fe9b5c4d981cbad610 [file] [log] [blame]
Gordon Henriksen2e855e62007-12-23 16:59:28 +00001//===-- ExecutionEngineBindings.cpp - C bindings for EEs ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Gordon Henriksen2e855e62007-12-23 16:59:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the C bindings for the ExecutionEngine library.
11//
12//===----------------------------------------------------------------------===//
13
Gordon Henriksen2e855e62007-12-23 16:59:28 +000014#include "llvm-c/ExecutionEngine.h"
Gordon Henriksen2e855e62007-12-23 16:59:28 +000015#include "llvm/ExecutionEngine/ExecutionEngine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "llvm/ExecutionEngine/GenericValue.h"
Andres Freund6a84cfb2018-07-25 15:04:57 +000017#include "llvm/ExecutionEngine/JITEventListener.h"
Filip Pizlo6cfed362013-05-22 02:46:43 +000018#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
Filip Pizlo40be1e82013-05-01 20:59:00 +000019#include "llvm/IR/DerivedTypes.h"
20#include "llvm/IR/Module.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000021#include "llvm/Support/ErrorHandling.h"
David Blaikiedae3bbe2018-03-23 23:58:21 +000022#include "llvm/Target/CodeGenCWrappers.h"
Sanjay Patel2c403d62015-06-01 21:56:56 +000023#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000024#include <cstring>
Gordon Henriksen2e855e62007-12-23 16:59:28 +000025
26using namespace llvm;
27
Chandler Carruth0d338a52014-04-22 03:04:17 +000028#define DEBUG_TYPE "jit"
29
Eric Christopher3e397312013-04-22 22:47:22 +000030// Wrapping the C bindings types.
Filip Pizlo40be1e82013-05-01 20:59:00 +000031DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef)
Eric Christopher3e397312013-04-22 22:47:22 +000032
Eric Christopher3e397312013-04-22 22:47:22 +000033
Diego Novillo55557ce2015-07-27 18:27:23 +000034static LLVMTargetMachineRef wrap(const TargetMachine *P) {
Juergen Ributzka9ce88db2014-01-23 19:23:28 +000035 return
36 reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
37}
38
Gordon Henriksen2e855e62007-12-23 16:59:28 +000039/*===-- Operations on generic values --------------------------------------===*/
40
41LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
42 unsigned long long N,
Chris Lattnerd686c8e2010-01-09 22:27:07 +000043 LLVMBool IsSigned) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +000044 GenericValue *GenVal = new GenericValue();
45 GenVal->IntVal = APInt(unwrap<IntegerType>(Ty)->getBitWidth(), N, IsSigned);
46 return wrap(GenVal);
47}
48
49LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P) {
50 GenericValue *GenVal = new GenericValue();
51 GenVal->PointerVal = P;
52 return wrap(GenVal);
53}
54
55LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N) {
56 GenericValue *GenVal = new GenericValue();
57 switch (unwrap(TyRef)->getTypeID()) {
58 case Type::FloatTyID:
59 GenVal->FloatVal = N;
60 break;
61 case Type::DoubleTyID:
62 GenVal->DoubleVal = N;
63 break;
64 default:
Torok Edwinc23197a2009-07-14 16:55:14 +000065 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2e855e62007-12-23 16:59:28 +000066 }
67 return wrap(GenVal);
68}
69
70unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef) {
71 return unwrap(GenValRef)->IntVal.getBitWidth();
72}
73
74unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef,
Chris Lattnerd686c8e2010-01-09 22:27:07 +000075 LLVMBool IsSigned) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +000076 GenericValue *GenVal = unwrap(GenValRef);
77 if (IsSigned)
78 return GenVal->IntVal.getSExtValue();
79 else
80 return GenVal->IntVal.getZExtValue();
81}
82
83void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal) {
84 return unwrap(GenVal)->PointerVal;
85}
86
87double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal) {
88 switch (unwrap(TyRef)->getTypeID()) {
89 case Type::FloatTyID:
90 return unwrap(GenVal)->FloatVal;
91 case Type::DoubleTyID:
92 return unwrap(GenVal)->DoubleVal;
93 default:
Torok Edwinc23197a2009-07-14 16:55:14 +000094 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2e855e62007-12-23 16:59:28 +000095 }
96}
97
98void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal) {
99 delete unwrap(GenVal);
100}
101
102/*===-- Operations on execution engines -----------------------------------===*/
103
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000104LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
105 LLVMModuleRef M,
106 char **OutError) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000107 std::string Error;
Rafael Espindola3f4ed322014-08-19 04:04:25 +0000108 EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
Reid Kleckner4b1511b2009-07-18 00:42:18 +0000109 builder.setEngineKind(EngineKind::Either)
110 .setErrorStr(&Error);
111 if (ExecutionEngine *EE = builder.create()){
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000112 *OutEE = wrap(EE);
113 return 0;
114 }
115 *OutError = strdup(Error.c_str());
116 return 1;
117}
118
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000119LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
120 LLVMModuleRef M,
121 char **OutError) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000122 std::string Error;
Rafael Espindola3f4ed322014-08-19 04:04:25 +0000123 EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
Reid Kleckner4b1511b2009-07-18 00:42:18 +0000124 builder.setEngineKind(EngineKind::Interpreter)
125 .setErrorStr(&Error);
126 if (ExecutionEngine *Interp = builder.create()) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000127 *OutInterp = wrap(Interp);
128 return 0;
129 }
130 *OutError = strdup(Error.c_str());
131 return 1;
132}
133
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000134LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
135 LLVMModuleRef M,
136 unsigned OptLevel,
137 char **OutError) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000138 std::string Error;
Rafael Espindola3f4ed322014-08-19 04:04:25 +0000139 EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
Reid Kleckner4b1511b2009-07-18 00:42:18 +0000140 builder.setEngineKind(EngineKind::JIT)
141 .setErrorStr(&Error)
142 .setOptLevel((CodeGenOpt::Level)OptLevel);
143 if (ExecutionEngine *JIT = builder.create()) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000144 *OutJIT = wrap(JIT);
145 return 0;
146 }
147 *OutError = strdup(Error.c_str());
148 return 1;
149}
150
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000151void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions,
152 size_t SizeOfPassedOptions) {
153 LLVMMCJITCompilerOptions options;
Filip Pizlo6cfed362013-05-22 02:46:43 +0000154 memset(&options, 0, sizeof(options)); // Most fields are zero by default.
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000155 options.CodeModel = LLVMCodeModelJITDefault;
Fangrui Songaf7b1832018-07-30 19:41:25 +0000156
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000157 memcpy(PassedOptions, &options,
158 std::min(sizeof(options), SizeOfPassedOptions));
159}
160
161LLVMBool LLVMCreateMCJITCompilerForModule(
162 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
163 LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions,
164 char **OutError) {
Andrew Kaylord2755af2013-04-29 17:49:40 +0000165 LLVMMCJITCompilerOptions options;
166 // If the user passed a larger sized options struct, then they were compiled
167 // against a newer LLVM. Tell them that something is wrong.
168 if (SizeOfPassedOptions > sizeof(options)) {
169 *OutError = strdup(
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000170 "Refusing to use options struct that is larger than my own; assuming "
171 "LLVM library mismatch.");
Andrew Kaylord2755af2013-04-29 17:49:40 +0000172 return 1;
173 }
Fangrui Songaf7b1832018-07-30 19:41:25 +0000174
Andrew Kaylord2755af2013-04-29 17:49:40 +0000175 // Defend against the user having an old version of the API by ensuring that
176 // any fields they didn't see are cleared. We must defend against fields being
177 // set to the bitwise equivalent of zero, and assume that this means "do the
178 // default" as if that option hadn't been available.
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000179 LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylord2755af2013-04-29 17:49:40 +0000180 memcpy(&options, PassedOptions, SizeOfPassedOptions);
Fangrui Songaf7b1832018-07-30 19:41:25 +0000181
Andrew Kaylord2755af2013-04-29 17:49:40 +0000182 TargetOptions targetOptions;
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000183 targetOptions.EnableFastISel = options.EnableFastISel;
Akira Hatanaka01461202015-05-23 01:14:08 +0000184 std::unique_ptr<Module> Mod(unwrap(M));
185
186 if (Mod)
187 // Set function attribute "no-frame-pointer-elim" based on
188 // NoFramePointerElim.
Akira Hatanaka6f491352015-05-26 20:17:20 +0000189 for (auto &F : *Mod) {
190 auto Attrs = F.getAttributes();
Mehdi Aminid1fa61b2016-10-01 06:22:04 +0000191 StringRef Value(options.NoFramePointerElim ? "true" : "false");
Reid Kleckner67077702017-03-21 16:57:19 +0000192 Attrs = Attrs.addAttribute(F.getContext(), AttributeList::FunctionIndex,
Akira Hatanaka6f491352015-05-26 20:17:20 +0000193 "no-frame-pointer-elim", Value);
194 F.setAttributes(Attrs);
195 }
Andrew Kaylord2755af2013-04-29 17:49:40 +0000196
197 std::string Error;
Akira Hatanaka01461202015-05-23 01:14:08 +0000198 EngineBuilder builder(std::move(Mod));
Andrew Kaylord2755af2013-04-29 17:49:40 +0000199 builder.setEngineKind(EngineKind::JIT)
200 .setErrorStr(&Error)
Andrew Kaylord2755af2013-04-29 17:49:40 +0000201 .setOptLevel((CodeGenOpt::Level)options.OptLevel)
202 .setTargetOptions(targetOptions);
Rafael Espindola9aafb852017-08-03 02:16:21 +0000203 bool JIT;
204 if (Optional<CodeModel::Model> CM = unwrap(options.CodeModel, JIT))
205 builder.setCodeModel(*CM);
Filip Pizlo6cfed362013-05-22 02:46:43 +0000206 if (options.MCJMM)
Lang Hames5ab94e72014-12-03 00:51:19 +0000207 builder.setMCJITMemoryManager(
208 std::unique_ptr<RTDyldMemoryManager>(unwrap(options.MCJMM)));
Andrew Kaylord2755af2013-04-29 17:49:40 +0000209 if (ExecutionEngine *JIT = builder.create()) {
210 *OutJIT = wrap(JIT);
211 return 0;
212 }
213 *OutError = strdup(Error.c_str());
214 return 1;
215}
216
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000217void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE) {
218 delete unwrap(EE);
219}
220
221void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE) {
Amaury Secheta0bd1622016-01-15 00:23:34 +0000222 unwrap(EE)->finalizeObject();
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000223 unwrap(EE)->runStaticConstructorsDestructors(false);
224}
225
226void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE) {
Amaury Secheta0bd1622016-01-15 00:23:34 +0000227 unwrap(EE)->finalizeObject();
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000228 unwrap(EE)->runStaticConstructorsDestructors(true);
229}
230
231int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
232 unsigned ArgC, const char * const *ArgV,
233 const char * const *EnvP) {
Andrew Kaylord2755af2013-04-29 17:49:40 +0000234 unwrap(EE)->finalizeObject();
Benjamin Kramer9589ff82015-05-29 19:43:39 +0000235
236 std::vector<std::string> ArgVec(ArgV, ArgV + ArgC);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000237 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(F), ArgVec, EnvP);
238}
239
240LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
241 unsigned NumArgs,
242 LLVMGenericValueRef *Args) {
Andrew Kaylord2755af2013-04-29 17:49:40 +0000243 unwrap(EE)->finalizeObject();
Fangrui Songaf7b1832018-07-30 19:41:25 +0000244
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000245 std::vector<GenericValue> ArgVec;
246 ArgVec.reserve(NumArgs);
247 for (unsigned I = 0; I != NumArgs; ++I)
248 ArgVec.push_back(*unwrap(Args[I]));
Fangrui Songaf7b1832018-07-30 19:41:25 +0000249
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000250 GenericValue *Result = new GenericValue();
251 *Result = unwrap(EE)->runFunction(unwrap<Function>(F), ArgVec);
252 return wrap(Result);
253}
254
255void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000256}
257
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000258void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M){
Rafael Espindola3f4ed322014-08-19 04:04:25 +0000259 unwrap(EE)->addModule(std::unique_ptr<Module>(unwrap(M)));
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000260}
261
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000262LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
263 LLVMModuleRef *OutMod, char **OutError) {
264 Module *Mod = unwrap(M);
265 unwrap(EE)->removeModule(Mod);
266 *OutMod = wrap(Mod);
267 return 0;
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000268}
269
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000270LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
271 LLVMValueRef *OutFn) {
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000272 if (Function *F = unwrap(EE)->FindFunctionNamed(Name)) {
273 *OutFn = wrap(F);
274 return 0;
275 }
276 return 1;
277}
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +0000278
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000279void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
280 LLVMValueRef Fn) {
Eric Christopherd5dd8ce2014-09-02 22:28:02 +0000281 return nullptr;
Duncan Sandsd90fee92010-07-19 09:33:13 +0000282}
283
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +0000284LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
Mehdi Aminie02fce02015-07-16 16:34:23 +0000285 return wrap(&unwrap(EE)->getDataLayout());
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +0000286}
Gordon Henriksen54227f62008-06-20 02:16:11 +0000287
Juergen Ributzka9ce88db2014-01-23 19:23:28 +0000288LLVMTargetMachineRef
289LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE) {
290 return wrap(unwrap(EE)->getTargetMachine());
291}
292
Gordon Henriksen54227f62008-06-20 02:16:11 +0000293void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
294 void* Addr) {
295 unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);
296}
Chris Lattner1e42c5b2009-01-21 18:11:10 +0000297
298void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global) {
Andrew Kaylord2755af2013-04-29 17:49:40 +0000299 unwrap(EE)->finalizeObject();
Fangrui Songaf7b1832018-07-30 19:41:25 +0000300
Chris Lattner1e42c5b2009-01-21 18:11:10 +0000301 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
302}
Filip Pizlo6cfed362013-05-22 02:46:43 +0000303
Peter Zotov7bfc61d2014-12-22 18:53:11 +0000304uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name) {
305 return unwrap(EE)->getGlobalValueAddress(Name);
306}
307
308uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name) {
309 return unwrap(EE)->getFunctionAddress(Name);
310}
311
Filip Pizlo6cfed362013-05-22 02:46:43 +0000312/*===-- Operations on memory managers -------------------------------------===*/
313
314namespace {
315
316struct SimpleBindingMMFunctions {
Anders Waldenborg5be81232013-09-30 19:11:32 +0000317 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection;
318 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection;
319 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory;
320 LLVMMemoryManagerDestroyCallback Destroy;
Filip Pizlo6cfed362013-05-22 02:46:43 +0000321};
322
323class SimpleBindingMemoryManager : public RTDyldMemoryManager {
324public:
325 SimpleBindingMemoryManager(const SimpleBindingMMFunctions& Functions,
326 void *Opaque);
Alexander Kornienkoc16fc542015-04-11 02:11:45 +0000327 ~SimpleBindingMemoryManager() override;
Filip Pizlo6cfed362013-05-22 02:46:43 +0000328
Craig Topper838cb742014-03-08 07:51:20 +0000329 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
330 unsigned SectionID,
331 StringRef SectionName) override;
Filip Pizlo6cfed362013-05-22 02:46:43 +0000332
Craig Topper838cb742014-03-08 07:51:20 +0000333 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
334 unsigned SectionID, StringRef SectionName,
335 bool isReadOnly) override;
336
337 bool finalizeMemory(std::string *ErrMsg) override;
338
Filip Pizlo6cfed362013-05-22 02:46:43 +0000339private:
340 SimpleBindingMMFunctions Functions;
341 void *Opaque;
342};
343
344SimpleBindingMemoryManager::SimpleBindingMemoryManager(
345 const SimpleBindingMMFunctions& Functions,
346 void *Opaque)
347 : Functions(Functions), Opaque(Opaque) {
348 assert(Functions.AllocateCodeSection &&
349 "No AllocateCodeSection function provided!");
350 assert(Functions.AllocateDataSection &&
351 "No AllocateDataSection function provided!");
352 assert(Functions.FinalizeMemory &&
353 "No FinalizeMemory function provided!");
354 assert(Functions.Destroy &&
355 "No Destroy function provided!");
356}
357
358SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
359 Functions.Destroy(Opaque);
360}
361
362uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
Filip Pizlo6eb43d22013-10-02 00:59:25 +0000363 uintptr_t Size, unsigned Alignment, unsigned SectionID,
364 StringRef SectionName) {
365 return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID,
366 SectionName.str().c_str());
Filip Pizlo6cfed362013-05-22 02:46:43 +0000367}
368
369uint8_t *SimpleBindingMemoryManager::allocateDataSection(
Filip Pizlo6eb43d22013-10-02 00:59:25 +0000370 uintptr_t Size, unsigned Alignment, unsigned SectionID,
371 StringRef SectionName, bool isReadOnly) {
Filip Pizlo6cfed362013-05-22 02:46:43 +0000372 return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID,
Filip Pizlo6eb43d22013-10-02 00:59:25 +0000373 SectionName.str().c_str(),
Filip Pizlo6cfed362013-05-22 02:46:43 +0000374 isReadOnly);
375}
376
377bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
Craig Topper0b6cb712014-04-15 06:32:26 +0000378 char *errMsgCString = nullptr;
Filip Pizlo6cfed362013-05-22 02:46:43 +0000379 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
380 assert((result || !errMsgCString) &&
381 "Did not expect an error message if FinalizeMemory succeeded");
382 if (errMsgCString) {
383 if (ErrMsg)
384 *ErrMsg = errMsgCString;
385 free(errMsgCString);
386 }
387 return result;
388}
389
390} // anonymous namespace
391
392LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
393 void *Opaque,
Anders Waldenborg5be81232013-09-30 19:11:32 +0000394 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
395 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
396 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
397 LLVMMemoryManagerDestroyCallback Destroy) {
Fangrui Songaf7b1832018-07-30 19:41:25 +0000398
Filip Pizlo6cfed362013-05-22 02:46:43 +0000399 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
400 !Destroy)
Craig Topper0b6cb712014-04-15 06:32:26 +0000401 return nullptr;
Fangrui Songaf7b1832018-07-30 19:41:25 +0000402
Filip Pizlo6cfed362013-05-22 02:46:43 +0000403 SimpleBindingMMFunctions functions;
404 functions.AllocateCodeSection = AllocateCodeSection;
405 functions.AllocateDataSection = AllocateDataSection;
406 functions.FinalizeMemory = FinalizeMemory;
407 functions.Destroy = Destroy;
408 return wrap(new SimpleBindingMemoryManager(functions, Opaque));
409}
410
411void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM) {
412 delete unwrap(MM);
413}
414
Andres Freund6a84cfb2018-07-25 15:04:57 +0000415/*===-- JIT Event Listener functions -------------------------------------===*/
416
417
418#if !LLVM_USE_INTEL_JITEVENTS
419LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void)
420{
421 return nullptr;
422}
423#endif
424
425#if !LLVM_USE_OPROFILE
426LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
427{
428 return nullptr;
429}
430#endif
431
432#if !LLVM_USE_PERF
433LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void)
434{
435 return nullptr;
436}
437#endif