use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class FindSpinLoops method run.
@Override
public void run(Program program) {
Preconditions.checkArgument(!program.isUnrolled(), getClass().getSimpleName() + " should be performed before unrolling.");
for (Thread thread : program.getThreads()) {
markAnnotatedSpinLoops(thread);
detectAndMarkSpinLoops(thread);
}
program.clearCache(false);
logger.info("# of spinloops: {}", spinloops);
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class RemoveDeadCondJumps method run.
@Override
public void run(Program program) {
Preconditions.checkArgument(program.isUnrolled(), "The program needs to be unrolled before performing " + getClass().getSimpleName());
logger.info(String.format("#Events before %s: %s", getClass().getSimpleName(), +program.getEvents().size()));
for (Thread t : program.getThreads()) {
eliminateDeadCondJumps(t);
t.clearCache();
}
program.clearCache(false);
logger.info(String.format("#Events after %s: %s", getClass().getSimpleName(), +program.getEvents().size()));
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class RemoveDeadCondJumps method eliminateDeadCondJumps.
private void eliminateDeadCondJumps(Thread thread) {
Map<Event, List<Event>> immediateLabelPredecessors = new HashMap<>();
List<Event> removed = new ArrayList<>();
Event pred = thread.getEntry();
Event current = pred.getSuccessor();
// We fill the map of predecessors
while (current != null) {
if (current instanceof CondJump) {
CondJump jump = (CondJump) current;
// After constant propagation some jumps have False as condition and are dead
if (jump.isDead()) {
removed.add(jump);
} else {
immediateLabelPredecessors.computeIfAbsent(jump.getLabel(), key -> new ArrayList<>()).add(jump);
}
} else if (current instanceof Label && !(pred instanceof CondJump && ((CondJump) pred).isGoto())) {
immediateLabelPredecessors.computeIfAbsent(current, key -> new ArrayList<>()).add(pred);
}
pred = current;
current = current.getSuccessor();
}
// We check which ifs can be removed
for (Event label : immediateLabelPredecessors.keySet()) {
Event next = label.getSuccessor();
List<Event> preds = immediateLabelPredecessors.get(label);
// BOUND events
if (next instanceof CondJump && preds.stream().allMatch(e -> mutuallyExclusiveIfs((CondJump) next, e))) {
removed.add(next);
}
// SPINLOOP events
if (next != null && preds.size() == 1 && preds.get(0).getSuccessor().equals(label)) {
removed.add(label);
}
}
// Here is the actual removal
pred = null;
Event cur = thread.getEntry();
boolean dead = false;
while (cur != null) {
if (dead && cur instanceof Label && !immediateLabelPredecessors.getOrDefault(cur, List.of()).isEmpty()) {
dead = false;
}
if (dead && cur instanceof CondJump && immediateLabelPredecessors.containsKey(((CondJump) cur).getLabel())) {
immediateLabelPredecessors.get(((CondJump) cur).getLabel()).remove(cur);
}
if (dead && immediateLabelPredecessors.containsKey(cur.getSuccessor())) {
immediateLabelPredecessors.get(cur.getSuccessor()).remove(cur);
}
if ((dead || removed.contains(cur)) && !cur.is(Tag.NOOPT)) {
cur.delete();
cur = pred;
}
if (cur instanceof CondJump && ((CondJump) cur).isGoto()) {
dead = true;
}
pred = cur;
cur = cur.getSuccessor();
}
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class SymmetryReduction method run.
public void run(Program program) {
ThreadSymmetry symm = ThreadSymmetry.withoutMappings(program);
Set<? extends EquivalenceClass<Thread>> symmClasses = symm.getNonTrivialClasses();
if (symmClasses.isEmpty()) {
return;
}
for (EquivalenceClass<Thread> c : symmClasses) {
Thread rep = c.getRepresentative();
if (rep.getEvents().stream().noneMatch(x -> x.is(Tag.ASSERTION))) {
continue;
}
rep.setName(rep.getName() + "__symm_unique");
for (Thread t : c.stream().filter(x -> x != rep).collect(Collectors.toList())) {
for (Event e : t.getEvents()) {
if (e.is(Tag.ASSERTION)) {
e.getSuccessor().delete();
e.delete();
}
}
t.clearCache();
}
}
logger.info("Reduced symmetry of {} many symmetry classes", symmClasses.size());
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class Compilation method run.
@Override
public void run(Program program) {
if (program.isCompiled()) {
logger.warn("Skipped compilation: Program is already compiled to {}", program.getArch());
return;
}
Preconditions.checkArgument(program.isUnrolled(), "The program needs to be unrolled before compilation.");
EventVisitor<List<Event>> visitor;
switch(target) {
case C11:
visitor = new VisitorC11();
break;
case LKMM:
visitor = new VisitorLKMM();
break;
case TSO:
visitor = new VisitorTso();
break;
case POWER:
visitor = new VisitorPower();
break;
case ARM8:
visitor = new VisitorArm8();
break;
case IMM:
visitor = new VisitorIMM();
break;
default:
throw new UnsupportedOperationException(String.format("Compilation to %s is not supported.", target));
}
int nextId = 0;
for (Thread thread : program.getThreads()) {
nextId = compileThread(thread, nextId, visitor);
int fId = 0;
for (Event e : thread.getEvents()) {
e.setFId(fId++);
}
}
program.setArch(target);
program.clearCache(false);
program.markAsCompiled();
logger.info("Program compiled to {}", target);
if (print) {
System.out.println("===== Program after compilation =====");
System.out.println(new Printer().print(program));
System.out.println("=====================================");
}
}
Aggregations