[LLVMdev] How to get the total number of variables in a funciton?

tanmingxing at mprc.pku.edu.cn tanmingxing at mprc.pku.edu.cn
Mon Dec 15 22:25:52 PST 2008


Hi,John.
In fact, I am doing a project for fast liveness checking. The information
of live varibles is needed by both the register allocation and our own
verification system. To support register allocation, I only need to
calculate in which BasicBlocks is the given virtual register lives; but to
support our own verification system, I need to map these virtual registers
to the original variables appeared in source code.
By now, I have complete the pass of computing the liveness(similar to the
original LiveVariable pass in LLVM2.4,but faster), but I can not find a
good way to map these virtual registers in machineFunction to the original
source program variables. Maybe I need at least two steps:
Step1: maps the virtual registers to the SSA-variables;
Step2: maps the SSA-variables to original source program varibales;
Of course, if the step1 is impossible, I can move the liveness checking
pass to FunctionPass from MachineFunctionPass(that is the way I am trying
now); but I really can not find a good solution for the step2.
I'm learning the Clang, and maybe that will helpful.
If anyone have good solution to map the virtual registers to the original
source program variables, or to map the SSA-variables to the original
source program variables, please tell me.

> Mingxing Tan wrote:
>>
>> Hi, all;
>>
>> How can I get the number of variables in a function/module (both the
>> number of variables in original source program and the number of
>> temporal variables for ssa-form)?
>>
> Do you want the SSA values *created* by a function, those used by a
> function, or both?
>
> For SSA values, simply iterate over all of the instructions within the
> function and count those that generate SSA values.  Most instructions
> (like add, sub, cast) do, but a few (like store or call when calling a
> function returning void) do not.  If you want all SSA variables, you
> will also need to count the number of operands to each instruction (even
> those like store that do not create new SSA values).
>
> If you're working on a whole module, you will also need to count he SSA
> values for all globals and functions.
>
> Counting original source program variables is more difficult.  One thing
> you could try is to compile the program with debug information and use
> the information in the LLVM debugging intrinsics to find the original
> source program variables.  You might want to try doing this before the
> mem2reg pass is run (mem2reg will take stack allocated variables and
> change them to SSA form; this may make correlation between the LLVM
> level and source level a bit more tricky).
>
> Another solution to finding the number of source-level variables is to
> use clang instead of llvm-gcc.  I believe you can, with relative ease,
> modify clang to record the number of source-level variables.
>>
>> I’m dealing with some dataflow analysis problem and need the
>> information of variables. Appreciate any help.
>>
> Just out of curiosity, what dataflow analysis problem are you trying to
> solve?
>
> -- John T.
>
>>
>>
>> Thanks.
>>
>>
>>
>> Star.Tan
>>
>>
>>
>




More information about the llvm-dev mailing list