-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit of moving IR persistence toward being instance based so …
…we can override it
Showing
10 changed files
with
279 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/main/java/org/jruby/ir/dataflow/analyses/AddMissingAssignsNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.jruby.ir.dataflow.analyses; | ||
|
||
import java.util.BitSet; | ||
import java.util.HashSet; | ||
import org.jruby.dirgra.Edge; | ||
import org.jruby.ir.dataflow.FlowGraphNode; | ||
import org.jruby.ir.instructions.Instr; | ||
import org.jruby.ir.instructions.ResultInstr; | ||
import org.jruby.ir.operands.Variable; | ||
import org.jruby.ir.representations.BasicBlock; | ||
|
||
/** | ||
*/ | ||
public class AddMissingAssignsNode extends FlowGraphNode<AddMissingAssignsProblem, AddMissingAssignsNode> { | ||
private HashSet out; | ||
private HashSet use; | ||
private HashSet def; | ||
|
||
public AddMissingAssignsNode(AddMissingAssignsProblem problem, BasicBlock bb) { | ||
super(problem, bb); | ||
|
||
out = new HashSet(); | ||
use = new HashSet(); | ||
def = new HashSet(); | ||
} | ||
|
||
@Override | ||
public void buildDataFlowVars(Instr i) { | ||
if (i instanceof ResultInstr) registerVariable(((ResultInstr) i).getResult()); | ||
|
||
for (Variable x: i.getUsedVariables()) { | ||
registerVariable(x); | ||
} | ||
} | ||
|
||
@Override | ||
public void applyPreMeetHandler() { | ||
} | ||
|
||
@Override | ||
public void compute_MEET(Edge e, AddMissingAssignsNode pred) { | ||
use.retainAll(pred.out); | ||
} | ||
|
||
@Override | ||
public void applyTransferFunction(Instr instr) { | ||
if (instr instanceof ResultInstr) def.add(((ResultInstr) instr).getResult()); | ||
|
||
for (Variable variable: instr.getUsedVariables()) { | ||
use.add(variable); | ||
} | ||
} | ||
|
||
@Override | ||
public void finalizeSolution() { | ||
out = def; | ||
} | ||
|
||
@Override | ||
public boolean solutionChanged() { | ||
return !out.equals(def); | ||
} | ||
|
||
private void registerVariable(Variable variable) { | ||
if (!problem.hasVariable(variable)) problem.addVariable(variable); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/jruby/ir/dataflow/analyses/AddMissingAssignsProblem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jruby.ir.dataflow.analyses; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.jruby.ir.IRScope; | ||
import org.jruby.ir.dataflow.DataFlowProblem; | ||
import org.jruby.ir.operands.Variable; | ||
import org.jruby.ir.representations.BasicBlock; | ||
|
||
/** | ||
*/ | ||
public class AddMissingAssignsProblem extends DataFlowProblem<AddMissingAssignsProblem, AddMissingAssignsNode> { | ||
public static final String NAME = "Live Variables Analysis"; | ||
|
||
private Set<Variable> variables; | ||
|
||
public AddMissingAssignsProblem(IRScope scope) { | ||
super(DataFlowProblem.DF_Direction.FORWARD); | ||
setup(scope); | ||
variables = new HashSet<>(); | ||
} | ||
|
||
protected void addVariable(Variable variable) { | ||
variables.add(variable); | ||
} | ||
|
||
protected boolean hasVariable(Variable variable) { | ||
return variables.contains(variable); | ||
} | ||
|
||
@Override | ||
public AddMissingAssignsNode buildFlowGraphNode(BasicBlock bb) { | ||
return new AddMissingAssignsNode(this, bb); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters