use of com.dat3m.dartagnan.program.event.core.CondJump in project Dat3M by hernanponcedeleon.
the class ExceptionsTest method JumpWithNullLabel.
@Test(expected = NullPointerException.class)
public void JumpWithNullLabel() throws Exception {
ProgramBuilder pb = new ProgramBuilder();
pb.initThread(0);
// Label cannot be null
pb.addChild(0, new CondJump(BConst.FALSE, null));
}
use of com.dat3m.dartagnan.program.event.core.CondJump in project Dat3M by hernanponcedeleon.
the class LoopUnrolling method unrollThreadOnce.
private void unrollThreadOnce(Thread t, int bound) {
// NOTE: The implemented unroll semantics are identical to the previous one we had.
// TODO: We might want to allow usage of different bounds per loop by e.g.
// annotating the looping jump with a custom bound counter
// TODO (2): The code can surely be cleaned up somehow
Event cur = t.getEntry();
Event successor;
Event predecessor = null;
Event newPred;
do {
successor = cur.getSuccessor();
if (cur instanceof CondJump && ((CondJump) cur).getLabel().getOId() < cur.getOId()) {
CondJump jump = (CondJump) cur;
Label label = jump.getLabel();
if (bound > 1) {
predecessor = copyPath(label, successor, predecessor);
}
if (bound == 1) {
Label target = (Label) jump.getThread().getExit();
newPred = EventFactory.newGoto(target);
newPred.addFilters(Tag.BOUND);
predecessor.setSuccessor(newPred);
} else {
newPred = predecessor;
}
} else {
newPred = cur;
if (predecessor != null) {
// TODO: Is this needed anymore since we got rid of If events?
if (bound != 1) {
newPred = cur.getCopy();
}
predecessor.setSuccessor(newPred);
}
}
cur = successor;
predecessor = newPred;
} while (successor != null);
}
use of com.dat3m.dartagnan.program.event.core.CondJump in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeThreadCF.
private BooleanFormula encodeThreadCF(Thread thread, SolverContext ctx) {
checkInitialized();
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
BiFunction<BooleanFormula, BooleanFormula, BooleanFormula> cfEncoder = shouldAllowPartialExecutions ? bmgr::implication : bmgr::equivalence;
Map<Label, Set<Event>> labelJumpMap = new HashMap<>();
Event pred = null;
for (Event e : thread.getEntry().getSuccessors()) {
// Immediate control flow
BooleanFormula cfCond = pred == null ? bmgr.makeTrue() : pred.cf();
if (pred instanceof CondJump) {
CondJump jump = (CondJump) pred;
cfCond = bmgr.and(cfCond, bmgr.not(jump.getGuard().toBoolFormula(jump, ctx)));
// NOTE: we need to register the actual jumps here, because the
// listener sets of labels is too large (it contains old copies)
labelJumpMap.computeIfAbsent(jump.getLabel(), key -> new HashSet<>()).add(jump);
}
// Control flow via jumps
if (e instanceof Label) {
for (Event jump : labelJumpMap.getOrDefault(e, Collections.emptySet())) {
CondJump j = (CondJump) jump;
cfCond = bmgr.or(cfCond, bmgr.and(j.cf(), j.getGuard().toBoolFormula(j, ctx)));
}
}
enc = bmgr.and(enc, cfEncoder.apply(e.cf(), cfCond), e.encodeExec(ctx));
pred = e;
}
return enc;
}
use of com.dat3m.dartagnan.program.event.core.CondJump 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.CondJump in project Dat3M by hernanponcedeleon.
the class RemoveDeadCondJumps method mutuallyExclusiveIfs.
private boolean mutuallyExclusiveIfs(CondJump jump, Event e) {
if (!(e instanceof CondJump)) {
return false;
}
CondJump jump2 = (CondJump) e;
if (jump.getGuard() instanceof BExprUn && ((BExprUn) jump.getGuard()).getInner().equals(jump2.getGuard()) || jump2.getGuard() instanceof BExprUn && ((BExprUn) jump2.getGuard()).getInner().equals(jump.getGuard())) {
return true;
}
if (jump.getGuard() instanceof Atom && jump2.getGuard() instanceof Atom) {
Atom a1 = (Atom) jump.getGuard();
Atom a2 = (Atom) jump2.getGuard();
return a1.getOp().inverted() == a2.getOp() && a1.getLHS().equals(a2.getLHS()) && a1.getRHS().equals(a2.getRHS());
}
return false;
}
Aggregations