[LLVMdev] Parameter names in IR and debug info

Rodney M. Bates rodney_bates at lcwb.coop
Thu Feb 19 08:18:06 PST 2015


Have I correctly inferred below, how I build IR and debug info for
a function type and a function (value), in particular, how to supply
the names of the formal parameters?

To create a function in llvm IR and give names to its formal parameters,
I must:

1. Build a LLVMTypeRef for the type of each formal and the function result.
2. Build a function type using LLVMFunctionType, from the results of 1.
3. Build a function (an LLVMValueRef), using LLVMAddFunction, from the result of 2.
4. Get the LLVMValueRef for each formal (apparently, these are constructed inside
    LLVMAddFunction), using LLVMGetParam, from the result of 3.
5. Set the formal name using LLVMSetValueName, from each result of 5.

Which appears to imply that the formal names are part of the function,
not the function type, and thus the function type could be reused for another
function whose signature differs only in the names of the formals.  Also the
function type could be used as the referent of a pointer type, which could
then be used as the type of a variable, without any actual function at all.

To build corresponding debug info, I must:

6. Build a llvm::DIArray, using llvm::getOrCreateArray, from the results of 4.
7. Build a llvm::DIComposite type for the function, using
    llvm::createSubroutineType, from the result of 6.
8. Build a llvm::DIFunction using llvm::createFunction, from the result of 7.

Here, I need the formal values, with names, first, before building the function
type.  This appears to imply that, in debug info, the formal names are also part
of the function type, which thus cannot be reused for a different function with
different formal names.

Can I build a DI function type without having an actual function of that type?
This happens in my language.

-- 
Rodney Bates
rodney.m.bates at acm.org



More information about the llvm-dev mailing list