[prev in list] [next in list] [prev in thread] [next in thread]
List: soot-list
Subject: Re: [Soot-list] Constant Propagation
From: Alefiya Lightwala <alefiya.lightwala90 () gmail ! com>
Date: 2013-09-23 18:39:10
Message-ID: CACqPjruQ0awMo6k4WE+xOoui9FxrBX1s4qU3gmVGBUWwkeSBMg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Thankyou.. It solved the problem...
Regards
Alefiya
On Mon, Sep 23, 2013 at 11:28 PM, Bernhard Berger <berber@tzi.de> wrote:
> Hi Alefiya,
>
> I've not checked your code thoroughly but wanted to give you at least one
> pointer. Your copy function is broken since you do not update the
> destination parameter. You overwrite the parameter value. Hope that this
> helps.
>
> Bernhard
>
> Am 23.09.2013 um 19:37 schrieb Alefiya Lightwala <
> alefiya.lightwala90@gmail.com>:
>
> > package vasco.soot.examples;
> >
> > import java.util.HashMap;
> > import java.util.Map;
> >
> > import soot.Local;
> > import soot.Unit;
> > import soot.Value;
> > import soot.jimple.AssignStmt;
> > import soot.jimple.CastExpr;
> > import soot.jimple.Constant;
> > import soot.jimple.ReturnStmt;
> > import soot.jimple.internal.JimpleLocal;
> > import soot.toolkits.graph.DirectedGraph;
> > import soot.toolkits.graph.UnitGraph;
> > import soot.toolkits.scalar.ArraySparseSet;
> > import soot.toolkits.scalar.FlowSet;
> > import soot.toolkits.scalar.ForwardFlowAnalysis;
> >
> > public class constantprop extends
> ForwardFlowAnalysis<Unit,Map<Local,Constant>>{
> > private static final Local RETURN_LOCAL = new JimpleLocal("@return",
> null);
> > DirectedGraph<Unit> graph;
> > public constantprop(DirectedGraph<Unit> graph) {
> > super(graph);
> > this.graph=graph;
> > doAnalysis();
> > }
> > private void assign(Local lhs, Value rhs, Map<Local, Constant>
> input, Map<Local, Constant> output) {
> > // First remove casts, if any.
> > if (rhs instanceof CastExpr) {
> > rhs = ((CastExpr) rhs).getOp();
> > }
> > // Then check if the RHS operand is a constant or local
> > if (rhs instanceof Constant) {
> > // If RHS is a constant, it is a direct gen
> > output.put(lhs, (Constant) rhs);
> > } else if (rhs instanceof Local) {
> > // Copy constant-status of RHS to LHS (indirect gen), if
> exists
> > if(input.containsKey(rhs)) {
> > output.put(lhs, input.get(rhs));
> > }
> > } else {
> > // RHS is some compound expression, then LHS is non-constant
> (only kill)
> > output.put(lhs, null);
> > }
> > }
> >
> > @Override
> > protected void flowThrough(Map<Local, Constant> inValue, Unit unit,
> > Map<Local, Constant> outValue) {
> > System.out.println("invalue="+inValue);
> > copy(inValue,outValue);
> > // Only statements assigning locals matter
> > if (unit instanceof AssignStmt) {
> > // Get operands
> > Value lhsOp = ((AssignStmt) unit).getLeftOp();
> > Value rhsOp = ((AssignStmt) unit).getRightOp();
> > if (lhsOp instanceof Local) {
> > assign((Local) lhsOp, rhsOp, inValue, outValue);
> > }
> > } else if (unit instanceof ReturnStmt) {
> > // Get operand
> > Value rhsOp = ((ReturnStmt) unit).getOp();
> > assign(RETURN_LOCAL, rhsOp, inValue, outValue);
> > }
> > // Return the data flow value at the OUT of the statement
> >
> > }
> >
> > @Override
> > protected void merge(Map<Local, Constant> op1, Map<Local, Constant>
> op2,
> > Map<Local, Constant> out) {
> > //Map<Local, Constant> result;
> > // First add everything in the first operand
> > copy(op1,out);
> > FlowSet l = null;
> > l.add(op1);
> >
> > // Then add everything in the second operand, bottoming out the
> common keys with different values
> > for (Local x : op2.keySet()) {
> > if (op1.containsKey(x)) {
> > // Check the values in both operands
> > Constant c1 = op1.get(x);
> > Constant c2 = op2.get(x);
> > if (c1 != null && c1.equals(c2) == false) {
> > // Set to non-constant
> > out.put(x, null);
> > }
> > } else {
> > // Only in second operand, so add as-is
> > out.put(x, op2.get(x));
> > }
> > }
> >
> > }
> >
> > @Override
> > protected void copy(Map<Local, Constant> source, Map<Local,
> Constant> dest) {
> > dest = new HashMap<Local,Constant>(source);
> > }
> >
> > @Override
> > protected Map<Local, Constant> entryInitialFlow() {
> > return new HashMap<Local,Constant>();
> > }
> >
> >
> >
> > @Override
> > protected Map<Local, Constant> newInitialFlow() {
> > return new HashMap<Local,Constant>();
> > }
> >
> >
> > }
> >
> > Here I attached code for constant propagation in soot. The values
> computed at OUT of one node are not propagated to IN of its predecessor
> node. IN for all the nodes is null. What is the problem with code?
> >
> > Regards
> > Alefiya
> > _______________________________________________
> > Soot-list mailing list
> > Soot-list@sable.mcgill.ca
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>
[Attachment #5 (text/html)]
<div dir="ltr"><div>Thankyou.. It solved the \
problem...<br><br></div>Regards<br>Alefiya<br></div><div \
class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 23, 2013 at 11:28 \
PM, Bernhard Berger <span dir="ltr"><<a href="mailto:berber@tzi.de" \
target="_blank">berber@tzi.de</a>></span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hi Alefiya,<br> <br>
I've not checked your code thoroughly but wanted to give you at least one \
pointer. Your copy function is broken since you do not update the destination \
parameter. You overwrite the parameter value. Hope that this helps.<br>
<br>
Bernhard<br>
<br>
Am 23.09.2013 um 19:37 schrieb Alefiya Lightwala <<a \
href="mailto:alefiya.lightwala90@gmail.com">alefiya.lightwala90@gmail.com</a>>:<br>
<div><div class="h5"><br>
> package vasco.soot.examples;<br>
><br>
> import java.util.HashMap;<br>
> import java.util.Map;<br>
><br>
> import soot.Local;<br>
> import soot.Unit;<br>
> import soot.Value;<br>
> import soot.jimple.AssignStmt;<br>
> import soot.jimple.CastExpr;<br>
> import soot.jimple.Constant;<br>
> import soot.jimple.ReturnStmt;<br>
> import soot.jimple.internal.JimpleLocal;<br>
> import soot.toolkits.graph.DirectedGraph;<br>
> import soot.toolkits.graph.UnitGraph;<br>
> import soot.toolkits.scalar.ArraySparseSet;<br>
> import soot.toolkits.scalar.FlowSet;<br>
> import soot.toolkits.scalar.ForwardFlowAnalysis;<br>
><br>
> public class constantprop extends \
ForwardFlowAnalysis<Unit,Map<Local,Constant>>{<br> > private \
static final Local RETURN_LOCAL = new JimpleLocal("@return", null);<br> \
> DirectedGraph<Unit> graph;<br> > public \
constantprop(DirectedGraph<Unit> graph) {<br> > super(graph);<br>
> this.graph=graph;<br>
> doAnalysis();<br>
> }<br>
> private void assign(Local lhs, Value rhs, Map<Local, Constant> input, \
Map<Local, Constant> output) {<br> > // First remove casts, if \
any.<br> > if (rhs instanceof CastExpr) {<br>
> rhs = ((CastExpr) rhs).getOp();<br>
> }<br>
> // Then check if the RHS operand is a constant or local<br>
> if (rhs instanceof Constant) {<br>
> // If RHS is a constant, it is a direct gen<br>
> output.put(lhs, (Constant) rhs);<br>
> } else if (rhs instanceof Local) {<br>
> // Copy constant-status of RHS to LHS (indirect gen), if exists<br>
> if(input.containsKey(rhs)) {<br>
> output.put(lhs, input.get(rhs));<br>
> }<br>
> } else {<br>
> // RHS is some compound expression, then LHS is non-constant (only \
kill)<br> > output.put(lhs, null);<br>
> }<br>
> }<br>
><br>
> @Override<br>
> protected void flowThrough(Map<Local, Constant> inValue, Unit \
unit,<br> > Map<Local, Constant> outValue) {<br>
> System.out.println("invalue="+inValue);<br>
> copy(inValue,outValue);<br>
> // Only statements assigning locals matter<br>
> if (unit instanceof AssignStmt) {<br>
> // Get operands<br>
> Value lhsOp = ((AssignStmt) unit).getLeftOp();<br>
> Value rhsOp = ((AssignStmt) unit).getRightOp();<br>
> if (lhsOp instanceof Local) {<br>
> assign((Local) lhsOp, rhsOp, inValue, outValue);<br>
> }<br>
> } else if (unit instanceof ReturnStmt) {<br>
> // Get operand<br>
> Value rhsOp = ((ReturnStmt) unit).getOp();<br>
> assign(RETURN_LOCAL, rhsOp, inValue, outValue);<br>
> }<br>
> // Return the data flow value at the OUT of the statement<br>
><br>
> }<br>
><br>
> @Override<br>
> protected void merge(Map<Local, Constant> op1, Map<Local, \
Constant> op2,<br> > Map<Local, Constant> out) {<br>
> //Map<Local, Constant> result;<br>
> // First add everything in the first operand<br>
> copy(op1,out);<br>
> FlowSet l = null;<br>
> l.add(op1);<br>
><br>
> // Then add everything in the second operand, bottoming out the common \
keys with different values<br> > for (Local x : op2.keySet()) {<br>
> if (op1.containsKey(x)) {<br>
> // Check the values in both operands<br>
> Constant c1 = op1.get(x);<br>
> Constant c2 = op2.get(x);<br>
> if (c1 != null && c1.equals(c2) == false) {<br>
> // Set to non-constant<br>
> out.put(x, null);<br>
> }<br>
> } else {<br>
> // Only in second operand, so add as-is<br>
> out.put(x, op2.get(x));<br>
> }<br>
> }<br>
><br>
> }<br>
><br>
> @Override<br>
> protected void copy(Map<Local, Constant> source, Map<Local, \
Constant> dest) {<br> > dest = new \
HashMap<Local,Constant>(source);<br> > }<br>
><br>
> @Override<br>
> protected Map<Local, Constant> entryInitialFlow() {<br>
> return new HashMap<Local,Constant>();<br>
> }<br>
><br>
><br>
><br>
> @Override<br>
> protected Map<Local, Constant> newInitialFlow() {<br>
> return new HashMap<Local,Constant>();<br>
> }<br>
><br>
><br>
> }<br>
><br>
> Here I attached code for constant propagation in soot. The values computed at \
OUT of one node are not propagated to IN of its predecessor node. IN for all the \
nodes is null. What is the problem with code?<br> ><br>
> Regards<br>
> Alefiya<br>
</div></div>> _______________________________________________<br>
> Soot-list mailing list<br>
> <a href="mailto:Soot-list@sable.mcgill.ca">Soot-list@sable.mcgill.ca</a><br>
> <a href="http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list" \
target="_blank">http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list</a><br> <br>
</blockquote></div><br></div>
_______________________________________________
Soot-list mailing list
Soot-list@sable.mcgill.ca
http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic