[LLVMdev] Capturing the assembler from MCJIT
Frank Winter
fwinter at jlab.org
Fri Mar 7 13:23:52 PST 2014
Is there a way to capture the assembler when using MCJIT? I was
searching the lists and this popped up:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/047873.html
However this is quite elaborate and I was wondering if there's not an
easier way to do this..?!
The setup I am using:
llvm::InitializeNativeTarget();
InitializeNativeTargetAsmPrinter(); // MCJIT
InitializeNativeTargetAsmParser(); // MCJIT
Mod = llvm::ParseIRFile( INPUT_FILE , Err, llvm::getGlobalContext());
Mod->setTargetTriple(llvm::sys::getProcessTriple());
llvm::EngineBuilder engineBuilder(Mod);
engineBuilder.setEngineKind(llvm::EngineKind::JIT);
engineBuilder.setOptLevel(llvm::CodeGenOpt::Aggressive);
TheExecutionEngine = engineBuilder.setUseMCJIT(true).create(); // MCJIT
targetMachine = engineBuilder.selectTarget();
mainFunc = Mod->getFunction("main");
llvm::FunctionPassManager *functionPassManager;
llvm::PassRegistry ®istry = *llvm::PassRegistry::getPassRegistry();
initializeScalarOpts(registry);
functionPassManager = new llvm::FunctionPassManager(Mod);
functionPassManager->add(llvm::createVerifierPass(llvm::PrintMessageAction));
targetMachine->addAnalysisPasses(*functionPassManager);
functionPassManager->add(new
llvm::TargetLibraryInfo(llvm::Triple(Mod->getTargetTriple())));
functionPassManager->add(new llvm::DataLayout(Mod));
functionPassManager->add(llvm::createBasicAliasAnalysisPass());
functionPassManager->add(llvm::createLICMPass());
functionPassManager->add(llvm::createGVNPass());
functionPassManager->add(llvm::createPromoteMemoryToRegisterPass());
functionPassManager->add(llvm::createLoopVectorizePass());
functionPassManager->add(llvm::createEarlyCSEPass());
functionPassManager->add(llvm::createInstructionCombiningPass());
functionPassManager->add(llvm::createCFGSimplificationPass());
functionPassManager->run(*mainFunc);
TheExecutionEngine->finalizeObject(); // MCJIT
void *fptr = TheExecutionEngine->getPointerToFunction( mainFunc );
Thanks,
Frank
More information about the llvm-dev
mailing list