forked from jruby/jruby
/
AddLocalVarLoadStoreInstructions.java
54 lines (42 loc) · 1.85 KB
/
AddLocalVarLoadStoreInstructions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.jruby.ir.passes;
import java.util.HashMap;
import java.util.Map;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.dataflow.analyses.LoadLocalVarPlacementProblem;
import org.jruby.ir.dataflow.analyses.StoreLocalVarPlacementProblem;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.representations.BasicBlock;
public class AddLocalVarLoadStoreInstructions extends CompilerPass {
public static String[] NAMES = new String[] { "add_lvar_load_store", "add_local_var_load_store_instructions" };
public String getLabel() {
return "Add Local Variable Load/Store Instructions";
}
public boolean isPreOrder() {
return false;
}
public Object execute(IRScope s, Object... data) {
// if (s.requiresBinding()) {
StoreLocalVarPlacementProblem fsp = new StoreLocalVarPlacementProblem();
fsp.setup(s);
fsp.compute_MOP_Solution();
LoadLocalVarPlacementProblem frp = new LoadLocalVarPlacementProblem();
frp.setup(s);
frp.compute_MOP_Solution();
// Add stores and loads, assigning an equivalent tmp-var for each local var
Map<Operand, Operand> varRenameMap = new HashMap<Operand, Operand>();
fsp.addStoreAndBindingAllocInstructions(varRenameMap);
frp.addLoads(varRenameMap);
// Rename all local var uses with their tmp-var stand-ins
for (BasicBlock b: s.getCFG().getBasicBlocks()) {
for (Instr i: b.getInstrs()) i.renameVars(varRenameMap);
}
// }
// Run on all nested closures.
// In the current implementation, nested scopes are processed independently (unlike Live Variable Analysis)
for (IRClosure c: s.getClosures()) execute(c);
return null;
}
}