Search in sources :

Example 36 with Thread

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

Example 37 with Thread

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

Example 38 with Thread

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();
    }
}
Also used : Atom(com.dat3m.dartagnan.expression.Atom) Configuration(org.sosy_lab.common.configuration.Configuration) HashMap(java.util.HashMap) Thread(com.dat3m.dartagnan.program.Thread) Label(com.dat3m.dartagnan.program.event.core.Label) ArrayList(java.util.ArrayList) Tag(com.dat3m.dartagnan.program.event.Tag) List(java.util.List) Logger(org.apache.logging.log4j.Logger) BExprUn(com.dat3m.dartagnan.expression.BExprUn) Map(java.util.Map) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) LogManager(org.apache.logging.log4j.LogManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) ArrayList(java.util.ArrayList) List(java.util.List) CondJump(com.dat3m.dartagnan.program.event.core.CondJump)

Example 39 with Thread

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());
}
Also used : Tag(com.dat3m.dartagnan.program.event.Tag) EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Logger(org.apache.logging.log4j.Logger) Configuration(org.sosy_lab.common.configuration.Configuration) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) Set(java.util.Set) Thread(com.dat3m.dartagnan.program.Thread) LogManager(org.apache.logging.log4j.LogManager) Collectors(java.util.stream.Collectors) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Event(com.dat3m.dartagnan.program.event.core.Event) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Thread(com.dat3m.dartagnan.program.Thread)

Example 40 with Thread

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("=====================================");
    }
}
Also used : Printer(com.dat3m.dartagnan.utils.printer.Printer) Thread(com.dat3m.dartagnan.program.Thread) Event(com.dat3m.dartagnan.program.event.core.Event) List(java.util.List)

Aggregations

Thread (com.dat3m.dartagnan.program.Thread)48 Event (com.dat3m.dartagnan.program.event.core.Event)27 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)13 TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)11 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)9 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)9 Program (com.dat3m.dartagnan.program.Program)8 Tag (com.dat3m.dartagnan.program.event.Tag)8 Configuration (org.sosy_lab.common.configuration.Configuration)8 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)8 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)7 Collectors (java.util.stream.Collectors)7 Context (com.dat3m.dartagnan.verification.Context)6 Preconditions (com.google.common.base.Preconditions)6 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)5 Options (org.sosy_lab.common.configuration.Options)5 Utils.generalEqual (com.dat3m.dartagnan.expression.utils.Utils.generalEqual)4 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)4