Mohammad Norouzi via llvm-dev
2016-Feb-08 15:54 UTC
[llvm-dev] distinguish program and temporary variables
> Hi, > > I need to check if a variable belongs to the program originally. Consider > the following code line: > > y = x + 4 > > and its corresponding llvm ir (roughly): > > %16 = load i32 %x > %add = add i32 %16, i32 4 > store i32 %add, %y > > I need to distinguish between %16, %add and %x, %y. > > > You might be able to use the Debug information embedded within the LLVM IR > to determine what is an original variable and what is a temporary added by > LLVM. However, I think that such an approach is fragile. >yes, Debug info provides lots of useful info and i think there should be sth about this case. But I don't know which api or method does this.> > It sounds like you need to be analyzing Clang ASTs instead of LLVM IR. > The Clang AST represents a program in its original source form, so you can > tell what is a program variable, in what file it was defined, its original > source type, etc. >I'm not sure about Clang ASTs but this is part of an llvm pass which analyzes llvm IR. So, i doubt if i can use Clang AST. Best, Mohammad> > Regards, > > John Criswell > > > Any help is appreciated. > > Best, > Mohammad > > > _______________________________________________ > LLVM Developers mailing listllvm-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > > > -- > John Criswell > Assistant Professor > Department of Computer Science, University of Rochesterhttp://www.cs.rochester.edu/u/criswell > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160208/bcd38785/attachment.html>
John Criswell via llvm-dev
2016-Feb-08 16:05 UTC
[llvm-dev] distinguish program and temporary variables
On 2/8/16 10:54 AM, Mohammad Norouzi wrote:> >> Hi, >> >> I need to check if a variable belongs to the program originally. >> Consider the following code line: >> >> y = x + 4 >> >> and its corresponding llvm ir (roughly): >> >> %16 = load i32 %x >> %add = add i32 %16, i32 4 >> store i32 %add, %y >> >> I need to distinguish between %16, %add and %x, %y. > > You might be able to use the Debug information embedded within the > LLVM IR to determine what is an original variable and what is a > temporary added by LLVM. However, I think that such an approach > is fragile. > > > yes, Debug info provides lots of useful info and i think there should > be sth about this case. But I don't know which api or method does this.Look at the Doxygen documentation on the LLVM web site for documentation on the Value and Instruction classes. They probably have methods for retrieving the Debug Metadata (and if they don't, one of their subclasses/superclasses does). You can search through the LLVM source code for examples as well, plus I think there's a document that describes the format of the LLVM Debug Metadata on the LLVM web page.> > It sounds like you need to be analyzing Clang ASTs instead of LLVM > IR. The Clang AST represents a program in its original source > form, so you can tell what is a program variable, in what file it > was defined, its original source type, etc. > > > I'm not sure about Clang ASTs but this is part of an llvm pass which > analyzes llvm IR. So, i doubt if i can use Clang AST.Why are you restricted to using LLVM IR? Regards, John Criswell> > Best, > Mohammad > > > Regards, > > John Criswell > >> >> Any help is appreciated. >> >> Best, >> Mohammad >> >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > > -- > John Criswell > Assistant Professor > Department of Computer Science, University of Rochester > http://www.cs.rochester.edu/u/criswell > >-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160208/e7b2ab2d/attachment.html>
Mohammad Norouzi via llvm-dev
2016-Feb-08 16:29 UTC
[llvm-dev] distinguish program and temporary variables
thanks for your time and reply.> > Look at the Doxygen documentation on the LLVM web site for documentation > on the Value and Instruction classes. They probably have methods for > retrieving the Debug Metadata (and if they don't, one of their > subclasses/superclasses does). You can search through the LLVM source code > for examples as well, plus I think there's a document that describes the > format of the LLVM Debug Metadata on the LLVM web page. > >what about DILocalVariable class? do you think it would provide any info about the case?> > >> >> It sounds like you need to be analyzing Clang ASTs instead of LLVM IR. >> The Clang AST represents a program in its original source form, so you can >> tell what is a program variable, in what file it was defined, its original >> source type, etc. >> > > I'm not sure about Clang ASTs but this is part of an llvm pass which > analyzes llvm IR. So, i doubt if i can use Clang AST. > > > Why are you restricted to using LLVM IR? >I'm working on some part of a project. The whole project works on llvm ir. Best, Mohammad>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160208/d28f9cae/attachment.html>