Search in sources :

Example 1 with CondJump

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));
}
Also used : ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) Test(org.junit.Test)

Example 2 with CondJump

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);
}
Also used : Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) CondJump(com.dat3m.dartagnan.program.event.core.CondJump)

Example 3 with CondJump

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;
}
Also used : Options(org.sosy_lab.common.configuration.Options) java.util(java.util) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Memory(com.dat3m.dartagnan.program.memory.Memory) BiFunction(java.util.function.BiFunction) Thread(com.dat3m.dartagnan.program.Thread) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) Option(org.sosy_lab.common.configuration.Option) Dependency(com.dat3m.dartagnan.program.analysis.Dependency) Program(com.dat3m.dartagnan.program.Program) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) Configuration(org.sosy_lab.common.configuration.Configuration) Utils.generalEqualZero(com.dat3m.dartagnan.expression.utils.Utils.generalEqualZero) org.sosy_lab.java_smt.api(org.sosy_lab.java_smt.api) OptionNames(com.dat3m.dartagnan.configuration.OptionNames) ARCH_PRECISION(com.dat3m.dartagnan.GlobalSettings.ARCH_PRECISION) BranchEquivalence(com.dat3m.dartagnan.program.analysis.BranchEquivalence) Label(com.dat3m.dartagnan.program.event.core.Label) Context(com.dat3m.dartagnan.verification.Context) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) Lists.reverse(com.google.common.collect.Lists.reverse) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) LogManager(org.apache.logging.log4j.LogManager) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) CondJump(com.dat3m.dartagnan.program.event.core.CondJump)

Example 4 with CondJump

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();
}
Also used : LoopEnd(com.dat3m.dartagnan.program.event.lang.svcomp.LoopEnd) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) CondJump(com.dat3m.dartagnan.program.event.core.CondJump)

Example 5 with CondJump

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;
}
Also used : BExprUn(com.dat3m.dartagnan.expression.BExprUn) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) Atom(com.dat3m.dartagnan.expression.Atom)

Aggregations

CondJump (com.dat3m.dartagnan.program.event.core.CondJump)14 Event (com.dat3m.dartagnan.program.event.core.Event)10 Label (com.dat3m.dartagnan.program.event.core.Label)9 Program (com.dat3m.dartagnan.program.Program)4 Thread (com.dat3m.dartagnan.program.Thread)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)3 Preconditions (com.google.common.base.Preconditions)3 HashMap (java.util.HashMap)3 Configuration (org.sosy_lab.common.configuration.Configuration)3 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)3 Atom (com.dat3m.dartagnan.expression.Atom)2 BExprUn (com.dat3m.dartagnan.expression.BExprUn)2 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)2 Register (com.dat3m.dartagnan.program.Register)2 Tag (com.dat3m.dartagnan.program.event.Tag)2 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)2 Context (com.dat3m.dartagnan.verification.Context)2 java.util (java.util)2