[LLVMdev] Get the loop trip count variable

Zheng Wang jason.wangz at gmail.com
Tue Apr 6 03:15:27 PDT 2010

Hi Eli,

Could you tell me how to extract the variable name?
The reason I want to do it at the IR level is because I have more
information at this stage, such as, constant propagation and back


On 5 April 2010 21:51, Eli Friedman <eli.friedman at gmail.com> 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.
> -Eli

Best regards,

WANG Zheng

More information about the llvm-dev mailing list