[llvm-dev] Getting stack size of compiled functions from LLVM

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Tue May 29 10:41:58 PDT 2018


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



More information about the llvm-dev mailing list