Search in sources :

Example 11 with Register

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

the class VisitorNone method visitRMWAddUnless.

@Override
public List<Event> visitRMWAddUnless(RMWAddUnless e) {
    Register resultRegister = e.getResultRegister();
    Register dummy = new Register(null, resultRegister.getThreadId(), resultRegister.getPrecision());
    RMWReadCondUnless load = Linux.newRMWReadCondUnless(dummy, e.getCmp(), e.getAddress(), Tag.Linux.MO_RELAXED);
    return eventSequence(Linux.newConditionalMemoryBarrier(load), load, Linux.newRMWStoreCond(load, e.getAddress(), new IExprBin(dummy, IOpBin.PLUS, (IExpr) e.getMemValue()), Tag.Linux.MO_RELAXED), newLocal(resultRegister, new Atom(dummy, NEQ, e.getCmp())), Linux.newConditionalMemoryBarrier(load));
}
Also used : Register(com.dat3m.dartagnan.program.Register) RMWReadCondUnless(com.dat3m.dartagnan.program.event.lang.linux.cond.RMWReadCondUnless)

Example 12 with Register

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

the class VisitorNone method visitJoin.

@Override
public List<Event> visitJoin(Join e) {
    Register resultRegister = e.getResultRegister();
    Load load = newLoad(resultRegister, e.getAddress(), e.getMo());
    load.addFilters(C11.PTHREAD);
    return eventSequence(load, newJumpUnless(new Atom(resultRegister, EQ, IValue.ZERO), e.getLabel()));
}
Also used : Register(com.dat3m.dartagnan.program.Register)

Example 13 with Register

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

the class VisitorNone method visitRMWOp.

@Override
public List<Event> visitRMWOp(RMWOp e) {
    IExpr address = e.getAddress();
    Register resultRegister = e.getResultRegister();
    Load load = newRMWLoad(resultRegister, address, Tag.Linux.MO_RELAXED);
    load.addFilters(Tag.Linux.NORETURN);
    return eventSequence(load, newRMWStore(load, address, new IExprBin(resultRegister, e.getOp(), (IExpr) e.getMemValue()), Tag.Linux.MO_RELAXED));
}
Also used : Register(com.dat3m.dartagnan.program.Register)

Example 14 with Register

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

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

the class ProgramEncoder method encodeDependencies.

/**
 * @param ctx
 * Builder of expressions and formulas.
 * @return
 * Describes that for each pair of events, if the reader uses the result of the writer,
 * then the value the reader gets from the register is exactly the value that the writer computed.
 * Also, the reader may only use the value of the latest writer that is executed.
 * Also, if no fitting writer is executed, the reader uses 0.
 */
public BooleanFormula encodeDependencies(SolverContext ctx) {
    logger.info("Encoding dependencies");
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    for (Map.Entry<Event, Map<Register, Dependency.State>> e : dep.getAll()) {
        Event reader = e.getKey();
        for (Map.Entry<Register, Dependency.State> r : e.getValue().entrySet()) {
            Formula value = r.getKey().toIntFormula(reader, ctx);
            Dependency.State state = r.getValue();
            BooleanFormula overwrite = bmgr.makeFalse();
            for (Event writer : reverse(state.may)) {
                assert writer instanceof RegWriter;
                BooleanFormula edge;
                if (state.must.contains(writer)) {
                    edge = writer.exec();
                } else {
                    edge = dependencyEdgeVariable(writer, reader, bmgr);
                    enc = bmgr.and(enc, bmgr.equivalence(edge, bmgr.and(writer.exec(), reader.cf(), bmgr.not(overwrite))));
                }
                enc = bmgr.and(enc, bmgr.implication(edge, generalEqual(value, ((RegWriter) writer).getResultRegisterExpr(), ctx)));
                overwrite = bmgr.or(overwrite, writer.exec());
            }
            if (initializeRegisters && !state.initialized) {
                enc = bmgr.and(enc, bmgr.or(overwrite, bmgr.not(reader.cf()), generalEqualZero(value, ctx)));
            }
        }
    }
    return enc;
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) Event(com.dat3m.dartagnan.program.event.core.Event) Dependency(com.dat3m.dartagnan.program.analysis.Dependency)

Aggregations

Register (com.dat3m.dartagnan.program.Register)154 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)29 Event (com.dat3m.dartagnan.program.event.core.Event)25 IExpr (com.dat3m.dartagnan.expression.IExpr)16 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)15 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)13 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)12 Label (com.dat3m.dartagnan.program.event.core.Label)11 ParsingException (com.dat3m.dartagnan.exception.ParsingException)10 BigInteger (java.math.BigInteger)8 IConst (com.dat3m.dartagnan.expression.IConst)7 IExprBin (com.dat3m.dartagnan.expression.IExprBin)6 IValue (com.dat3m.dartagnan.expression.IValue)6 IOpBin (com.dat3m.dartagnan.expression.op.IOpBin)6 Program (com.dat3m.dartagnan.program.Program)6 Dependency (com.dat3m.dartagnan.program.analysis.Dependency)6 ExprInterface (com.dat3m.dartagnan.expression.ExprInterface)5 Thread (com.dat3m.dartagnan.program.Thread)5 java.util (java.util)5 Atom (com.dat3m.dartagnan.expression.Atom)4