Pushpinder Singh via llvm-dev
2017-Apr-19 15:50 UTC
[llvm-dev] API to Differentiate between SSA and non SSA form
Hello everyone, We are working on a particular points-to analysis. The final output of that analysis should not have the LLVM SSA temporaries (like, %0, %1). My doubt is that whether we can extract the normal C variables from LLVM IR or is there any way to differentiate between SSA temporary and local C variable? For e.g. in GCC I can check whether a particular variable is an SSA temporary like, if(TREE_CODE(t) == SSA_NAME) return true; Basically, I want to skip all those %0, %1 temporaries. But keep all those which refer to C variables. One way to do this would be to check whether a Value has been given a name by using hasName function. But it does not work every time. For e.g. in case of getelementptr instruction, this name refers to a member name of a structure (which is in SSA form). E.g., define void @f() { entry: %s = alloca %struct.A, align 8 %a = alloca i32, align 4 ; I can know that this is a C variable store i32 10, i32* %a, align 4 %b = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 1 ; but this is not store i32* %a, i32** %b, align 8 ; and this is not a C variable, so hasName logic can not work here. %a1 = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 0 store i32 30, i32* %a1, align 8 ret void } Thanks, Pushpinder Singh
Anshuman Dhuliya via llvm-dev
2017-Apr-19 16:22 UTC
[llvm-dev] API to Differentiate between SSA and non SSA form
Is it the case that for each C stack variable there will always be and 'alloca' statement. If so, we can identify all such variables. And globals can be identified separately, I guess... Thanks & Regards Anshuman Dhuliya PhD Scholar CSE Department IIT Bombay Mumbai, India On Wed, Apr 19, 2017 at 9:20 PM, Pushpinder Singh < pushpinderdhaliwal00 at gmail.com> wrote:> Hello everyone, > > We are working on a particular points-to analysis. The final output of > that analysis should not have the LLVM SSA temporaries (like, %0, %1). > My doubt is that whether we can extract the normal C variables from > LLVM IR or is there any way to differentiate between SSA temporary and > local C variable? > > For e.g. in GCC I can check whether a particular variable is an SSA > temporary like, > > if(TREE_CODE(t) == SSA_NAME) > return true; > > Basically, I want to skip all those %0, %1 temporaries. But keep all > those which refer to C variables. One way to do this would be to check > whether a Value has been given a name by using hasName function. But > it does not work every time. For e.g. in case of getelementptr > instruction, this name refers to a member name of a structure (which > is in SSA form). > E.g., > > define void @f() { > entry: > %s = alloca %struct.A, align 8 > %a = alloca i32, align 4 ; I can know that > this is a C variable > store i32 10, i32* %a, align 4 > %b = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 1 > ; but this is not > store i32* %a, i32** %b, align 8 > > ; and this is not a C variable, so hasName logic can not work here. > %a1 = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 0 > store i32 30, i32* %a1, align 8 > ret void > } > > Thanks, > Pushpinder Singh >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170419/a0a3774d/attachment.html>
mats petersson via llvm-dev
2017-Apr-21 08:37 UTC
[llvm-dev] API to Differentiate between SSA and non SSA form
On 19 April 2017 at 17:22, Anshuman Dhuliya via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Is it the case that for each C stack variable there will always be and > 'alloca' statement. If so, we can identify all such variables. >That would only hold true before the mem2reg pass, which makes the alloca into registers whenever possible. And conversely, the compiler may well introduce temporary allocas that aren't referring to any variable in the source code. I'd be surprised if there is a trivial way to tell this - more likely, you need source-code information (e.g. AST-level) to perform such analysis. Possibly debug info would be helpful too. -- Mats> > And globals can be identified separately, I guess... > > Thanks & Regards > Anshuman Dhuliya > PhD Scholar > CSE Department > IIT Bombay > Mumbai, India > > > > On Wed, Apr 19, 2017 at 9:20 PM, Pushpinder Singh < > pushpinderdhaliwal00 at gmail.com> wrote: > >> Hello everyone, >> >> We are working on a particular points-to analysis. The final output of >> that analysis should not have the LLVM SSA temporaries (like, %0, %1). >> My doubt is that whether we can extract the normal C variables from >> LLVM IR or is there any way to differentiate between SSA temporary and >> local C variable? >> >> For e.g. in GCC I can check whether a particular variable is an SSA >> temporary like, >> >> if(TREE_CODE(t) == SSA_NAME) >> return true; >> >> Basically, I want to skip all those %0, %1 temporaries. But keep all >> those which refer to C variables. One way to do this would be to check >> whether a Value has been given a name by using hasName function. But >> it does not work every time. For e.g. in case of getelementptr >> instruction, this name refers to a member name of a structure (which >> is in SSA form). >> E.g., >> >> define void @f() { >> entry: >> %s = alloca %struct.A, align 8 >> %a = alloca i32, align 4 ; I can know that >> this is a C variable >> store i32 10, i32* %a, align 4 >> %b = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 1 >> ; but this is not >> store i32* %a, i32** %b, align 8 >> >> ; and this is not a C variable, so hasName logic can not work here. >> %a1 = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 0 >> store i32 30, i32* %a1, align 8 >> ret void >> } >> >> Thanks, >> Pushpinder Singh >> > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170421/de6b18a0/attachment.html>
James Courtier-Dutton via llvm-dev
2017-Apr-21 12:18 UTC
[llvm-dev] API to Differentiate between SSA and non SSA form
On 19 April 2017 at 16:50, Pushpinder Singh via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello everyone, > > We are working on a particular points-to analysis. The final output of > that analysis should not have the LLVM SSA temporaries (like, %0, %1). > My doubt is that whether we can extract the normal C variables from > LLVM IR or is there any way to differentiate between SSA temporary and > local C variable? > >SSA does not directly map onto C variables. C variables vary. SSA labels do not vary. If you wish to raise LLVM to C, a general approach could take all the SSA labels that are linked with a PHI statement, and give them all the same C variable name. It is unclear what you mean by "points-to analysis". You might wish to look into "alias analysis" as it might be similar to what you are trying to do. The "alloca" statement can represent a C local variable, but due to optimisations, not all C local variables are stored on the stack. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170421/c7f6b2f3/attachment.html>