use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class VisitorLitmusAArch64 method visitBranch.
@Override
public Object visitBranch(LitmusAArch64Parser.BranchContext ctx) {
Label label = programBuilder.getOrCreateLabel(ctx.label().getText());
if (ctx.branchCondition() == null) {
return programBuilder.addChild(mainThread, EventFactory.newGoto(label));
}
Event lastEvent = programBuilder.getLastEvent(mainThread);
if (!(lastEvent instanceof Cmp)) {
throw new ParsingException("Invalid syntax near " + ctx.getText());
}
Cmp cmp = (Cmp) lastEvent;
Atom expr = new Atom(cmp.getLeft(), ctx.branchCondition().op, cmp.getRight());
return programBuilder.addChild(mainThread, EventFactory.newJump(expr, label));
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class FindSpinLoops method markAnnotatedSpinLoops.
private void markAnnotatedSpinLoops(Thread t) {
Event pred = t.getEntry();
Event curr = pred.getSuccessor();
while (curr != null) {
if (curr instanceof LoopEnd) {
// This assume the following implementation of await_while
// #define await_while(cond) \
// for (int tmp = (__VERIFIER_loop_begin(), 0); __VERIFIER_spin_start(), \
// tmp = cond, __VERIFIER_spin_end(!tmp), tmp;)
Event spinloop = curr.getSuccessors().stream().filter(e -> e instanceof CondJump && ((CondJump) e).isGoto()).findFirst().get();
spinloop.addFilters(Tag.SPINLOOP, Tag.NOOPT);
((CondJump) spinloop).getLabel().addFilters(Tag.SPINLOOP, Tag.NOOPT);
spinloops++;
}
curr = curr.getSuccessor();
}
t.clearCache();
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class FindSpinLoops method isSideEffectFree.
private boolean isSideEffectFree(Label loopBegin, CondJump loopEnd) {
Event cur = loopBegin.getSuccessor();
// Unsafe means the loop read from the registers before writing to them.
Set<Register> unsafeRegisters = new HashSet<>();
// Safe means the loop wrote to these register before using them
Set<Register> safeRegisters = new HashSet<>();
while (cur != loopEnd) {
if (cur instanceof MemEvent) {
if (cur.is(Tag.WRITE)) {
// Writes always cause side effects
return false;
}
MemEvent memEvent = (MemEvent) cur;
Set<Register> addrRegs = memEvent.getAddress().getRegs();
unsafeRegisters.addAll(Sets.difference(addrRegs, safeRegisters));
}
if (cur instanceof RegReaderData) {
RegReaderData reader = (RegReaderData) cur;
Set<Register> dataRegs = reader.getDataRegs();
unsafeRegisters.addAll(Sets.difference(dataRegs, safeRegisters));
}
if (cur instanceof RegWriter) {
RegWriter writer = (RegWriter) cur;
if (unsafeRegisters.contains(writer.getResultRegister())) {
return false;
} else {
safeRegisters.add(writer.getResultRegister());
}
}
cur = cur.getSuccessor();
}
return true;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class LoopUnrolling method copyPath.
private List<Event> copyPath(Event from, Event until, Map<Event, Event> copyContext) {
List<Event> copies = new ArrayList<>();
Event cur = from;
while (cur != null && !cur.equals(until)) {
Event copy = cur.getCopy();
copies.add(copy);
copyContext.put(cur, copy);
cur = cur.getSuccessor();
}
Event pred = null;
for (Event e : copies) {
e.setPredecessor(pred);
e.updateReferences(copyContext);
pred = e;
}
return copies;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class BranchEquivalence method computeExclusiveClasses.
// ========================== Equivalence class computations =========================
private void computeExclusiveClasses(Map<Thread, Map<Event, Branch>> threadBranches) {
for (Thread t : program.getThreads()) {
computeReachableBranches(threadBranches.get(t).get(t.getEntry()));
}
Set<BranchClass> branchClasses = getAllTypedEqClasses();
for (BranchClass c1 : branchClasses) {
Set<BranchClass> excl = c1.exclusiveClasses;
if (c1 == initialClass) {
if (!unreachableClass.isEmpty()) {
excl.add(unreachableClass);
}
continue;
} else if (c1 == unreachableClass) {
excl.addAll(branchClasses);
excl.remove(unreachableClass);
continue;
}
for (BranchClass c2 : branchClasses) {
if (c2 == unreachableClass) {
excl.add(unreachableClass);
continue;
} else if (c2 == initialClass || c2 == c1) {
continue;
}
Event e1 = c1.getRepresentative();
Event e2 = c2.getRepresentative();
if (e1.getThread() == e2.getThread() && e1.getCId() < e2.getCId()) {
if (!c1.reachableClasses.contains(c2)) {
excl.add(c2);
c2.exclusiveClasses.add(c1);
}
}
}
}
}
Aggregations