Mattias Holm via llvm-dev
2019-Mar-14 09:13 UTC
[llvm-dev] Disabling prolog/epilog emitters
Hi, I am working on something where I would like to disable the prolog and epilog emitters in the ORC JIT layer and move these into a custom trampoline written in manual assembler, mostly because the prolog and epilogues actually interfering with the chaining / tail calling of emitted functions. Is there some way to get this done easily, the TargetPassConfig::addMachinePasses() function seem to point at that the the prolog pass can be overridden/substituted if needed. But I have a hard time figuring out where to do that. Is there some documentation about this or does someone have a clue how to do this? Basically in case it explains a bit better, I have a generated code block like this: Func1: <prolog> <code> <patchpoint> <epilogue> Where I want to override the patch point to jump directly to another function (that is luckily trivial), my aiming point is to get to something like this: Trampoline: <prolog> Jump to Func1 <epilogue> Func1: <code> Jump to Func2 Ret to trampoline Func2: <code> <patchpoint> Ret to trampoline Currently I am analysing the machine code that has been emitted in order to get the prolog/epilogue handling compatible and actually handle the jumping to the next function correctly, but this is less then ideal and not overly robust. My, so my initial thought was to see if the prolog and epilog pass can be disabled, but maybe there is a better way to do this? Cheers, Mattias
Alex Bradbury via llvm-dev
2019-Mar-14 10:41 UTC
[llvm-dev] Disabling prolog/epilog emitters
On Thu, 14 Mar 2019 at 09:13, Mattias Holm via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Hi, > > I am working on something where I would like to disable the prolog and epilog emitters in the ORC JIT layer and move these into a custom trampoline written in manual assembler, mostly because the prolog and epilogues actually interfering with the chaining / tail calling of emitted functions. > > Is there some way to get this done easily, the TargetPassConfig::addMachinePasses() function seem to point at that the the prolog pass can be overridden/substituted if needed. But I have a hard time figuring out where to do that. > > Is there some documentation about this or does someone have a clue how to do this? > > Basically in case it explains a bit better, I have a generated code block like this: > > Func1: > <prolog> > <code> > <patchpoint> > <epilogue> > > Where I want to override the patch point to jump directly to another function (that is luckily trivial), my aiming point is to get to something like this: > > Trampoline: > <prolog> > Jump to Func1 > <epilogue> > > Func1: > <code> > Jump to Func2 > Ret to trampoline > > Func2: > <code> > <patchpoint> > Ret to trampoline > > Currently I am analysing the machine code that has been emitted in order to get the prolog/epilogue handling compatible and actually handle the jumping to the next function correctly, but this is less then ideal and not overly robust. My, so my initial thought was to see if the prolog and epilog pass can be disabled, but maybe there is a better way to do this?I think the"naked" function attribute is what you want. It will disable prolog/epilog emission for that function (see line 255 in PrologEpilogInserter.cpp). Best, Alex