Gang.Yao
2010-Apr-12 07:36 UTC
[LLVMdev] Question. about Machinefunction pass, funtion Prolog/Epilog code, stack frame
I am new to the LLVM, and need some help with this points. 1. how can we add special code for the Prolog/Epilog for some certain functions, this should be done with machinefunction pass, rt? 2. Basically, I want to get the function stack frame, that is the size and the initial position. I found int64_t llvm::MachineFrameInfo::getObjectSize ( int *ObjectIdx* ) const[inline] This method is done before or after the mapping of virtual registers? 3. the program code will be at .text section, suppose we are going to move the code from .text to somewhere else, how can we get the start and the length of the effective code, Thanks. -- -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100412/4d54034e/attachment.html>
John Criswell
2010-Apr-14 14:49 UTC
[LLVMdev] Question. about Machinefunction pass, funtion Prolog/Epilog code, stack frame
Dear All, Gang is a student at University of Illinois, and I've been asked to help advise him on using LLVM for a project. However, I lack experience with LLVM's machine-level IR (used for code generation), so I asked Gang to post to LLVMdev for help. To clarify Gang's questions, we need to insert machine code into the beginning of a function that does some prefetching of the stack frame and the function's code. We'd like to avoid modifying the code generators, so we're hoping we can implement this as a MachineFunctionPass. So, to rephrase Gang's questions: 1) Can we implement this functionality as a MachineFunctionPass? If so, is there another MachineFunctionPass that does something similar that we can use as an example? Also, can this MachineFunctionPass be target independent, or will it have to know how to insert processor-specific instructions? 2) We believe we can get the size of the stack frame by using the MachineFrameInfo::getStackSize() method. What sort of objects does this method include (e.g., does it contain function parameters)? Also, how do we find where it begins? Is this guaranteed to be stored in a specific register after the Prologue code (e.g, the %esp or %ebp registers on x86)? 3) Is there a way to determine the location and size (in bytes) of a function? On a related note, does implementing a transform on the machine IR level make sense for this work, or is there an LLVM IR way to do it? I think that, on x86, we could find the stack frame by using a combination of the stacksave and frameaddress intrinsics, but I'm not sure if this method is reliable. Thanks in advance for any answers. -- John T. Gang.Yao wrote:> I am new to the LLVM, and need some help with this points. > > 1. how can we add special code for the Prolog/Epilog for some > certain functions, this should be done with machinefunction pass, rt? > > 2. Basically, I want to get the function stack frame, that is the size and > the initial position. > I found > int64_t llvm::MachineFrameInfo::getObjectSize ( int > /ObjectIdx/ ) const| [inline]| > > This method is done before or after the mapping of virtual registers? > > 3. the program code will be at .text section, suppose we are going to > move the code from .text to somewhere else, how can we get the > start and the length of the effective code, > > Thanks. > --