collect end line number for scope

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

collect end line number for scope

Pankaj Gode
Hi All,
 
int global;
int func( int t)
  //scope 1
  {
     ....
  } <-----
  return x;
}
 
For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
 
 
Thanks & Regards,
Pankaj

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Eric Christopher-2

On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:

For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?


I don't know about 2.9 in specific, but current top of tree will get you that information.

-eric

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Pankaj Gode
What do you mean by "current top of tree"?
 
Pankaj

From: Eric Christopher <[hidden email]>
To: Pankaj Gode <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Sent: Monday, October 3, 2011 10:32 PM
Subject: Re: [LLVMdev] collect end line number for scope


On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:

For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?


I don't know about 2.9 in specific, but current top of tree will get you that information.

-eric



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Alex-661
Hi,

He is referring to current SVN head.

Regards,
Alex

On Tue, Oct 4, 2011 at 12:08 PM, Pankaj Gode <[hidden email]> wrote:

> What do you mean by "current top of tree"?
>
> Pankaj
> From: Eric Christopher <[hidden email]>
> To: Pankaj Gode <[hidden email]>
> Cc: "[hidden email]" <[hidden email]>
> Sent: Monday, October 3, 2011 10:32 PM
> Subject: Re: [LLVMdev] collect end line number for scope
>
>
> On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:
>
> For the above code, i want to collect endline (indicated by <---) for the
> scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
>
> I don't know about 2.9 in specific, but current top of tree will get you
> that information.
> -eric
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Pankaj Gode
Hi,
 
My problem definition is to collect "end line" for each scope (i.e. start and end line for a scope). I need to dump this information while emitting target code for an architecture. Though I understand that scoping details are not modeled in LLVM. Reference: http://llvm.org/docs/SourceLevelDebugging.html#format_common_lifetime
 
There are 2 classes I am referring, viz, DIScope and DbgScope.
I am also not sure on the approach.
 
Regards,
Pankaj
 

From: Alex <[hidden email]>
To: Pankaj Gode <[hidden email]>
Cc: Eric Christopher <[hidden email]>; "[hidden email]" <[hidden email]>
Sent: Tuesday, October 4, 2011 3:42 PM
Subject: Re: [LLVMdev] collect end line number for scope

Hi,

He is referring to current SVN head.

Regards,
Alex

On Tue, Oct 4, 2011 at 12:08 PM, Pankaj Gode <[hidden email]> wrote:

> What do you mean by "current top of tree"?
>
> Pankaj
> From: Eric Christopher <[hidden email]>
> To: Pankaj Gode <[hidden email]>
> Cc: "[hidden email]" <[hidden email]>
> Sent: Monday, October 3, 2011 10:32 PM
> Subject: Re: [LLVMdev] collect end line number for scope
>
>
> On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:
>
> For the above code, i want to collect endline (indicated by <---) for the
> scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
>
> I don't know about 2.9 in specific, but current top of tree will get you
> that information.
> -eric
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Eric Christopher-2

On Oct 4, 2011, at 4:32 AM, Pankaj Gode wrote:

Hi,
 
My problem definition is to collect "end line" for each scope (i.e. start and end line for a scope). I need to dump this information while emitting target code for an architecture. Though I understand that scoping details are not modeled in LLVM. Reference: http://llvm.org/docs/SourceLevelDebugging.html#format_common_lifetime


You have misread this link. We use metadata attached to instructions to model scopes. Look for DW_TAG_lexical_block in the output. I'm working on this area at the moment to make it more precise, but for the general case this should work just fine.

-eric

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Devang Patel
In reply to this post by Pankaj Gode
Pankaj,

On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:

Hi All,
 
int global;
int func( int t)
  //scope 1
  {
     ....
  } <-----
  return x;
}
 
For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
 

If there is no code generated for a source line with just "}", so you are not going to get that line number in debug info (because there is not any llvm instruction). You can access the line number for the last statement/expression in the scope. See http://llvm.org/docs/SourceLevelDebugging.html#ccxx_compile_units for a code snippet on how to get line number from an llvm instruction.

What exactly are you trying to do? Depending on your needs, you may be able to access clang AST nodes to get exact line and column number information for "}" irrespective of debug info.

-
Devang

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Pankaj Gode
Hi,
 
The link and the information shared was helpful.
 
I will make my problem definition more clear.
While I am "asm printing" target code, I also want to emit scope related information.
Scope related information includes,
- for each scope, start line, end line, start column, end column
and
- scope heirarchy.
As scope is delimited by "{" and "}" (for an input C/C++ code), hence wanted to collect "endline" for scope.
When I went through the ".ll" emitted by llc, i could find the "startline" in metadata.
 
For this I could think of 2 approaches
1. Create a pass in llvm, to collect this information from the llvm instructions, by simply traversing them.
  Identifying line number for each instruction and checking on the lexical block it points to. Also would maintain the parent/child lexical block relation using metadata information.
  My "startline" is least line number associated with lexical block, and "endline" number is max line number associated with lexical block.
2. While "asm printing", traverse through the machine instruction and collect the information in similar way as 1.
 
I am not sure whether I should collect it from Clang AST nodes.
 
Regards,
Pankaj
 
 
From: Devang Patel <[hidden email]>
To: Pankaj Gode <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Sent: Tuesday, October 4, 2011 10:08 PM
Subject: Re: [LLVMdev] collect end line number for scope

Pankaj,

On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:

Hi All,
 
int global;
int func( int t)
  //scope 1
  {
     ....
  } <-----
  return x;
}
 
For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
 

If there is no code generated for a source line with just "}", so you are not going to get that line number in debug info (because there is not any llvm instruction). You can access the line number for the last statement/expression in the scope. See http://llvm.org/docs/SourceLevelDebugging.html#ccxx_compile_units for a code snippet on how to get line number from an llvm instruction.

What exactly are you trying to do? Depending on your needs, you may be able to access clang AST nodes to get exact line and column number information for "}" irrespective of debug info.

-
Devang



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Devang Patel
Pankaj,

If you want to decorate MachineInstrs then for the end of scope you're not looking at "}" but instead you're looking at _last_ machine instruction in that scope. Now, if you want to find out start and end MachineInstrs for a lexical scope (and corresponding line numbers) then see CodeGen/LexicalScopes pass. It collects lexical scope information and maps MIs to respective lexical scopes.

-
Devang

On Oct 5, 2011, at 3:48 AM, Pankaj Gode wrote:

Hi,
 
The link and the information shared was helpful.
 
I will make my problem definition more clear.
While I am "asm printing" target code, I also want to emit scope related information.
Scope related information includes,
- for each scope, start line, end line, start column, end column
and
- scope heirarchy.
As scope is delimited by "{" and "}" (for an input C/C++ code), hence wanted to collect "endline" for scope.
When I went through the ".ll" emitted by llc, i could find the "startline" in metadata.
 
For this I could think of 2 approaches
1. Create a pass in llvm, to collect this information from the llvm instructions, by simply traversing them.
  Identifying line number for each instruction and checking on the lexical block it points to. Also would maintain the parent/child lexical block relation using metadata information.
  My "startline" is least line number associated with lexical block, and "endline" number is max line number associated with lexical block.
2. While "asm printing", traverse through the machine instruction and collect the information in similar way as 1.
 
I am not sure whether I should collect it from Clang AST nodes.
 
Regards,
Pankaj
 
 
From: Devang Patel <[hidden email]>
To: Pankaj Gode <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Sent: Tuesday, October 4, 2011 10:08 PM
Subject: Re: [LLVMdev] collect end line number for scope

Pankaj,

On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:

Hi All,
 
int global;
int func( int t)
  //scope 1
  {
     ....
  } <-----
  return x;
}
 
For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
 

If there is no code generated for a source line with just "}", so you are not going to get that line number in debug info (because there is not any llvm instruction). You can access the line number for the last statement/expression in the scope. See http://llvm.org/docs/SourceLevelDebugging.html#ccxx_compile_units for a code snippet on how to get line number from an llvm instruction.

What exactly are you trying to do? Depending on your needs, you may be able to access clang AST nodes to get exact line and column number information for "}" irrespective of debug info.

-
Devang




_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: collect end line number for scope

Pankaj Gode
Hi,
 
I had a look at CodeGen/LexicalScopes and decided to use it. I contains almost everything I want (other attributes can be easily extracted).  
As I am using llvm 2.9 and can't migrate to the latest llvm as of now, so I am using the LexicalScopes information while printing.
 
Thanks.
 
Pankaj
 

From: Devang Patel <[hidden email]>
To: Pankaj Gode <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Sent: Wednesday, October 5, 2011 10:04 PM
Subject: Re: [LLVMdev] collect end line number for scope

Pankaj,

If you want to decorate MachineInstrs then for the end of scope you're not looking at "}" but instead you're looking at _last_ machine instruction in that scope. Now, if you want to find out start and end MachineInstrs for a lexical scope (and corresponding line numbers) then see CodeGen/LexicalScopes pass. It collects lexical scope information and maps MIs to respective lexical scopes.

-
Devang

On Oct 5, 2011, at 3:48 AM, Pankaj Gode wrote:

Hi,
 
The link and the information shared was helpful.
 
I will make my problem definition more clear.
While I am "asm printing" target code, I also want to emit scope related information.
Scope related information includes,
- for each scope, start line, end line, start column, end column
and
- scope heirarchy.
As scope is delimited by "{" and "}" (for an input C/C++ code), hence wanted to collect "endline" for scope.
When I went through the ".ll" emitted by llc, i could find the "startline" in metadata.
 
For this I could think of 2 approaches
1. Create a pass in llvm, to collect this information from the llvm instructions, by simply traversing them.
  Identifying line number for each instruction and checking on the lexical block it points to. Also would maintain the parent/child lexical block relation using metadata information.
  My "startline" is least line number associated with lexical block, and "endline" number is max line number associated with lexical block.
2. While "asm printing", traverse through the machine instruction and collect the information in similar way as 1.
 
I am not sure whether I should collect it from Clang AST nodes.
 
Regards,
Pankaj
 
 
From: Devang Patel <[hidden email]>
To: Pankaj Gode <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Sent: Tuesday, October 4, 2011 10:08 PM
Subject: Re: [LLVMdev] collect end line number for scope

Pankaj,

On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:

Hi All,
 
int global;
int func( int t)
  //scope 1
  {
     ....
  } <-----
  return x;
}
 
For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ?
 

If there is no code generated for a source line with just "}", so you are not going to get that line number in debug info (because there is not any llvm instruction). You can access the line number for the last statement/expression in the scope. See http://llvm.org/docs/SourceLevelDebugging.html#ccxx_compile_units for a code snippet on how to get line number from an llvm instruction.

What exactly are you trying to do? Depending on your needs, you may be able to access clang AST nodes to get exact line and column number information for "}" irrespective of debug info.

-
Devang






_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev