[cfe-dev] Can I establish a relation between a SCoP in LLVM-IR and the corresponding line number in C-code?

Tobias Grosser tobias at grosser.es
Tue Jan 17 06:24:29 PST 2012


On 01/17/2012 03:19 PM, Pieter Custers wrote:
> On 17 jan 2012, at 14:57, Tobias Grosser wrote:
>
>> On 01/17/2012 11:49 AM, Pieter Custers wrote:
>>> Hi all,
>>>
>>> I am using LLVM w/ Clang as front end. I use Clang to transform a
>>> C-file into LLVM-IR. Now I'm wondering if I can establish a relation
>>> between the SCoPs in this IR and the C-code. In other words, I want
>>> the line-number in the C-code of this SCoP (e.g. a loop nest) in LLVM-IR.
>>>
>>> Is this possible, and if so, how do I obtain this?
>>
>> Hi Pieter,
>>
>> it is not supported out of the box, but you may try to use the
>> debugging information to get this information. However, keep in mind,
>> that debugging information is best afford and may not be available in
>> all cases. If you really need accurate feedback based on C-code a
>> source analysis tool like pet[1] may better fit your needs. pet uses
>> clang and isl to extract a polyhedral model directly from the source code.
>>
>> Tobi
>>
>> [1] http://repo.or.cz/w/pet.git
>
> I see now two possibilities:
>
> 1) pet would be okay to use, but then I loose the ability to transform
> loops in a canonical form (now I use a LLVM pass for that). Right?

Yes. This is the drawback when using source to source tools. 
canonicalication and induction variable analysis is a lot simpler on 
LLVM-IR. Especially if you want to optimize through pointers, C++ 
iterators and C++ templates. Still, for direct user feedback working on 
the source code is a valuable option.

> 2) I am looking to use CLang APIs in a C-program to construct the AST
> and try 'Mapping between cursors and source code' [2].

That is basically what pet does (though using the C++ API). It should 
allow you to map every statement and expression directly to the relevant 
source line. It can even highlight which part of the source code, blocks 
a loop to be represented in a polyhedral model.

Cheers
Tobi



More information about the cfe-dev mailing list