This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
forked from Bluefire2/xic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Guava 16 with 27, fix live var analysis, create a SetWithInf …
…wrapper for inf sets
- Loading branch information
1 parent
c6caeeb
commit c3dd265
Showing
10 changed files
with
171 additions
and
47 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
Binary file not shown.
Binary file not shown.
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
2 changes: 1 addition & 1 deletion
2
src/main/java/kc875/asm/graph/FlowGraph.java → src/main/java/kc875/asm/dfa/FlowGraph.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package kc875.asm.graph; | ||
package kc875.asm.dfa; | ||
|
||
import kc875.asm.ASMExprRegReplaceable; | ||
import kc875.cfg.Graph; | ||
|
2 changes: 1 addition & 1 deletion
2
...va/kc875/asm/graph/InterferenceGraph.java → ...java/kc875/asm/dfa/InterferenceGraph.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package kc875.asm.graph; | ||
package kc875.asm.dfa; | ||
|
||
import kc875.asm.ASMExprTemp; | ||
import kc875.asm.ASMInstr_2Arg; | ||
|
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,34 @@ | ||
package kc875.asm.dfa; | ||
|
||
import kc875.asm.ASMExprRegReplaceable; | ||
import kc875.cfg.DFAFramework; | ||
import kc875.cfg.Graph; | ||
import kc875.cfg.GraphNode; | ||
import kc875.utils.SetWithInf; | ||
|
||
/** | ||
* Live variable DFA (used in reg allocation). The lattice elements are sets | ||
* of Temps/Regs. | ||
*/ | ||
public class LiveVariableDFA extends DFAFramework<SetWithInf<ASMExprRegReplaceable>> { | ||
|
||
public LiveVariableDFA(Graph graph) { | ||
super( | ||
graph, | ||
Direction.BACKWARD, | ||
(node, l) -> use(node).union(l.diff(def(node))), | ||
SetWithInf::union, | ||
SetWithInf.infSet() | ||
); | ||
} | ||
|
||
// TODO | ||
public static SetWithInf<ASMExprRegReplaceable> use(GraphNode node) { | ||
return new SetWithInf<>(); | ||
} | ||
|
||
// TODO | ||
public static SetWithInf<ASMExprRegReplaceable> def(GraphNode node) { | ||
return new SetWithInf<>(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,66 @@ | ||
package kc875.cfg; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
import java.util.function.BinaryOperator; | ||
|
||
public abstract class DFAFramework<T> { | ||
// T are the lattice elements. | ||
|
||
// Graph associated with this DFA. | ||
protected Graph graph; | ||
|
||
// Direction of the DFA | ||
public enum Direction {FORWARD, BACKWARD} | ||
protected Direction direction; | ||
|
||
// Transformer function or F. Takes in the node and a lattice element, | ||
// and returns a lattice element. | ||
protected BiFunction<GraphNode, T, T> F; | ||
|
||
// Meet operator, combining l1 and l2 to produce l. A BinaryOperator<T> | ||
// is a BiFunction<T, T, T>. | ||
protected BinaryOperator<T> meet; | ||
|
||
/** | ||
* Applies the meet operator on the lattice elements ls. Returns Optional | ||
* .empty() if ls is empty, otherwise reductively applies the meet operator. | ||
* @param ls lattice elements. | ||
*/ | ||
public Optional<T> applyMeet(Collection<T> ls) { | ||
return ls.stream().reduce(meet); | ||
} | ||
|
||
// Maps from nodes to lattice elements in (after meet if applicable) and | ||
// out (before meet if applicable) of the node. | ||
protected Map<GraphNode, T> inMap = new HashMap<>(); | ||
protected Map<GraphNode, T> outMap = new HashMap<>(); | ||
|
||
/** | ||
* Initialize the DFA Framework, with all nodes' inMap and outMap | ||
* initialized to lattice element top. | ||
* @param graph graph associated with this DFA. | ||
* @param direction direction of DFA. | ||
* @param F transformer function. | ||
* @param meet meet operator. | ||
* @param top top lattice element for initialization. | ||
*/ | ||
public DFAFramework(Graph graph, | ||
Direction direction, | ||
BiFunction<GraphNode, T, T> F, | ||
BinaryOperator<T> meet, | ||
T top | ||
) { | ||
this.graph = graph; | ||
this.direction = direction; | ||
this.F = F; | ||
this.meet = meet; | ||
for (GraphNode node : graph.getAllNodes()) { | ||
inMap.put(node, top); | ||
outMap.put(node, top); | ||
} | ||
} | ||
} |
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,66 @@ | ||
package kc875.utils; | ||
|
||
import com.google.common.collect.Sets; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* A wrapper on Set, providing support for infinite sets. | ||
*/ | ||
public class SetWithInf<E> { | ||
// Class invariants: | ||
// - An element s cannot be in both includeSet and excludeSet at the same | ||
// time. | ||
// - A set can be infinite and still have non-empty excludeSet. If a set | ||
// is infinite, then we don't care about the includeSet. | ||
private Set<E> set; | ||
private boolean isInf = false; | ||
|
||
public SetWithInf(Set<E> set) { | ||
this.set = set; | ||
isInf = false; | ||
} | ||
|
||
public SetWithInf() { | ||
this(new HashSet<>()); | ||
} | ||
|
||
public static<T> SetWithInf<T> infSet() { | ||
SetWithInf<T> set = new SetWithInf<>(); | ||
set.isInf = true; | ||
return set; | ||
} | ||
|
||
/** | ||
* Returns a SetWithInf of T elements with includeSet as the wrapped set | ||
* in the returned wrapper. | ||
* @param includeSet set to wrap around. | ||
*/ | ||
private static<T> SetWithInf<T> infSet(Set<T> includeSet) { | ||
SetWithInf<T> set = new SetWithInf<>(includeSet); | ||
set.isInf = true; | ||
return set; | ||
} | ||
|
||
public SetWithInf<E> union(SetWithInf<E> other) { | ||
Set<E> unionSet = Sets.union(this.set, other.set).immutableCopy(); | ||
if (this.isInf || other.isInf) { | ||
// return an inf set but with the wrapped sets combined | ||
return infSet(unionSet); | ||
} else { | ||
// both are non-inf sets | ||
return new SetWithInf<>(unionSet); | ||
} | ||
} | ||
|
||
// TODO | ||
public SetWithInf<E> intersect(SetWithInf<E> other) { | ||
return null; | ||
} | ||
|
||
// TODO | ||
public SetWithInf<E> diff(SetWithInf<E> other) { | ||
return null; | ||
} | ||
} |