Merge pull request #955 from ermshiperete/bug-xamarin-10537
[mono.git] / mono / mini / mini-llvm-cpp.cpp
1 //
2 // mini-llvm-cpp.cpp: C++ support classes for the mono LLVM integration
3 //
4 // (C) 2009-2011 Novell, Inc.
5 // Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
6 //
7
8 //
9 // We need to override some stuff in LLVM, but this cannot be done using the C
10 // interface, so we have to use some C++ code here.
11 // The things which we override are:
12 // - the default JIT code manager used by LLVM doesn't allocate memory using
13 //   MAP_32BIT, we require it.
14 // - add some callbacks so we can obtain the size of methods and their exception
15 //   tables.
16 //
17
18 //
19 // Mono's internal header files are not C++ clean, so avoid including them if 
20 // possible
21 //
22
23 #include "config.h"
24 //undef those as llvm defines them on its own config.h as well.
25 #undef PACKAGE_BUGREPORT
26 #undef PACKAGE_NAME
27 #undef PACKAGE_STRING
28 #undef PACKAGE_TARNAME
29 #undef PACKAGE_VERSION
30
31 #include <stdint.h>
32
33 #include <llvm/Support/raw_ostream.h>
34 #include <llvm/PassManager.h>
35 #include <llvm/ExecutionEngine/ExecutionEngine.h>
36 #include <llvm/ExecutionEngine/JITMemoryManager.h>
37 #include <llvm/ExecutionEngine/JITEventListener.h>
38 #include <llvm/Target/TargetOptions.h>
39 #include <llvm/Target/TargetRegisterInfo.h>
40 #include <llvm/IR/Verifier.h>
41 #include <llvm/Analysis/Passes.h>
42 #include <llvm/Transforms/Scalar.h>
43 #include <llvm/Support/CommandLine.h>
44 #include "llvm/Support/PassNameParser.h"
45 #include "llvm/Support/PrettyStackTrace.h"
46 #include <llvm/CodeGen/Passes.h>
47 #include <llvm/CodeGen/MachineFunctionPass.h>
48 #include <llvm/CodeGen/MachineFunction.h>
49 #include <llvm/CodeGen/MachineFrameInfo.h>
50 #include <llvm/IR/Function.h>
51 #include <llvm/IR/IRBuilder.h>
52 #include <llvm/IR/Module.h>
53 //#include <llvm/LinkAllPasses.h>
54
55 #include "llvm-c/Core.h"
56 #include "llvm-c/ExecutionEngine.h"
57
58 #include "mini-llvm-cpp.h"
59
60 #define LLVM_CHECK_VERSION(major,minor) \
61         ((LLVM_MAJOR_VERSION > (major)) ||                                                                      \
62          ((LLVM_MAJOR_VERSION == (major)) && (LLVM_MINOR_VERSION >= (minor))))
63
64 // extern "C" void LLVMInitializeARMTargetInfo();
65 // extern "C" void LLVMInitializeARMTarget ();
66 // extern "C" void LLVMInitializeARMTargetMC ();
67
68 using namespace llvm;
69
70 #ifndef MONO_CROSS_COMPILE
71
72 class MonoJITMemoryManager : public JITMemoryManager
73 {
74 private:
75         JITMemoryManager *mm;
76
77 public:
78         /* Callbacks installed by mono */
79         AllocCodeMemoryCb *alloc_cb;
80         DlSymCb *dlsym_cb;
81
82         MonoJITMemoryManager ();
83         ~MonoJITMemoryManager ();
84
85         void setMemoryWritable (void);
86
87         void setMemoryExecutable (void);
88
89         void AllocateGOT();
90
91     unsigned char *getGOTBase() const {
92                 return mm->getGOTBase ();
93     }
94
95         void setPoisonMemory(bool) {
96         }
97
98         unsigned char *startFunctionBody(const Function *F, 
99                                                                          uintptr_t &ActualSize);
100   
101         unsigned char *allocateStub(const GlobalValue* F, unsigned StubSize,
102                                                                  unsigned Alignment);
103   
104         void endFunctionBody(const Function *F, unsigned char *FunctionStart,
105                                                  unsigned char *FunctionEnd);
106
107         unsigned char *allocateSpace(intptr_t Size, unsigned Alignment);
108
109         uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment);
110   
111         void deallocateMemForFunction(const Function *F);
112   
113         unsigned char*startExceptionTable(const Function* F,
114                                                                           uintptr_t &ActualSize);
115   
116         void endExceptionTable(const Function *F, unsigned char *TableStart,
117                                                    unsigned char *TableEnd, 
118                                                    unsigned char* FrameRegister);
119
120         virtual void deallocateFunctionBody(void*) {
121         }
122
123         virtual void deallocateExceptionTable(void*) {
124         }
125
126         virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
127                                                                                  StringRef SectionName) {
128                 // FIXME:
129                 assert(0);
130                 return NULL;
131         }
132
133         virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
134                                                                                  StringRef SectionName, bool IsReadOnly) {
135                 // FIXME:
136                 assert(0);
137                 return NULL;
138         }
139
140         virtual bool applyPermissions(std::string*) {
141                 // FIXME:
142                 assert(0);
143                 return false;
144         }
145
146         virtual bool finalizeMemory(std::string *ErrMsg = 0) {
147                 // FIXME:
148                 assert(0);
149                 return false;
150         }
151
152         virtual void* getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure) {
153                 void *res;
154                 char *err;
155
156                 err = dlsym_cb (Name.c_str (), &res);
157                 if (err) {
158                         outs () << "Unable to resolve: " << Name << ": " << err << "\n";
159                         assert(0);
160                         return NULL;
161                 }
162                 return res;
163         }
164 };
165
166 MonoJITMemoryManager::MonoJITMemoryManager ()
167 {
168         mm = JITMemoryManager::CreateDefaultMemManager ();
169 }
170
171 MonoJITMemoryManager::~MonoJITMemoryManager ()
172 {
173         delete mm;
174 }
175
176 void
177 MonoJITMemoryManager::setMemoryWritable (void)
178 {
179 }
180
181 void
182 MonoJITMemoryManager::setMemoryExecutable (void)
183 {
184 }
185
186 void
187 MonoJITMemoryManager::AllocateGOT()
188 {
189         mm->AllocateGOT ();
190 }
191
192 unsigned char *
193 MonoJITMemoryManager::startFunctionBody(const Function *F, 
194                                         uintptr_t &ActualSize)
195 {
196         // FIXME: This leaks memory
197         if (ActualSize == 0)
198                 ActualSize = 128;
199         return alloc_cb (wrap (F), ActualSize);
200 }
201   
202 unsigned char *
203 MonoJITMemoryManager::allocateStub(const GlobalValue* F, unsigned StubSize,
204                            unsigned Alignment)
205 {
206         return alloc_cb (wrap (F), StubSize);
207 }
208   
209 void
210 MonoJITMemoryManager::endFunctionBody(const Function *F, unsigned char *FunctionStart,
211                                   unsigned char *FunctionEnd)
212 {
213 }
214
215 unsigned char *
216 MonoJITMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment)
217 {
218         return new unsigned char [Size];
219 }
220
221 uint8_t *
222 MonoJITMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment)
223 {
224         return new unsigned char [Size];
225 }
226
227 void
228 MonoJITMemoryManager::deallocateMemForFunction(const Function *F)
229 {
230 }
231   
232 unsigned char*
233 MonoJITMemoryManager::startExceptionTable(const Function* F,
234                                           uintptr_t &ActualSize)
235 {
236         return startFunctionBody(F, ActualSize);
237 }
238   
239 void
240 MonoJITMemoryManager::endExceptionTable(const Function *F, unsigned char *TableStart,
241                                         unsigned char *TableEnd, 
242                                         unsigned char* FrameRegister)
243 {
244 }
245
246 #else
247
248 class MonoJITMemoryManager {
249 };
250
251 #endif /* !MONO_CROSS_COMPILE */
252
253 class MonoJITEventListener : public JITEventListener {
254
255 public:
256         FunctionEmittedCb *emitted_cb;
257
258         MonoJITEventListener (FunctionEmittedCb *cb) {
259                 emitted_cb = cb;
260         }
261
262         virtual void NotifyFunctionEmitted(const Function &F,
263                                                                            void *Code, size_t Size,
264                                                                            const EmittedFunctionDetails &Details) {
265                 /*
266                  * X86TargetMachine::setCodeModelForJIT() sets the code model to Large on amd64,
267                  * which means the JIT will generate calls of the form
268                  * mov reg, <imm>
269                  * call *reg
270                  * Our trampoline code can't patch this. Passing CodeModel::Small to createJIT
271                  * doesn't seem to work, we need Default. A discussion is here:
272                  * http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-December/027999.html
273                  * There seems to no way to get the TargeMachine used by an EE either, so we
274                  * install a profiler hook and reset the code model here.
275                  * This should be inside an ifdef, but we can't include our config.h either,
276                  * since its definitions conflict with LLVM's config.h.
277                  * The LLVM mono branch contains a workaround.
278                  */
279                 emitted_cb (wrap (&F), Code, (char*)Code + Size);
280         }
281 };
282
283 class MonoEE {
284 public:
285         ExecutionEngine *EE;
286         MonoJITMemoryManager *mm;
287         MonoJITEventListener *listener;
288         FunctionPassManager *fpm;
289 };
290
291 void
292 mono_llvm_optimize_method (MonoEERef eeref, LLVMValueRef method)
293 {
294         MonoEE *mono_ee = (MonoEE*)eeref;
295
296         /*
297          * The verifier does some checks on the whole module, leading to quadratic behavior.
298          */
299         //verifyFunction (*(unwrap<Function> (method)));
300         mono_ee->fpm->run (*unwrap<Function> (method));
301 }
302
303 void
304 mono_llvm_dump_value (LLVMValueRef value)
305 {
306         /* Same as LLVMDumpValue (), but print to stdout */
307         fflush (stdout);
308         outs () << (*unwrap<Value> (value));
309 }
310
311 /* Missing overload for building an alloca with an alignment */
312 LLVMValueRef
313 mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty, 
314                                                 LLVMValueRef ArraySize,
315                                                 int alignment, const char *Name)
316 {
317         return wrap (unwrap (builder)->Insert (new AllocaInst (unwrap (Ty), unwrap (ArraySize), alignment), Name));
318 }
319
320 LLVMValueRef 
321 mono_llvm_build_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
322                                           const char *Name, gboolean is_volatile)
323 {
324         return wrap(unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name));
325 }
326
327 LLVMValueRef 
328 mono_llvm_build_aligned_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
329                                                           const char *Name, gboolean is_volatile, int alignment)
330 {
331         LoadInst *ins;
332
333         ins = unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name);
334         ins->setAlignment (alignment);
335
336         return wrap(ins);
337 }
338
339 LLVMValueRef 
340 mono_llvm_build_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
341                                           gboolean is_volatile)
342 {
343         return wrap(unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile));
344 }
345
346 LLVMValueRef 
347 mono_llvm_build_aligned_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
348                                                            gboolean is_volatile, int alignment)
349 {
350         StoreInst *ins;
351
352         ins = unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile);
353         ins->setAlignment (alignment);
354
355         return wrap (ins);
356 }
357
358 LLVMValueRef
359 mono_llvm_build_cmpxchg (LLVMBuilderRef builder, LLVMValueRef ptr, LLVMValueRef cmp, LLVMValueRef val)
360 {
361         AtomicCmpXchgInst *ins;
362
363         ins = unwrap(builder)->CreateAtomicCmpXchg (unwrap(ptr), unwrap (cmp), unwrap (val), SequentiallyConsistent);
364         return wrap (ins);
365 }
366
367 LLVMValueRef
368 mono_llvm_build_atomic_rmw (LLVMBuilderRef builder, AtomicRMWOp op, LLVMValueRef ptr, LLVMValueRef val)
369 {
370         AtomicRMWInst::BinOp aop = AtomicRMWInst::Xchg;
371         AtomicRMWInst *ins;
372
373         switch (op) {
374         case LLVM_ATOMICRMW_OP_XCHG:
375                 aop = AtomicRMWInst::Xchg;
376                 break;
377         case LLVM_ATOMICRMW_OP_ADD:
378                 aop = AtomicRMWInst::Add;
379                 break;
380         default:
381                 g_assert_not_reached ();
382                 break;
383         }
384
385         ins = unwrap (builder)->CreateAtomicRMW (aop, unwrap (ptr), unwrap (val), AcquireRelease);
386         return wrap (ins);
387 }
388
389 LLVMValueRef
390 mono_llvm_build_fence (LLVMBuilderRef builder)
391 {
392         FenceInst *ins;
393
394         ins = unwrap (builder)->CreateFence (AcquireRelease);
395         return wrap (ins);
396 }
397
398 void
399 mono_llvm_replace_uses_of (LLVMValueRef var, LLVMValueRef v)
400 {
401         Value *V = ConstantExpr::getTruncOrBitCast (unwrap<Constant> (v), unwrap (var)->getType ());
402         unwrap (var)->replaceAllUsesWith (V);
403 }
404
405 static cl::list<const PassInfo*, bool, PassNameParser>
406 PassList(cl::desc("Optimizations available:"));
407
408 static void
409 force_pass_linking (void)
410 {
411         // Make sure the rest is linked in, but never executed
412         if (g_getenv ("FOO") != (char*)-1)
413                 return;
414
415         // This is a subset of the passes in LinkAllPasses.h
416         // The utility passes and the interprocedural passes are commented out
417
418       (void) llvm::createAAEvalPass();
419       (void) llvm::createAggressiveDCEPass();
420       (void) llvm::createAliasAnalysisCounterPass();
421       (void) llvm::createAliasDebugger();
422           /*
423       (void) llvm::createArgumentPromotionPass();
424       (void) llvm::createStructRetPromotionPass();
425           */
426       (void) llvm::createBasicAliasAnalysisPass();
427       (void) llvm::createLibCallAliasAnalysisPass(0);
428       (void) llvm::createScalarEvolutionAliasAnalysisPass();
429       //(void) llvm::createBlockPlacementPass();
430       (void) llvm::createBreakCriticalEdgesPass();
431       (void) llvm::createCFGSimplificationPass();
432           /*
433       (void) llvm::createConstantMergePass();
434       (void) llvm::createConstantPropagationPass();
435           */
436           /*
437       (void) llvm::createDeadArgEliminationPass();
438           */
439       (void) llvm::createDeadCodeEliminationPass();
440       (void) llvm::createDeadInstEliminationPass();
441       (void) llvm::createDeadStoreEliminationPass();
442           /*
443       (void) llvm::createDeadTypeEliminationPass();
444       (void) llvm::createDomOnlyPrinterPass();
445       (void) llvm::createDomPrinterPass();
446       (void) llvm::createDomOnlyViewerPass();
447       (void) llvm::createDomViewerPass();
448       (void) llvm::createEdgeProfilerPass();
449       (void) llvm::createOptimalEdgeProfilerPass();
450       (void) llvm::createFunctionInliningPass();
451       (void) llvm::createAlwaysInlinerPass();
452       (void) llvm::createGlobalDCEPass();
453       (void) llvm::createGlobalOptimizerPass();
454       (void) llvm::createGlobalsModRefPass();
455       (void) llvm::createIPConstantPropagationPass();
456       (void) llvm::createIPSCCPPass();
457           */
458       (void) llvm::createIndVarSimplifyPass();
459       (void) llvm::createInstructionCombiningPass();
460           /*
461       (void) llvm::createInternalizePass(false);
462           */
463       (void) llvm::createLCSSAPass();
464       (void) llvm::createLICMPass();
465       (void) llvm::createLazyValueInfoPass();
466       //(void) llvm::createLoopDependenceAnalysisPass();
467           /*
468       (void) llvm::createLoopExtractorPass();
469           */
470       (void) llvm::createLoopSimplifyPass();
471       (void) llvm::createLoopStrengthReducePass();
472       (void) llvm::createLoopUnrollPass();
473       (void) llvm::createLoopUnswitchPass();
474       (void) llvm::createLoopRotatePass();
475       (void) llvm::createLowerInvokePass();
476           /*
477       (void) llvm::createLowerSetJmpPass();
478           */
479       (void) llvm::createLowerSwitchPass();
480       (void) llvm::createNoAAPass();
481           /*
482       (void) llvm::createNoProfileInfoPass();
483       (void) llvm::createProfileEstimatorPass();
484       (void) llvm::createProfileVerifierPass();
485       (void) llvm::createProfileLoaderPass();
486           */
487       (void) llvm::createPromoteMemoryToRegisterPass();
488       (void) llvm::createDemoteRegisterToMemoryPass();
489           /*
490       (void) llvm::createPruneEHPass();
491       (void) llvm::createPostDomOnlyPrinterPass();
492       (void) llvm::createPostDomPrinterPass();
493       (void) llvm::createPostDomOnlyViewerPass();
494       (void) llvm::createPostDomViewerPass();
495           */
496       (void) llvm::createReassociatePass();
497       (void) llvm::createSCCPPass();
498       (void) llvm::createScalarReplAggregatesPass();
499       //(void) llvm::createSimplifyLibCallsPass();
500           /*
501       (void) llvm::createSingleLoopExtractorPass();
502       (void) llvm::createStripSymbolsPass();
503       (void) llvm::createStripNonDebugSymbolsPass();
504       (void) llvm::createStripDeadDebugInfoPass();
505       (void) llvm::createStripDeadPrototypesPass();
506       (void) llvm::createTailCallEliminationPass();
507       (void) llvm::createTailDuplicationPass();
508       (void) llvm::createJumpThreadingPass();
509           */
510           /*
511       (void) llvm::createUnifyFunctionExitNodesPass();
512           */
513       (void) llvm::createInstCountPass();
514       (void) llvm::createCodeGenPreparePass();
515       (void) llvm::createGVNPass();
516       (void) llvm::createMemCpyOptPass();
517       (void) llvm::createLoopDeletionPass();
518           /*
519       (void) llvm::createPostDomTree();
520       (void) llvm::createPostDomFrontier();
521       (void) llvm::createInstructionNamerPass();
522       (void) llvm::createPartialSpecializationPass();
523       (void) llvm::createFunctionAttrsPass();
524       (void) llvm::createMergeFunctionsPass();
525       (void) llvm::createPrintModulePass(0);
526       (void) llvm::createPrintFunctionPass("", 0);
527       (void) llvm::createDbgInfoPrinterPass();
528       (void) llvm::createModuleDebugInfoPrinterPass();
529       (void) llvm::createPartialInliningPass();
530       (void) llvm::createGEPSplitterPass();
531       (void) llvm::createLintPass();
532           */
533       (void) llvm::createSinkingPass();
534 }
535
536 #ifndef MONO_CROSS_COMPILE
537
538 static gboolean inited;
539
540 static void
541 init_llvm (void)
542 {
543         if (inited)
544                 return;
545
546   force_pass_linking ();
547
548 #ifdef TARGET_ARM
549   LLVMInitializeARMTarget ();
550   LLVMInitializeARMTargetInfo ();
551   LLVMInitializeARMTargetMC ();
552 #else
553   LLVMInitializeX86Target ();
554   LLVMInitializeX86TargetInfo ();
555   LLVMInitializeX86TargetMC ();
556 #endif
557
558   PassRegistry &Registry = *PassRegistry::getPassRegistry();
559   initializeCore(Registry);
560   initializeScalarOpts(Registry);
561   initializeAnalysis(Registry);
562   initializeIPA(Registry);
563   initializeTransformUtils(Registry);
564   initializeInstCombine(Registry);
565   initializeTarget(Registry);
566
567   llvm::cl::ParseEnvironmentOptions("mono", "MONO_LLVM", "");
568
569   inited = true;
570 }
571
572 MonoEERef
573 mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb, LLVMExecutionEngineRef *ee)
574 {
575   std::string Error;
576   MonoEE *mono_ee;
577
578   init_llvm ();
579
580   mono_ee = new MonoEE ();
581
582   MonoJITMemoryManager *mono_mm = new MonoJITMemoryManager ();
583   mono_mm->alloc_cb = alloc_cb;
584   mono_mm->dlsym_cb = dlsym_cb;
585   mono_ee->mm = mono_mm;
586
587   /*
588    * The Default code model doesn't seem to work on amd64,
589    * test_0_fields_with_big_offsets (among others) crashes, because LLVM tries to call
590    * memset using a normal pcrel code which is in 32bit memory, while memset isn't.
591    */
592
593   TargetOptions opts;
594   opts.JITExceptionHandling = 1;
595
596   EngineBuilder b (unwrap (MP));
597 #ifdef TARGET_AMD64
598   ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setCodeModel (CodeModel::Large).setAllocateGVsWithCode (true).create ();
599 #else
600   ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setAllocateGVsWithCode (true).create ();
601 #endif
602   g_assert (EE);
603   mono_ee->EE = EE;
604
605   EE->InstallExceptionTableRegister (exception_cb);
606   MonoJITEventListener *listener = new MonoJITEventListener (emitted_cb);
607   EE->RegisterJITEventListener (listener);
608   mono_ee->listener = listener;
609
610   FunctionPassManager *fpm = new FunctionPassManager (unwrap (MP));
611   mono_ee->fpm = fpm;
612
613   fpm->add(new DataLayout(*EE->getDataLayout()));
614
615   if (PassList.size() > 0) {
616           /* Use the passes specified by the env variable */
617           /* Only the passes in force_pass_linking () can be used */
618           for (unsigned i = 0; i < PassList.size(); ++i) {
619                   const PassInfo *PassInf = PassList[i];
620                   Pass *P = 0;
621
622                   if (PassInf->getNormalCtor())
623                           P = PassInf->getNormalCtor()();
624                   fpm->add (P);
625           }
626   } else {
627           /* Use the same passes used by 'opt' by default, without the ipo passes */
628           const char *opts = "-simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -domfrontier -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-deletion -loop-simplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -gvn -simplifycfg";
629           char **args;
630           int i;
631
632           args = g_strsplit (opts, " ", 1000);
633           for (i = 0; args [i]; i++)
634                   ;
635           llvm::cl::ParseCommandLineOptions (i, args, "");
636           g_strfreev (args);
637
638           for (unsigned i = 0; i < PassList.size(); ++i) {
639                   const PassInfo *PassInf = PassList[i];
640                   Pass *P = 0;
641
642                   if (PassInf->getNormalCtor())
643                           P = PassInf->getNormalCtor()();
644                   g_assert (P->getPassKind () == llvm::PT_Function || P->getPassKind () == llvm::PT_Loop);
645                   fpm->add (P);
646           }
647
648           /*
649           fpm->add(createInstructionCombiningPass());
650           fpm->add(createReassociatePass());
651           fpm->add(createGVNPass());
652           fpm->add(createCFGSimplificationPass());
653           */
654   }
655
656   *ee = wrap (EE);
657
658   return mono_ee;
659 }
660
661 void
662 mono_llvm_dispose_ee (MonoEERef *eeref)
663 {
664         MonoEE *mono_ee = (MonoEE*)eeref;
665
666         delete mono_ee->EE;
667         delete mono_ee->fpm;
668         //delete mono_ee->mm;
669         delete mono_ee->listener;
670         delete mono_ee;
671 }
672
673 #else
674
675 MonoEERef
676 mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb, LLVMExecutionEngineRef *ee)
677 {
678         g_assert_not_reached ();
679         return NULL;
680 }
681
682 void
683 mono_llvm_dispose_ee (MonoEERef *eeref)
684 {
685         g_assert_not_reached ();
686 }
687
688 /* Not linked in */
689 void
690 LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
691                                          void* Addr)
692 {
693         g_assert_not_reached ();
694 }
695
696 void*
697 LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global)
698 {
699         g_assert_not_reached ();
700         return NULL;
701 }
702
703 #endif /* !MONO_CROSS_COMPILE */