Hi Lang, On Tue, 13 Aug 2019 at 20:47, Lang Hames <lhames at gmail.com> wrote:> > Sorry for the delayed reply. Looks like you have figured out how to solve your issue already. Out of interest, what did you need to do? Do you have anything that you would like to see added to http://llvm.org/docs/ORCv2.html ? >Sorry my post was misleading. I figured out below which was part of the problem. Code is still not getting optimized at all. I don't really know what is going on. Yet the same setup works fine with the Legacy ORC v1 setup. Any help is appreciated. Here are again the links to the relevant code: https://github.com/dibyendumajumdar/ravi/blob/master/include/ravi_llvmcodegen.h https://github.com/dibyendumajumdar/ravi/blob/master/src/ravi_llvmjit.cpp Just look sections marked USE_ORCv2_JIT.>> > Optimize Module is just a function object. >> > >> >> Thank you - I fixed that now.Regards Dibyendu
Hi Dibyendu, A couple of notes to simplify your code. The following: #if USE_ORCv2_JIT auto FPM = llvm::make_unique<FunctionPassManager>(TSM.getModule()); #else std::unique_ptr<FunctionPassManager> FPM(new FunctionPassManager(M.get())); #endif can be reduced to auto FPM = llvm::make_unique<FunctionPassManager>(&*M); since M must be non-null. Likewise, this: #if USE_ORCv2_JIT for (auto &F : *TSM.getModule()) FPM->run(F); #else for (auto &F : *M) FPM->run(F); #endif can be reduced to for (auto &F : *M) FPM->run(F); When you say your code is not getting optimized, do you mean that IR optimizations are not being applied, or that codegen optimizations are not being applied? What do you see if you dump the modules before/after running the pass manager on them, like this: dbgs() << "Before optimization:\n" << *M << "\n"; for (auto &F : *M) FPM->run(F); dbgs() << "Before optimization:\n" << *M << "\n"; I expect that output to be the same for both ORC and ORCv2. If not something is going wrong with IR optimization. CodeGen optimization seems a more likely culprit: JITTargetMachineBuilder and ExecutionEngineBuilder have different defaults for their CodeGen opt-level. JITTargetMachineBuilder defaults to CodeGenOpt::None, and ExecutionEngineBuilder default to CodeGenOpt::Default. What happens if you make the following modification to your setup? auto JTMB = llvm::orc::JITTargetMachineBuilder::detectHost(); *JTMB->setCodeGenOptLevel(CodeGenOpt::Default); // <-- Explicitly set Codegen opt level* auto dataLayout = JTMB->getDefaultDataLayoutForTarget(); Hopefully one of these approaches helps. If not let me know and we can dig deeper -- I would like to help you to get this working. Cheers, Lang. On Tue, Aug 13, 2019 at 1:10 PM Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:> Hi Lang, > > On Tue, 13 Aug 2019 at 20:47, Lang Hames <lhames at gmail.com> wrote: > > > > Sorry for the delayed reply. Looks like you have figured out how to > solve your issue already. Out of interest, what did you need to do? Do you > have anything that you would like to see added to > http://llvm.org/docs/ORCv2.html ? > > > > Sorry my post was misleading. I figured out below which was part of the > problem. > Code is still not getting optimized at all. I don't really know what > is going on. > > Yet the same setup works fine with the Legacy ORC v1 setup. > > Any help is appreciated. > > Here are again the links to the relevant code: > > > https://github.com/dibyendumajumdar/ravi/blob/master/include/ravi_llvmcodegen.h > https://github.com/dibyendumajumdar/ravi/blob/master/src/ravi_llvmjit.cpp > > Just look sections marked USE_ORCv2_JIT. > > >> > Optimize Module is just a function object. > >> > > >> > >> Thank you - I fixed that now. > > Regards > Dibyendu >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190813/1fa36853/attachment.html>
Hi Lang, On Tue, 13 Aug 2019 at 22:03, Lang Hames <lhames at gmail.com> wrote:> > Hi Dibyendu, > > A couple of notes to simplify your code. The following: > > #if USE_ORCv2_JIT > auto FPM = llvm::make_unique<FunctionPassManager>(TSM.getModule()); > #else > std::unique_ptr<FunctionPassManager> FPM(new FunctionPassManager(M.get())); > #endif > > can be reduced to > > auto FPM = llvm::make_unique<FunctionPassManager>(&*M); > > since M must be non-null. > > Likewise, this: > > #if USE_ORCv2_JIT > for (auto &F : *TSM.getModule()) > FPM->run(F); > #else > for (auto &F : *M) > FPM->run(F); > #endif > > can be reduced to > > for (auto &F : *M) > FPM->run(F); > > When you say your code is not getting optimized, do you mean that IR optimizations are not being applied, or that codegen optimizations are not being applied? > > What do you see if you dump the modules before/after running the pass manager on them, like this: > > dbgs() << "Before optimization:\n" << *M << "\n"; > for (auto &F : *M) > FPM->run(F); > dbgs() << "Before optimization:\n" << *M << "\n"; > > I expect that output to be the same for both ORC and ORCv2. If not something is going wrong with IR optimization. > > CodeGen optimization seems a more likely culprit: JITTargetMachineBuilder and ExecutionEngineBuilder have different defaults for their CodeGen opt-level. JITTargetMachineBuilder defaults to CodeGenOpt::None, and ExecutionEngineBuilder default to CodeGenOpt::Default. > > What happens if you make the following modification to your setup? > > auto JTMB = llvm::orc::JITTargetMachineBuilder::detectHost(); > JTMB->setCodeGenOptLevel(CodeGenOpt::Default); // <-- Explicitly set Codegen opt level > auto dataLayout = JTMB->getDefaultDataLayoutForTarget(); > > Hopefully one of these approaches helps. If not let me know and we can dig deeper -- I would like to help you to get this working. > > Cheers, > Lang.Thank you - let me try these and get back. Regards> > On Tue, Aug 13, 2019 at 1:10 PM Dibyendu Majumdar <mobile at majumdar.org.uk> wrote: >> >> Hi Lang, >> >> On Tue, 13 Aug 2019 at 20:47, Lang Hames <lhames at gmail.com> wrote: >> > >> > Sorry for the delayed reply. Looks like you have figured out how to solve your issue already. Out of interest, what did you need to do? Do you have anything that you would like to see added to http://llvm.org/docs/ORCv2.html ? >> > >> >> Sorry my post was misleading. I figured out below which was part of the problem. >> Code is still not getting optimized at all. I don't really know what >> is going on. >> >> Yet the same setup works fine with the Legacy ORC v1 setup. >> >> Any help is appreciated. >> >> Here are again the links to the relevant code: >> >> https://github.com/dibyendumajumdar/ravi/blob/master/include/ravi_llvmcodegen.h >> https://github.com/dibyendumajumdar/ravi/blob/master/src/ravi_llvmjit.cpp >> >> Just look sections marked USE_ORCv2_JIT. >> >> >> > Optimize Module is just a function object. >> >> > >> >> >> >> Thank you - I fixed that now. >> >> Regards >> Dibyendu
Hi Lang, On Tue, 13 Aug 2019 at 22:03, Lang Hames <lhames at gmail.com> wrote:> When you say your code is not getting optimized, do you mean that IR optimizations are not being applied, or that codegen optimizations are not being applied? > > What do you see if you dump the modules before/after running the pass manager on them, like this: > > dbgs() << "Before optimization:\n" << *M << "\n"; > for (auto &F : *M) > FPM->run(F); > dbgs() << "Before optimization:\n" << *M << "\n"; > > I expect that output to be the same for both ORC and ORCv2. If not something is going wrong with IR optimization.Well for ORCV2 there is no change before and after. I also get this message: JIT session error: Symbols not found: { raise_error } Yes raise_error and all other extern functions are explicitly added as global symbols.> > CodeGen optimization seems a more likely culprit: JITTargetMachineBuilder and ExecutionEngineBuilder have different defaults for their CodeGen opt-level. JITTargetMachineBuilder defaults to CodeGenOpt::None, and ExecutionEngineBuilder default to CodeGenOpt::Default. > > What happens if you make the following modification to your setup? > > auto JTMB = llvm::orc::JITTargetMachineBuilder::detectHost(); > JTMB->setCodeGenOptLevel(CodeGenOpt::Default); // <-- Explicitly set Codegen opt level > auto dataLayout = JTMB->getDefaultDataLayoutForTarget(); >No change. Regards