Felix Berlakovich via llvm-dev
2020-Mar-27 08:28 UTC
[llvm-dev] Passing inormation from pass to lowering
Hi! I have written a ModulePass that calculates various things and adds custom metadata attributes to certain instructions. Depending on the attributes, I would like to change the machine code of these instructions. For example, I would like to replace certain calls with jumps, but as far as I can tell the IR metadata is not accessible anymore on the level of machine instructions (e.g. in the AsmPrinter). What is the best way to pass the information calculated by the pass (e.g the attributes) to the part where the target specific instructions are emitted? Regards Felix -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/d2a02a9e/attachment.html>
Sam Parker via llvm-dev
2020-Mar-27 11:46 UTC
[llvm-dev] Passing inormation from pass to lowering
Hi Felix, Could you use intrinsics instead? Or modify the IR directly to inline and perform a br instead of a call? Regards, Sam Sam Parker Compilation Tools Engineer | Arm . . . . . . . . . . . . . . . . . . . . . . . . . . . Arm.com ________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Felix Berlakovich via llvm-dev <llvm-dev at lists.llvm.org> Sent: 27 March 2020 08:28 To: llvm-dev at lists.llvm.org <llvm-dev at lists.llvm.org> Subject: [llvm-dev] Passing inormation from pass to lowering Hi! I have written a ModulePass that calculates various things and adds custom metadata attributes to certain instructions. Depending on the attributes, I would like to change the machine code of these instructions. For example, I would like to replace certain calls with jumps, but as far as I can tell the IR metadata is not accessible anymore on the level of machine instructions (e.g. in the AsmPrinter). What is the best way to pass the information calculated by the pass (e.g the attributes) to the part where the target specific instructions are emitted? Regards Felix -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/5ddad7fd/attachment.html>
Felix Berlakovich via llvm-dev
2020-Mar-27 12:54 UTC
[llvm-dev] Passing inormation from pass to lowering
Hi Sam, I think an intrinsic would be ideal, but I couldn't figure out how to replace calls with an arbitrary number of arguments with a call to an intrinsic. In particular, I would like to call a trampoline instead of the original function. The trampoline performs certain actions and then jumps to the original callee. Would I have to call the intrinsic with the original arguments and then perform a jump to the original function in the intrinsic? Inlining is not possible unfortunately. I tried to use a IR branch instruction to jump the trampoline, but then the first basic block of the trampoline has a predecessor which is not allowed. Thanks for your help Felix Von: Sam Parker <Sam.Parker at arm.com> Gesendet: Freitag, 27. März 2020 12:47 An: llvm-dev at lists.llvm.org; Felix Berlakovich <felix at berlakovich.at> Betreff: Re: Passing inormation from pass to lowering Hi Felix, Could you use intrinsics instead? Or modify the IR directly to inline and perform a br instead of a call? Regards, Sam Sam Parker Compilation Tools Engineer | Arm . . . . . . . . . . . . . . . . . . . . . . . . . . . Arm.com ________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>> on behalf of Felix Berlakovich via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> Sent: 27 March 2020 08:28 To: llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> Subject: [llvm-dev] Passing inormation from pass to lowering Hi! I have written a ModulePass that calculates various things and adds custom metadata attributes to certain instructions. Depending on the attributes, I would like to change the machine code of these instructions. For example, I would like to replace certain calls with jumps, but as far as I can tell the IR metadata is not accessible anymore on the level of machine instructions (e.g. in the AsmPrinter). What is the best way to pass the information calculated by the pass (e.g the attributes) to the part where the target specific instructions are emitted? Regards Felix -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/44616509/attachment.html>
Reid Kleckner via llvm-dev
2020-Mar-28 16:42 UTC
[llvm-dev] Passing inormation from pass to lowering
I would encourage you to look at the "cfguard" bundle added for Windows Control Flow Integrity. AsmPrinter is probably far too late for the transform you want to do. You probably need to implement it somewhere in call lowering, so assuming this is for x86, you would implement this in X86ISelLowering::LowerCall. I think it would be less invasive to attach your metadata to the existing call instructions, and then change code generation later, rather than replacing the IR instructions completely. The implementation for cfguard is mostly here: http://github.com/llvm/llvm-project/commit/d157a9bc8ba1085cc4808c6941412322a7fd884e On Fri, Mar 27, 2020 at 1:28 AM Felix Berlakovich via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi! > > > > I have written a ModulePass that calculates various things and adds custom > metadata attributes to certain instructions. Depending on the attributes, I > would like to change the machine code of these instructions. For example, I > would like to replace certain calls with jumps, but as far as I can tell > the IR metadata is not accessible anymore on the level of machine > instructions (e.g. in the AsmPrinter). What is the best way to pass the > information calculated by the pass (e.g the attributes) to the part where > the target specific instructions are emitted? > > > > Regards > > > > Felix > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200328/d2705a9d/attachment-0001.html>
Felix Berlakovich via llvm-dev
2020-Mar-30 20:04 UTC
[llvm-dev] Passing inormation from pass to lowering
The one thing I can‘t seem to figure out is how to lower a jump to another function at any stage before AsmPrinter. The methods to construct an unconditional branch always seem to expect a (machine) basic block and I don’t know how to get the first basic block of *another* function. Is DAG.getNode(ISD::BR, dl, MVT::Other, ???) the right approach? And why isn’t there a X86::BR, but only a X86::BRCOND? The only implementation I could find that actually creates a jump to a function is Readactor (https://github.com/securesystemslab/multicompiler), but it does it in the AsmPrinter. Thanks for your help! Regards Felix Von: Reid Kleckner <rnk at google.com> Gesendet: Samstag, 28. März 2020 17:42 An: Felix Berlakovich <felix at berlakovich.at> Cc: llvm-dev at lists.llvm.org Betreff: Re: [llvm-dev] Passing inormation from pass to lowering I would encourage you to look at the "cfguard" bundle added for Windows Control Flow Integrity. AsmPrinter is probably far too late for the transform you want to do. You probably need to implement it somewhere in call lowering, so assuming this is for x86, you would implement this in X86ISelLowering::LowerCall. I think it would be less invasive to attach your metadata to the existing call instructions, and then change code generation later, rather than replacing the IR instructions completely. The implementation for cfguard is mostly here: http://github.com/llvm/llvm-project/commit/d157a9bc8ba1085cc4808c6941412322a7fd884e On Fri, Mar 27, 2020 at 1:28 AM Felix Berlakovich via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote: Hi! I have written a ModulePass that calculates various things and adds custom metadata attributes to certain instructions. Depending on the attributes, I would like to change the machine code of these instructions. For example, I would like to replace certain calls with jumps, but as far as I can tell the IR metadata is not accessible anymore on the level of machine instructions (e.g. in the AsmPrinter). What is the best way to pass the information calculated by the pass (e.g the attributes) to the part where the target specific instructions are emitted? Regards Felix _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200330/d9f66955/attachment-0001.html>
David Greene via llvm-dev
2020-Apr-01 16:33 UTC
[llvm-dev] Passing inormation from pass to lowering
Felix Berlakovich via llvm-dev <llvm-dev at lists.llvm.org> writes:> I have written a ModulePass that calculates various things and adds > custom metadata attributes to certain instructions. Depending on the > attributes, I would like to change the machine code of these > instructions. For example, I would like to replace certain calls with > jumps, but as far as I can tell the IR metadata is not accessible > anymore on the level of machine instructions (e.g. in the > AsmPrinter). What is the best way to pass the information calculated > by the pass (e.g the attributes) to the part where the target specific > instructions are emitted?This is something I have wanted for quite some time. It would be really useful to have a Machine IR metadata facility. In the past I have hacked things in in various ways but a more general solution would be ideal. Would others be interested in such a facility? I can't promise that I can devote a ton of time to it right now but it is something I might look at in the future if there is enough interest and/or it would be accepted upstream. If it's not likely to be accepted upstream I don't want to spend a lot of time on it, obviously. -David
Possibly Parallel Threads
- Passing inormation from pass to lowering
- LNT server function perf profile comparison
- question about xray tls data initialization
- Getting TargetLowering in AsmPrinter / Lowering constant addrspacecast
- [LLVMdev] How to Find Instruction Encoding for a MachineInstr