Search in sources :

Example 1 with Thread

use of com.dat3m.dartagnan.program.Thread 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 2 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class ProgramEncoder method encodeControlFlow.

public BooleanFormula encodeControlFlow(SolverContext ctx) {
    checkInitialized();
    logger.info("Encoding program control flow");
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    for (Thread t : program.getThreads()) {
        enc = bmgr.and(enc, encodeThreadCF(t, ctx));
    }
    return enc;
}
Also used : Thread(com.dat3m.dartagnan.program.Thread)

Example 3 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class SymmetryEncoder method encodeSymmetryClass.

public BooleanFormula encodeSymmetryClass(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    if (rel == null || symmClass.getEquivalence() != symm) {
        return enc;
    }
    Thread rep = symmClass.getRepresentative();
    List<Thread> symmThreads = new ArrayList<>(symmClass);
    symmThreads.sort(Comparator.comparingInt(Thread::getId));
    // ===== Construct row =====
    // IMPORTANT: Each thread writes to its own special location for the purpose of starting/terminating threads
    // These need to get skipped.
    Thread t1 = symmThreads.get(0);
    List<Tuple> r1Tuples = new ArrayList<>();
    for (Tuple t : rel.getMaxTupleSet()) {
        Event a = t.getFirst();
        Event b = t.getSecond();
        if (!a.is(Tag.C11.PTHREAD) && !b.is(Tag.C11.PTHREAD) && a.getThread() == t1) {
            r1Tuples.add(t);
        }
    }
    sort(r1Tuples);
    // Construct symmetric rows
    for (int i = 1; i < symmThreads.size(); i++) {
        Thread t2 = symmThreads.get(i);
        Function<Event, Event> p = symm.createTransposition(t1, t2);
        List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
        List<BooleanFormula> r1 = Lists.transform(r1Tuples, t -> rel.getSMTVar(t, ctx));
        List<BooleanFormula> r2 = Lists.transform(r2Tuples, t -> rel.getSMTVar(t, ctx));
        final String id = "_" + rep.getId() + "_" + i;
        // r1 >= r2
        enc = bmgr.and(enc, encodeLexLeader(id, r2, r1, ctx));
        t1 = t2;
        r1Tuples = r2Tuples;
    }
    return enc;
}
Also used : Options(org.sosy_lab.common.configuration.Options) java.util(java.util) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Thread(com.dat3m.dartagnan.program.Thread) Function(java.util.function.Function) RelationRepository(com.dat3m.dartagnan.wmm.utils.RelationRepository) BREAK_SYMMETRY_BY_SYNC_DEGREE(com.dat3m.dartagnan.configuration.OptionNames.BREAK_SYMMETRY_BY_SYNC_DEGREE) Wmm(com.dat3m.dartagnan.wmm.Wmm) Lists(com.google.common.collect.Lists) Option(org.sosy_lab.common.configuration.Option) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) BREAK_SYMMETRY_ON_RELATION(com.dat3m.dartagnan.configuration.OptionNames.BREAK_SYMMETRY_ON_RELATION) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) Configuration(org.sosy_lab.common.configuration.Configuration) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Collectors(java.util.stream.Collectors) Tag(com.dat3m.dartagnan.program.event.Tag) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Context(com.dat3m.dartagnan.verification.Context) RelationNameRepository(com.dat3m.dartagnan.wmm.relation.RelationNameRepository) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) LogManager(org.apache.logging.log4j.LogManager) Axiom(com.dat3m.dartagnan.wmm.axiom.Axiom) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Thread(com.dat3m.dartagnan.program.Thread) Event(com.dat3m.dartagnan.program.event.core.Event) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 4 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class VerificationTask method performStaticProgramAnalyses.

public void performStaticProgramAnalyses() throws InvalidConfigurationException {
    analysisContext.register(BranchEquivalence.class, BranchEquivalence.fromConfig(program, config));
    analysisContext.register(ExecutionAnalysis.class, ExecutionAnalysis.fromConfig(program, analysisContext, config));
    analysisContext.register(Dependency.class, Dependency.fromConfig(program, analysisContext, config));
    analysisContext.register(AliasAnalysis.class, AliasAnalysis.fromConfig(program, config));
    analysisContext.register(ThreadSymmetry.class, ThreadSymmetry.fromConfig(program, config));
    for (Thread thread : program.getThreads()) {
        for (Event e : thread.getEvents()) {
            // Some events perform static analyses by themselves (e.g. Svcomp's EndAtomic)
            // which may rely on previous "global" analyses
            e.runLocalAnalysis(program, analysisContext);
        }
    }
}
Also used : Event(com.dat3m.dartagnan.program.event.core.Event) Thread(com.dat3m.dartagnan.program.Thread)

Example 5 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class Printer method print.

public String print(Program program) {
    result = new StringBuilder();
    padding = new StringBuilder(paddingBase);
    IDType origType = idType;
    idType = resolveIDType(program);
    String name = program.getName();
    if (name == null) {
        name = "program";
    }
    result.append(name).append("\n");
    for (Thread thread : program.getThreads()) {
        if (shouldPrintThread(thread)) {
            appendThread(thread);
        }
    }
    idType = origType;
    return result.toString();
}
Also used : Thread(com.dat3m.dartagnan.program.Thread)

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