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. Cheers, Zheng
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
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 edges. Cheers, Zheng 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
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