Extracting the global variables accessed by individual function with function pass

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

Extracting the global variables accessed by individual function with function pass

Yan Lin Aung
Hi All,

Is there a way to dump the global variables, which are accessed (read/written to) by each function within the LLVM function pass?
Any pointers on how that info can be extracted in LLVM for each function in the application?

Thanks.

Regards,
Yan Lin Aung


_______________________________________________
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: Extracting the global variables accessed by individual function with function pass

Duncan Sands
Hi,

> Is there a way to dump the global variables, which are accessed (read/written
> to) by each function within the LLVM function pass?
> Any pointers on how that info can be extracted in LLVM for each function in the
> application?

you will have to write your own pass to do this.  For each global, visit each
of its uses (via use_begin, use_end).  If the use is a constant (isa<Constant>),
visit each of its uses too (do this recursively until you aren't visiting
constants any more).  If a use isn't a constant, check whether it's parent
(getParent) is the function you are interested in.  The point of recursing on
constant uses is that the global may be used in a constant expression (eg a
constant bitcast) before actually being used by an instruction.

Ciao, Duncan.
_______________________________________________
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: Extracting the global variables accessed by individual function with function pass

John Criswell-4
On 9/2/13 6:15 AM, Duncan Sands wrote:

> Hi,
>
>> Is there a way to dump the global variables, which are accessed
>> (read/written
>> to) by each function within the LLVM function pass?
>> Any pointers on how that info can be extracted in LLVM for each
>> function in the
>> application?
>
> you will have to write your own pass to do this.  For each global,
> visit each
> of its uses (via use_begin, use_end).  If the use is a constant
> (isa<Constant>),
> visit each of its uses too (do this recursively until you aren't visiting
> constants any more).  If a use isn't a constant, check whether it's
> parent
> (getParent) is the function you are interested in.  The point of
> recursing on
> constant uses is that the global may be used in a constant expression
> (eg a
> constant bitcast) before actually being used by an instruction.

Note that this only finds globals that are directly accessed by the
function.  It won't find globals that are accessed by the function due
to the global being passed into the function as an argument or loaded
from memory via an LLVM load instruction.  To find those, you'll need to
use alias analysis or a points-to analysis.

-- John T.

>
> Ciao, Duncan.
> _______________________________________________
> 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: Extracting the global variables accessed by individual function with function pass

Yan Lin Aung
Hi Duncan and John,

Thank your very much for the advice and help.

Yes, I have got the first part working following Duncan's advice.

I think I can also incorporate Alias Analysis (AA) in my code.

A bit of guidance on how the LLVM provided methods in AA have to be invoked so as to get the info on
the global being passed into the function as an argument or loaded from memory via an LLVM load instruction as John pointed out?

Thanks again.

Regards,
Yan Lin Aung


From: John Criswell <[hidden email]>
To: Duncan Sands <[hidden email]>
Cc: [hidden email]
Sent: Friday, September 6, 2013 11:41 PM
Subject: Re: [LLVMdev] Extracting the global variables accessed by individual function with function pass

On 9/2/13 6:15 AM, Duncan Sands wrote:

> Hi,
>
>> Is there a way to dump the global variables, which are accessed
>> (read/written
>> to) by each function within the LLVM function pass?
>> Any pointers on how that info can be extracted in LLVM for each
>> function in the
>> application?
>
> you will have to write your own pass to do this.  For each global,
> visit each
> of its uses (via use_begin, use_end).  If the use is a constant
> (isa<Constant>),
> visit each of its uses too (do this recursively until you aren't visiting
> constants any more).  If a use isn't a constant, check whether it's
> parent
> (getParent) is the function you are interested in.  The point of
> recursing on
> constant uses is that the global may be used in a constant expression
> (eg a
> constant bitcast) before actually being used by an instruction.

Note that this only finds globals that are directly accessed by the
function.  It won't find globals that are accessed by the function due
to the global being passed into the function as an argument or loaded
from memory via an LLVM load instruction.  To find those, you'll need to
use alias analysis or a points-to analysis.

-- John T.

>
> Ciao, Duncan.
> _______________________________________________
> 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



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