[LLVMdev] Get the loop trip count variable

Andreas Neustifter astifter-llvm at gmx.at
Wed Apr 7 04:29:38 PDT 2010


Hi,

On 04/05/2010 10:51 PM, Eli Friedman wrote:
> On Mon, Apr 5, 2010 at 1:19 PM, Zheng Wang<jason.wangz at gmail.com>  wrote:
>> Hello,
>>
>> I am wondering whether I can get the variable name of loop trip count in LLVM?
>>
>> For example,
>>
>> int NUM;
>>
>> NUM=atoi(argv[i]);
>>
>> for (int i=0; i<NUM; i++)
>> {
>>     ...
>> }
>>
>> How can I get the corresponding variable name for "NUM"? Then, I can
>> instrument something in the source code to record the loop trip count
>> for a given input data set.
>>
>> BasicBlock* b = L->getHeader();
>>
>> returns the basicblock of the loop header, but I don't know how to
>> extract "NUM" from basicblock b.
>
> If you need to instrument the source, you'd probably be better off
> doing this with clang purely at the source level; by the time LLVM
> loop analyzers can tell "NUM" is the trip count, the name is likely to
> be lost due to optimization.

You can also use the instrumentation pass 
(-insert-optimal-edge-instrumenation) to instrument all your code, this 
adds about 10% runtime overhead.

Also with some tweaking the instrumentation pass could be talked into 
instrumenting only loop headers so that only the loop counts get 
recorded but for a code with a whole lot of loops this would be almost 
equivalent to do the optimal instrumentation. (For a loop with only one 
block in the body only one counter gets added anyway...)

Andi




More information about the llvm-dev mailing list