-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve dynamic pure loop cutting (#619)
* Added new DominatorTree class. Added simple DominatorAnalysis with static helper methods. Simplified DynamicPureLoopCutting using new dominator trees. * Reworked DynamicPureLoopCutting to run on proper loops. It now instruments the code without using ExecutionStatus. * - Merged DynamicPureLoopCutting.java and SimpleSpinLoopDetection.java into a single new pass: DynamicSpinLoopDetection. - Renamed OptionNames accordingly.
- Loading branch information
1 parent
fa3122c
commit bf457e3
Showing
8 changed files
with
483 additions
and
495 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
54 changes: 54 additions & 0 deletions
54
dartagnan/src/main/java/com/dat3m/dartagnan/program/analysis/DominatorAnalysis.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,54 @@ | ||
package com.dat3m.dartagnan.program.analysis; | ||
|
||
import com.dat3m.dartagnan.program.IRHelper; | ||
import com.dat3m.dartagnan.program.event.Event; | ||
import com.dat3m.dartagnan.program.event.core.CondJump; | ||
import com.dat3m.dartagnan.program.event.core.Label; | ||
import com.dat3m.dartagnan.utils.DominatorTree; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Sets; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class DominatorAnalysis { | ||
|
||
public static DominatorTree<Event> computePreDominatorTree(Event from, Event to) { | ||
Preconditions.checkArgument(from.getFunction() == to.getFunction(), | ||
"Cannot compute dominator tree between events of different functions."); | ||
final Predicate<Event> isInRange = (e -> from.getGlobalId() <= e.getGlobalId() && e.getGlobalId() <= to.getGlobalId()); | ||
return new DominatorTree<>(from, e -> Iterables.filter(getSuccessors(e), isInRange)); | ||
} | ||
|
||
public static DominatorTree<Event> computePostDominatorTree(Event from, Event to) { | ||
Preconditions.checkArgument(from.getFunction() == to.getFunction(), | ||
"Cannot compute dominator tree between events of different functions."); | ||
final Predicate<Event> isInRange = (e -> from.getGlobalId() <= e.getGlobalId() && e.getGlobalId() <= to.getGlobalId()); | ||
return new DominatorTree<>(to, e -> Iterables.filter(getPredecessors(e), isInRange)); | ||
} | ||
|
||
// ============================================================================================================== | ||
// Internals | ||
|
||
private static Iterable<? extends Event> getSuccessors(Event e) { | ||
final boolean hasSucc = (e.getSuccessor() != null && !IRHelper.isAlwaysBranching(e)); | ||
if (e instanceof CondJump jump) { | ||
return hasSucc ? List.of(jump.getSuccessor(), jump.getLabel()) : List.of(jump.getLabel()); | ||
} else { | ||
return hasSucc ? List.of(e.getSuccessor()) : List.of(); | ||
} | ||
} | ||
|
||
private static Iterable<? extends Event> getPredecessors(Event e) { | ||
final boolean hasPred = (e.getPredecessor() != null && !IRHelper.isAlwaysBranching(e.getPredecessor())); | ||
if (e instanceof Label label) { | ||
return hasPred ? Sets.union(label.getJumpSet(), Set.of(e.getPredecessor())) : label.getJumpSet(); | ||
} else { | ||
return hasPred ? List.of(e.getPredecessor()) : List.of(); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.