Nicholas Chapman via llvm-dev
2018-May-29 06:34 UTC
[llvm-dev] Getting stack size of compiled functions from LLVM
Hi all, I'm trying to get the amount of stack memory used by the functions I am JIT compiling with LLVM. I have a host C++ program, and I want to be able to access the stack size from the host C++ program. I see in PrologEpilogInserter.cpp that the computed stack size is read from the MachineFunction corresponding to a Function, in order to issue a warning if the stack size is too large. However I don't see a way to access this information from my host C++ program. One approach I have investigated is writing a MachineFunctionPass that could access the MachineFunctions and hence the stack size. However I have not been able to get my MachineFunctionPass to run without hitting assert failures. Is it possible to add/schedule a MachineFunctionPass to run without modifying the LLVM libraries themselves? I would prefer not to have to modify LLVM. If it is the case that the code to schedule the MachineFunctionPass must be added to LLVM, then it's not clear to me how to return the stack size information to the host C++ program either. Any help would be appreciated. Thanks, Nick C.
Friedman, Eli via llvm-dev
2018-May-29 17:41 UTC
[llvm-dev] Getting stack size of compiled functions from LLVM
On 5/28/2018 11:34 PM, Nicholas Chapman via llvm-dev wrote:> Hi all, > I'm trying to get the amount of stack memory used by the functions I > am JIT compiling with LLVM. > I have a host C++ program, and I want to be able to access the stack > size from the host C++ program. > > I see in PrologEpilogInserter.cpp that the computed stack size is read > from the MachineFunction corresponding to a Function, in order to > issue a warning if the stack size is too large. > However I don't see a way to access this information from my host C++ > program.You can retrieve those warnings from your host program; if you call LLVMContext::setDiagnosticHandler, the DiagnosticInfoStackSize gets passed to your code instead of getting dumped to stderr.> > One approach I have investigated is writing a MachineFunctionPass that > could access the MachineFunctions and hence the stack size. However I > have not been able to get my MachineFunctionPass to run > without hitting assert failures. > > Is it possible to add/schedule a MachineFunctionPass to run without > modifying the LLVM libraries themselves? I would prefer not to have > to modify LLVM. > If it is the case that the code to schedule the MachineFunctionPass > must be added to LLVM, then it's not clear to me how to return the > stack size information to the host C++ program either.There currently aren't any hooks for this, but it probably wouldn't be hard to implement, if you're interested in contributing upstream. (See PassManagerBuilder::addExtension for IR optimization passes.) -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Sanjoy Das via llvm-dev
2018-May-30 18:17 UTC
[llvm-dev] Getting stack size of compiled functions from LLVM
If you don't want to modify LLVM, you can consider inserting a "dummy" patchpoint or statepoint call in your function. Then the JIT generated in-memory object file will contain a __llvm_stackmaps section that will contain the stack sizes of all the functions in the module that have a compile-time constant sized stack. You could also look into adding a flag that would ask LLVM to always produce this __llvm_stackmaps section, even if the module did not have any statepoint or patchpoint calls. See https://llvm.org/docs/StackMaps.html -- Sanjoy On Tue, May 29, 2018 at 10:41 AM, Friedman, Eli via llvm-dev <llvm-dev at lists.llvm.org> wrote:> On 5/28/2018 11:34 PM, Nicholas Chapman via llvm-dev wrote: >> >> Hi all, >> I'm trying to get the amount of stack memory used by the functions I am >> JIT compiling with LLVM. >> I have a host C++ program, and I want to be able to access the stack size >> from the host C++ program. >> >> I see in PrologEpilogInserter.cpp that the computed stack size is read >> from the MachineFunction corresponding to a Function, in order to issue a >> warning if the stack size is too large. >> However I don't see a way to access this information from my host C++ >> program. > > > You can retrieve those warnings from your host program; if you call > LLVMContext::setDiagnosticHandler, the DiagnosticInfoStackSize gets passed > to your code instead of getting dumped to stderr. > >> >> One approach I have investigated is writing a MachineFunctionPass that >> could access the MachineFunctions and hence the stack size. However I have >> not been able to get my MachineFunctionPass to run >> without hitting assert failures. >> >> Is it possible to add/schedule a MachineFunctionPass to run without >> modifying the LLVM libraries themselves? I would prefer not to have to >> modify LLVM. >> If it is the case that the code to schedule the MachineFunctionPass must >> be added to LLVM, then it's not clear to me how to return the stack size >> information to the host C++ program either. > > > There currently aren't any hooks for this, but it probably wouldn't be hard > to implement, if you're interested in contributing upstream. (See > PassManagerBuilder::addExtension for IR optimization passes.) > > -Eli > > -- > Employee of Qualcomm Innovation Center, Inc. > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux > Foundation Collaborative Project > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Apparently Analagous Threads
- Getting stack size of compiled functions from LLVM
- [LLVMdev] design question on inlining through statepoints and patchpoints
- [LLVMdev] design question on inlining through statepoints and patchpoints
- [LLVMdev] RFC: implicit null checks in llvm
- [LLVMdev] Trying to use patchpoint in MCJIT