Search in sources :

Example 41 with Event

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

Example 42 with Event

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();
}
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 43 with Event

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;
}
Also used : Register(com.dat3m.dartagnan.program.Register) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) RegReaderData(com.dat3m.dartagnan.program.event.core.utils.RegReaderData) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) HashSet(java.util.HashSet)

Example 44 with Event

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

Example 45 with Event

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

Aggregations

Event (com.dat3m.dartagnan.program.event.core.Event)104 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)34 Thread (com.dat3m.dartagnan.program.Thread)32 Register (com.dat3m.dartagnan.program.Register)25 TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)25 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)20 Tag (com.dat3m.dartagnan.program.event.Tag)16 Label (com.dat3m.dartagnan.program.event.core.Label)16 Collectors (java.util.stream.Collectors)16 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)16 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)16 LogManager (org.apache.logging.log4j.LogManager)15 Logger (org.apache.logging.log4j.Logger)15 Program (com.dat3m.dartagnan.program.Program)12 ExecutionAnalysis (com.dat3m.dartagnan.program.analysis.ExecutionAnalysis)12 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)12 java.util (java.util)12 SolverContext (org.sosy_lab.java_smt.api.SolverContext)12 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)11 CondJump (com.dat3m.dartagnan.program.event.core.CondJump)10