Mingliang LIU
2013-Apr-12 09:31 UTC
[LLVMdev] The line number range of a function in source code level
Hi all, I need to know the line number range of a function. The start of the function line number can be found by the definition point, which is stored at the subprogram metadata: DISubprogram::getLineNumber(). However, there is no API (or the metadata in the first place) to know the end of the function. I have to visit all the instructions of the function and maintain the *max*line number of the instructions. I use the inst_begin(func): inst_end(func) as the iterator. But I don't think it's effective to iterate all the instructions from the beginning. It's supposed that we can iterate the instructions reversely and the first one who has attached metadata should be treated as the end of the function. Unfortunately, there is no reverse iterator of a function. Any idea? Thank you very much! -- Mingliang LIU (刘明亮 in Chinese) PACMAN Group, Dept. of Computer Science & Technology Tsinghua University, Beijing 100084, China Email: liuml07 at mails.tsinghua.edu.cn Homepage: http://pacman.cs.tsinghua.edu.cn/~liuml07/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130412/114b2250/attachment.html>
Hongxu Chen
2013-Apr-12 11:48 UTC
[LLVMdev] The line number range of a function in source code level
"liuml07 [via LLVM]" <ml-node+s1065342n56664h75 at n5.nabble.com> writes: There is a `std::reverse_iterator' that might be useful. See this page below for more information. https://github.com/jirislaby/LLVMSlicer/blob/master/src/Slicing/FunctionStaticSlicer.cpp#L331> Hi all, > > I need to know the line number range of a function. The start of the function > line number can be found by the definition point, which is stored at the > subprogram metadata: DISubprogram::getLineNumber(). > > However, there is no API (or the metadata in the first place) to know the end of > the function. > > I have to visit all the instructions of the function and maintain the max line > number of the instructions. I use the inst_begin(func): inst_end(func) as the > iterator. But I don't think it's effective to iterate all the instructions from > the beginning. It's supposed that we can iterate the instructions reversely and > the first one who has attached metadata should be treated as the end of the > function. Unfortunately, there is no reverse iterator of a function. > > Any idea? > > Thank you very much!-- Regards, Hongxu Chen -- View this message in context: http://llvm.1065342.n5.nabble.com/The-line-number-range-of-a-function-in-source-code-level-tp56664p56667.html Sent from the LLVM - Dev mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130412/978ffa91/attachment.html>
John Criswell
2013-Apr-12 14:26 UTC
[LLVMdev] The line number range of a function in source code level
On 4/12/13 4:31 AM, Mingliang LIU wrote:> Hi all, > > I need to know the line number range of a function. The start of the > function line number can be found by the definition point, which is > stored at the subprogram metadata: DISubprogram::getLineNumber(). > > However, there is no API (or the metadata in the first place) to know > the end of the function. > > I have to visit all the instructions of the function and maintain the > /max/ line number of the instructions. I use the inst_begin(func): > inst_end(func) as the iterator. But I don't think it's effective to > iterate all the instructions from the beginning. It's supposed that we > can iterate the instructions reversely and the first one who has > attached metadata should be treated as the end of the function. > Unfortunately, there is no reverse iterator of a function.Keep in mind that some transforms may move instructions, so the last instruction in the function with meta-data does not necessarily come from the last instruction in the function. For example, there is a transform that modifies a function so that it only has one return instruction. Which meta-data does the merged return instruction get? I think iterating over all the instructions is more robust. If you need more accuracy than that, it might be a good idea to modify the front-end to generate meta-data that marks the line number of the end of the function. -- John T.> > Any idea? > > Thank you very much! > > -- > Mingliang LIU (??? in Chinese) > > PACMAN Group, Dept. of Computer Science & Technology > Tsinghua University, Beijing 100084, China > Email: liuml07 at mails.tsinghua.edu.cn > <mailto:liuml07 at mails.tsinghua.edu.cn> > Homepage: http://pacman.cs.tsinghua.edu.cn/~liuml07/ > <http://pacman.cs.tsinghua.edu.cn/%7Eliuml07> > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130412/4372f25f/attachment.html>
Mingliang LIU
2013-Apr-12 15:48 UTC
[LLVMdev] The line number range of a function in source code level
Thank you very much. On Fri, Apr 12, 2013 at 10:26 PM, John Criswell <criswell at illinois.edu>wrote:> On 4/12/13 4:31 AM, Mingliang LIU wrote: > > Hi all, > > I need to know the line number range of a function. The start of the > function line number can be found by the definition point, which is stored > at the subprogram metadata: DISubprogram::getLineNumber(). > > However, there is no API (or the metadata in the first place) to know > the end of the function. > > I have to visit all the instructions of the function and maintain the * > max* line number of the instructions. I use the inst_begin(func): > inst_end(func) as the iterator. But I don't think it's effective to > iterate all the instructions from the beginning. It's supposed that we can > iterate the instructions reversely and the first one who has attached > metadata should be treated as the end of the function. Unfortunately, there > is no reverse iterator of a function. > > > Keep in mind that some transforms may move instructions, so the last > instruction in the function with meta-data does not necessarily come from > the last instruction in the function. > > For example, there is a transform that modifies a function so that it only > has one return instruction. Which meta-data does the merged return > instruction get? > > I think iterating over all the instructions is more robust. If you need > more accuracy than that, it might be a good idea to modify the front-end to > generate meta-data that marks the line number of the end of the function. > > -- John T. > > > > Any idea? > > Thank you very much! > > -- > Mingliang LIU (刘明亮 in Chinese) > > PACMAN Group, Dept. of Computer Science & Technology > Tsinghua University, Beijing 100084, China > Email: liuml07 at mails.tsinghua.edu.cn > Homepage: http://pacman.cs.tsinghua.edu.cn/~liuml07/ > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-- Mingliang LIU (刘明亮 in Chinese) PACMAN Group, Dept. of Computer Science & Technology Tsinghua University, Beijing 100084, China Email: liuml07 at mails.tsinghua.edu.cn Homepage: http://pacman.cs.tsinghua.edu.cn/~liuml07/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130412/b287dcbe/attachment.html>
Apparently Analagous Threads
- [LLVMdev] The line number range of a function in source code level
- [LLVMdev] How to enable c++11 in a llvm project?
- [LLVMdev] How to enable c++11 in a llvm project?
- [LLVMdev] How to enable c++11 in a llvm project?
- [LLVMdev] How to enable cbe as a supported target?