[cfe-users] binary operator
Hi, When iterating through the AST I encounter BinaryOperator-s, part of an IfStmt. My question now is: how can I find which operator it is? E.g. ==, >=, etc. I'm using libclang. Folkert van Heusden -- -- Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
[cfe-users] Help Needed: How to get source line number from .ll file LLVM
Hi, I am working with LLVM 3.4 and want to obtain the line number information of source file from IR. The IR is generated from simple c code with Clang. *I want to obtain the line number in source c file from the line in IR body.* I tried this - 1. For Instruction BI, unsigned Line = Line = BI->getDebugLoc().getLine(); 2. For Loop L, std::cout << L->getStartLoc().getLine(); But, the result stored/printed is always 0. I don't know how to obtain line number in the source from LLVM IR. My Source C file is - #include int main(){ int i; int inbuf[100]; int outbuf[100]; for(i = 0; i < 100; ++i) inbuf[i] ^= outbuf[i]; inbuf[1] += 402; inbuf[6] += 107; inbuf[97] += 231; for(i = 0; i < 100; ++i) { inbuf[i] += outbuf[i]; } inbuf[47] += 312; //print-statements for (i=0;i<100;i++) { printf("inbuf[%d] = %d\n",i,inbuf[i]); }return 0; } *Command Used-* ~/llvm/build/Release+Asserts/bin/clang -O3 -fno-unroll-loops -fno-vectorize -fno-slp-vectorize -S -emit-llvm sample.c -o sample.ll I have working pass which can detect and analyze the loops and instructions. I am using it inside function - runOnLoop(Loop *L, LPPassManager &LPM) I have also tried with -O0 and -fstandalone-debug option in the compile line. But, it is still printing 0. The following is also not working out. if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction DILocation Loc(N); // DILocation is in DebugInfo.h unsigned Line = Loc.getLineNumber(); } It would be great if anybody can kindly help me for the same. Thanks! Best, Shail ᐧ ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
Re: [cfe-users] Help Needed: How to get source line number from .ll file LLVM
you would need to build with debug info (-g) or similar (there are a few other options that enable the same source location info) to produce the debuglocs that will tell you about that On Mon, Jul 11, 2016 at 9:40 PM, Shail Dave via cfe-users < cfe-users@lists.llvm.org> wrote: > Hi, > > I am working with LLVM 3.4 and want to obtain the line number information > of source file from IR. The IR is generated from simple c code with Clang. *I > want to obtain the line number in source c file from the line in IR body.* > > I tried this - > >1. For Instruction BI, unsigned Line = Line = >BI->getDebugLoc().getLine(); >2. For Loop L, std::cout << L->getStartLoc().getLine(); > > But, the result stored/printed is always 0. I don't know how to obtain > line number in the source from LLVM IR. > > My Source C file is - > #include > > int main(){ > > int i; > > int inbuf[100]; > int outbuf[100]; > > for(i = 0; i < 100; ++i) > inbuf[i] ^= outbuf[i]; > > inbuf[1] += 402; > inbuf[6] += 107; > inbuf[97] += 231; > > for(i = 0; i < 100; ++i) > { > inbuf[i] += outbuf[i]; > } > > inbuf[47] += 312; > > //print-statements > for (i=0;i<100;i++) { > printf("inbuf[%d] = %d\n",i,inbuf[i]); }return 0; > } > > > *Command Used-* ~/llvm/build/Release+Asserts/bin/clang -O3 > -fno-unroll-loops -fno-vectorize -fno-slp-vectorize -S -emit-llvm sample.c > -o sample.ll > > I have working pass which can detect and analyze the loops and > instructions. I am using it inside function - runOnLoop(Loop *L, > LPPassManager &LPM) > > I have also tried with -O0 and -fstandalone-debug option in the compile > line. But, it is still printing 0. > > The following is also not working out. > > if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction >DILocation Loc(N); // DILocation is in DebugInfo.h >unsigned Line = Loc.getLineNumber(); > } > > It would be great if anybody can kindly help me for the same. Thanks! > > Best, > Shail > ᐧ > > ___ > cfe-users mailing list > cfe-users@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users > > ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
Re: [cfe-users] binary operator
Hi Folkert, On Tue, Jul 12, 2016 at 1:46 PM, folkert via cfe-users wrote: > Hi, > > When iterating through the AST I encounter BinaryOperator-s, part of an > IfStmt. > My question now is: how can I find which operator it is? E.g. ==, >=, > etc. > I'm using libclang. > You can call BinaryOperator::getOpcode, which will return an Opcode, which is a typedef of the BinaryOperatorKind enum. Csaba -- GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++ The Tao of math: The numbers you can count are not the real numbers. Life is complex, with real and imaginary parts. "Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds "People disagree with me. I just ignore them." -- Linus Torvalds ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
Re: [cfe-users] binary operator
Hi, > > When iterating through the AST I encounter BinaryOperator-s, part of an > > IfStmt. > > My question now is: how can I find which operator it is? E.g. ==, >=, > > etc. > > I'm using libclang. > > You can call BinaryOperator::getOpcode, which will return an Opcode, > which is a typedef of the BinaryOperatorKind enum. That is part of the C++ api right? I'm using the one with the clang_ prefixes and I could not find any getOpcode call in there (I checked Index.h). Folkert van Heusden -- -- Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users