# HG changeset patch # User Bernhard Urban # Date 1384808858 -3600 # Node ID 1729072a893a784b56c14ca8d46ccfac249f430a # Parent b6e04d6fe3a715b48982fdc86c032bf52d638962 NewMemoryAwareScheduling: hide data structure behind wrapper class diff -r b6e04d6fe3a7 -r 1729072a893a graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Mon Nov 18 17:22:37 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Mon Nov 18 22:07:38 2013 +0100 @@ -175,24 +175,53 @@ } } - private class NewMemoryScheduleClosure extends BlockIteratorClosure> { + private class KillSet implements Iterable { + private final Set set; + + public KillSet() { + this.set = new HashSet<>(); + } + + public KillSet(KillSet other) { + this.set = new HashSet<>(other.set); + } + + public void add(LocationIdentity locationIdentity) { + set.add(locationIdentity); + } + + public void addAll(KillSet other) { + set.addAll(other.set); + } + + public Iterator iterator() { + return set.iterator(); + } + + public boolean isKilled(LocationIdentity locationIdentity) { + return set.contains(locationIdentity); + } + + } + + private class NewMemoryScheduleClosure extends BlockIteratorClosure { @Override - protected Set getInitialState() { + protected KillSet getInitialState() { return cloneState(blockToKillSet.get(getCFG().getStartBlock())); } @Override - protected Set processBlock(Block block, Set currentState) { + protected KillSet processBlock(Block block, KillSet currentState) { currentState.addAll(computeKillSet(block)); return currentState; } @Override - protected Set merge(Block merge, List> states) { + protected KillSet merge(Block merge, List states) { assert merge.getBeginNode() instanceof MergeNode; - Set initKillSet = new HashSet<>(); - for (Set state : states) { + KillSet initKillSet = new KillSet(); + for (KillSet state : states) { initKillSet.addAll(state); } @@ -200,16 +229,16 @@ } @Override - protected Set cloneState(Set state) { - return new HashSet<>(state); + protected KillSet cloneState(KillSet state) { + return new KillSet(state); } @Override - protected List> processLoop(Loop loop, Set state) { - LoopInfo> info = ReentrantBlockIterator.processLoop(this, loop, cloneState(state)); + protected List processLoop(Loop loop, KillSet state) { + LoopInfo info = ReentrantBlockIterator.processLoop(this, loop, cloneState(state)); assert loop.header.getBeginNode() instanceof LoopBeginNode; - Set headerState = merge(loop.header, info.endStates); + KillSet headerState = merge(loop.header, info.endStates); // second iteration, for propagating information to loop exits info = ReentrantBlockIterator.processLoop(this, loop, cloneState(headerState)); @@ -226,12 +255,12 @@ * @param block block to analyze * @return all killed locations */ - private Set computeKillSet(Block block) { - Set cachedSet = blockToKillSet.get(block); + private KillSet computeKillSet(Block block) { + KillSet cachedSet = blockToKillSet.get(block); if (cachedSet != null) { return cachedSet; } - HashSet set = new HashSet<>(); + KillSet set = new KillSet(); blockToKillSet.put(block, set); if (block.getBeginNode() instanceof MergeNode) { @@ -265,7 +294,7 @@ * Map from blocks to the nodes in each block. */ private BlockMap> blockToNodesMap; - private BlockMap> blockToKillSet; + private BlockMap blockToKillSet; private final Map> phantomUsages = new IdentityHashMap<>(); private final Map> phantomInputs = new IdentityHashMap<>(); private final SchedulingStrategy selectedStrategy; @@ -343,11 +372,11 @@ Debug.printf("post-dom: %s. ", b.getPostdominator()); Debug.printf("preds: %s. ", b.getPredecessors()); Debug.printf("succs: %s ====\n", b.getSuccessors()); - BlockMap> killMaps = blockToKillSet; - if (killMaps != null) { + BlockMap killSets = blockToKillSet; + if (killSets != null) { Debug.printf("X block kills: \n"); - if (killMaps.get(b) != null) { - for (LocationIdentity locId : killMaps.get(b)) { + if (killSets.get(b) != null) { + for (LocationIdentity locId : killSets.get(b)) { Debug.printf("X %s killed by %s\n", locId, "dunno anymore"); } } @@ -539,7 +568,7 @@ Stack path = computePathInDominatorTree(earliestBlock, latestBlock); Debug.printf("|path| is %d: %s\n", path.size(), path); - Set killSet = new HashSet<>(); + KillSet killSet = new KillSet(); // follow path, start at earliest schedule while (path.size() > 0) { Block currentBlock = path.pop(); @@ -551,11 +580,11 @@ HashSet region = computeRegion(currentBlock, dominatedBlock); Debug.printf("%s: region for %s -> %s: %s\n", n, currentBlock, dominatedBlock, region); - Map> states; - states = ReentrantBlockIterator.apply(maschedClosure, currentBlock, new HashSet<>(killSet), region); + Map states; + states = ReentrantBlockIterator.apply(maschedClosure, currentBlock, new KillSet(killSet), region); - Set mergeState = states.get(dominatedBlock.getBeginNode()); - if (mergeState.contains(locid)) { + KillSet mergeState = states.get(dominatedBlock.getBeginNode()); + if (mergeState.isKilled(locid)) { // location got killed somewhere in the branches, // thus we've to move the read above it return currentBlock; @@ -566,8 +595,8 @@ if (dominatedBlock == null) { return currentBlock; } - Set blockKills = computeKillSet(currentBlock); - if (blockKills.contains(locid)) { + KillSet blockKills = computeKillSet(currentBlock); + if (blockKills.isKilled(locid)) { return currentBlock; } killSet.addAll(blockKills);