[Rose-public] Fwd: SSA support

Nilesh Mahajan nnmahaja at umail.iu.edu
Sat Mar 3 18:25:53 PST 2012


Hi all,

I was interested in ROSE SSA support and had some questions. George
Vulov was kind enough to answer them. Here is our correspondence for
anyone interested.

Thanks George!

Regards,
Nilesh.

---------- Forwarded message ----------
From: George Vulov <georgevulov at hotmail.com>
Date: Mon, Feb 20, 2012 at 10:24 PM
Subject: Re: SSA support
To: Nilesh Mahajan <nnmahaja at umail.iu.edu>


The situation is slightly more complicated, because a def doesn't
necessarily correspond to an SgVarRef.

For example, the code
a.x = 3; contains an "original" def for the expression
SgDotExp(SgVarRef(a), SgVarRef(x)).
The code also contains an "expanded def" for the root variable, SgVarRef(a).

Notice that if you treat defs as having a 1-1 correspondence with
SgVarRef, you will mess up something like

a.x = ...;
a.y = ...;

because the base SgVarRef is "a" for both of them. In this situations,
SSA::getVarName() is your friend; it returns the full name such as a.x
that corresponds to a given node (e.g. if you just give it the var ref
for x). Also, you can use SSA_UnfilteredCfg::buildVariableReference to
build a reference expression for a variable given its VarName. This
method is pretty straightforward; you are probably writing something
similar for your own work.

Anyway, you're right that there's no easy way to recover the actual
expression being defined with the current SSA interface; it takes some
extra work. What I suggest doing is querying the subtree for all
instances of SgVarRef* (using SageInterface::querySubTree), and then
using SSA::getDefinitionForUse and SSA::getVarName to filter out those
expressions that are not being defined.

Also, please do post these emails verbatim to rose-public, just so
that the information is out there before you finish your report. I
think the SSA analysis is being used actively.

-George


On 2/17/12 6:22 PM, Nilesh Mahajan wrote:

Hi George,

Thanks for you reply.

Yes, I can get the defs at a node. It's just that I wanted to get the
SgVarRefs at that node. getDefsAtNode gives you a <VarName,
ReachingDef> map which is useful but will not give you the SgVarRefs.
For that I have to deconstruct the node (see if it's
SgAssignOp/SgInitializedName etc.). When going out of SSA, I have to
replace the original defs with new variable defs e.g.

int x = 1;
...
... = x;

becomes

int x0 = 1;
...
... = x0;

Now I can get to the def, but I will have to deconstruct the
SgInitializedName AST node and replace 'x' with 'x0'. I was asking if
there is any way you could do that with the SSA API.

I will surely share these points, maybe in the form of a document,
along with the out-of-ssa stuff that I am building right now.

Thanks,
Nilesh.

On Wed, Feb 15, 2012 at 1:12 AM, George Vulov <georgevulov at hotmail.com> wrote:

To get the defs at a node, use ssa::getDefsAtNode. Note that a single AST
node may correspond to multiple CFG nodes; you can convert an AST node to a
CFG node with SgNode::cfgForBeginning() and SgNode::cfgForEnd() (some AST
nodes even correspond to than more than two CFG nodes;
SgNode::cfgIndexForEnd() + 1 is the number of CFG nodes generated from the
corresponding AST node).

Once you obtain ReachingDef objects, you can call
ReachingDef::getDefinitionNode() to get the node at which the def actually
occurred. This returns the CFGNode at which the definition occurred; you can
get the AST node that corresponds to that CFG node using CFGNode::getNode().

As you do this work, you should generate a graph of the CFG so you can
visually verify what is going on. Check out the ssa::toDOT and
ssa::toFilteredDOT functions; you can view the dot files using the graphviz
package.

Please post this answer, as well as the answer to your original question, to
rose-public, so that others may take advantage of this information.

Regards,

-George


On 2/13/12 3:51 PM, Nilesh Mahajan wrote:

Hi George,

I was trying to rename the defs of the ssa vars which is required when
you are going out of ssa. The problem I am facing is I don't know how
to get the defs at a node.
So what I did was
SSA_UnfilteredCfg::ReachingDefPtr def = ssa.getDefinitionForUse(ssa_ref);
set<CFGNode> actual_defs = def->getActualDefinitions();
foreach(CFGNode adef, actual_defs) {

Now in the for loop getDefsAtNode does not work (doesn't return the
defs). I took set difference of getReachingDefsAfter and
getReachingDefsBefore and that gives me the SSA_UnfilteredCfg::VarName
but not the actual AST node (SgVarRefExp*). Can you please suggest
anything I could do to get the AST def node?

Thanks,
Nilesh.

On Mon, Feb 6, 2012 at 12:33 AM, Nilesh Mahajan <nnmahaja at umail.iu.edu>
wrote:

Thanks George!

On Sat, Feb 4, 2012 at 3:52 PM, George Vulov <georgevulov at hotmail.com>
wrote:

1. You do need to calculate SSA again. The virtual CFG is generated
on-the-fly based on the AST, so it is updated automatically when the AST
changes
2. The ReachingDef object returned by SSA has a .getRenamingNumber() member
function that returns the number. Please refer to the doxygen documentation:

 http://www.rosecompiler.org/ROSE_HTML_Reference/classssa__unfiltered__cfg_1_1ReachingDef.html

 http://www.rosecompiler.org/ROSE_HTML_Reference/classssa__unfiltered__cfg_1_1SSA__UnfilteredCfg.html
3. The SSA in ROSE is treated as an analysis, rather than as a
transformation. It leaves the AST intact, and instead attaches information
to all the nodes.
4. Again, we have implemented SSA as an analysis. You have to use this
information to perform AST transformations.

-George


On 1/27/12 1:45 PM, Nilesh Mahajan wrote:

Hi George,

I saw you as the author of the file ssaUnfilteredCfg.h in the ROSE
source code. Since nobody else answered my questions on the ROSE
mailing list, I thought of mailing you directly. Sorry for the trouble
but it will help me a lot if you answered my questions below.

1. If I modified the AST/CFG, do I have to calculate the SSA again? I do
not see a way to modify the virtual CFG though.
2. Is there any way I can get the numbering info? SSA assigns unique
numbers to vars.
3. Is there any way, I can output the SSA form of the program? The AST
is not modified currently.
4. How do I get out of SSA?

Thanks,
Nilesh.

On Thu, Jan 26, 2012 at 6:46 PM, Nilesh Mahajan<nnmahaja at umail.iu.edu>
 wrote:

Is there anyone I can contact for these questions?

Thanks,
Nilesh.

On Tue, Jan 24, 2012 at 3:49 AM, Nilesh Mahajan<nnmahaja at umail.iu.edu>
 wrote:

Hi all,

I was looking at the SSA support in ROSE (SSA_UnfilteredCfg). The
example file is

tests/roseTests/programAnalysisTests/staticSingleAssignmentTests/ssaTestHarness.C.
I see that I can get defs at an AST node, def-use information. I have
some questions though:
1. If I modified the AST, do I have to calculate the SSA again?
2. Is there any way I can get the numbering info? SSA assigns unique
numbers to vars.
3. Is there any way, I can output the SSA form of the program? The AST
is not modified currently.
4. How do I get out of SSA?

Thanks,
Nilesh.


More information about the rose-public mailing list