[cfe-users] Help Needed: How to get source line number from .ll file LLVM

2016-07-12 Thread Shail Dave via cfe-users
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] Help needed to define and handle custom pragma #mypragma

2017-02-16 Thread Shail Dave via cfe-users
Hi,

I want to allow compilation of my own pragma in C/Cpp files such as
#pragma mypragma and I want to handle it in this way -- upon identification
of this pragma, I want to insert a function call and delete some code in
the original source file.

My problem is defining pragma and to handle it for inserting a function
call. It would be great if someone can guide or suggest some tutorials. I
am referring following resources but being newbie in front-end parsing, it
is little hard. So, any help is highly appreciated. Thank you! :)

Resources that I am following are --
http://wvanteijlingen.github.io/notes/clang_pragmas
http://llvm.org/devmtg/2013-04/pellegrini-slides.pdf

Best,
*Shail*
ᐧ
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] Help needed in analyzing liveness of variables with LLVM IR

2017-04-10 Thread Shail Dave via cfe-users
Hi,

Thank you for your time in reading this. I need help in analyzing the
live-in and live-out variables for few loops in the llvm IR. I want to
figure out which is a live-variable at the end of the loop and what is
live-in variable for the loop. I found that such provisions are available
for machine instructions. But, I have to use this at IR level. I found few
papers showing algorithms to construct such analysis but, it seems to me
that this must be a problem encountered before and there should be at least
similar functionalities in some of the analyses passes in the existing LLVM
framework. It would be great if I can find some references or someone can
give some suggestions.

If I cannot find some existing passes, I am also not sure about - how can I
make use of Intrinsic::invariant_start or Intrinsic::lifetime_start for
aforementioned purpose. Any help is highly appreciated. Thanks!



Best,
Shail

___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users