Dean Michael Berris via llvm-dev
2016-Sep-05 06:05 UTC
[llvm-dev] How to insert instructions before each function calls?
> On 5 Sep 2016, at 11:49, SHUCAI YAO <yaos4 at mcmaster.ca> wrote: > > For the function call lowering, do you mean lowercall function? I did insert the instruction before the stack adjustments, but the inserted code appears in the prologue of the function, other than before the function call. Maybe I did something wrong with the iterator. > > So you mean I should insert a pseudo instruction in the machinefunction pass, then replace it when function call lowering? (Like segemented stack implementation?) >Yes, inserting pseudo instructions in the MachineFunctionPass -- you might want to have a look at PATCHABLE_RET and how we handle this in XRay. Essentially the idea (which I saw Sanjoy Das do first) is to wrap the actual instruction (in this case, CALL or LEA, or something specific in the platform you're targeting) in a pseudo instruction that just lowers to the correct sequence. This gives you complete control of the actual assembly of the instructions that you're replacing. -- Dean
SHUCAI YAO via llvm-dev
2016-Sep-05 06:14 UTC
[llvm-dev] How to insert instructions before each function calls?
2016年9月5日星期一,Dean Michael Berris <dean.berris at gmail.com> 写道:> > On 5 Sep 2016, at 11:49, SHUCAI YAO <yaos4 at mcmaster.ca <javascript:;>> > wrote: > > > > For the function call lowering, do you mean lowercall function? I did > insert the instruction before the stack adjustments, but the inserted code > appears in the prologue of the function, other than before the function > call. Maybe I did something wrong with the iterator. > > > > So you mean I should insert a pseudo instruction in the machinefunction > pass, then replace it when function call lowering? (Like segemented stack > implementation?) > > > > Yes, inserting pseudo instructions in the MachineFunctionPass -- you might > want to have a look at PATCHABLE_RET and how we handle this in XRay. > Essentially the idea (which I saw Sanjoy Das do first) is to wrap the > actual instruction (in this case, CALL or LEA, or something specific in the > platform you're targeting) in a pseudo instruction that just lowers to the > correct sequence. This gives you complete control of the actual assembly of > the instructions that you're replacing.Hi Dean, Do you have any example for this? I would like have a look at how you handle this in XRay if it is possible. Thank you very much! Shucai> -- Dean-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160905/b9c350d8/attachment.html>
Dean Michael Berris via llvm-dev
2016-Sep-06 01:21 UTC
[llvm-dev] How to insert instructions before each function calls?
> On 5 Sep 2016, at 16:14, SHUCAI YAO <yaos4 at mcmaster.ca> wrote: > > > Hi Dean, > > Do you have any example for this? I would like have a look at how you handle this in XRay if it is possible. >Yes, this is all upstream -- if you look in lib/CodeGen/XRayInstrument.cpp and the associated lowering code for X86 in lib/Target/X86/X86MCInstLower.cpp and/or search for PATCHABLE_RET in include/... and lib/... then that should give you a better idea of how this works. :) Cheers -- Dean