Search in sources :

Example 81 with Register

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

the class VisitorNone method visitRMWXchg.

@Override
public List<Event> visitRMWXchg(RMWXchg e) {
    Register resultRegister = e.getResultRegister();
    String mo = e.getMo();
    IExpr address = e.getAddress();
    Register dummy = resultRegister;
    if (resultRegister == e.getMemValue()) {
        dummy = new Register(null, resultRegister.getThreadId(), resultRegister.getPrecision());
    }
    Fence optionalMbBefore = mo.equals(Tag.Linux.MO_MB) ? Linux.newMemoryBarrier() : null;
    Load load = newRMWLoad(dummy, address, Tag.Linux.loadMO(mo));
    Local optionalUpdateReg = dummy != resultRegister ? newLocal(resultRegister, dummy) : null;
    Fence optionalMbAfter = mo.equals(Tag.Linux.MO_MB) ? Linux.newMemoryBarrier() : null;
    return eventSequence(optionalMbBefore, load, newRMWStore(load, address, e.getMemValue(), Tag.Linux.storeMO(mo)), optionalUpdateReg, optionalMbAfter);
}
Also used : Register(com.dat3m.dartagnan.program.Register)

Example 82 with Register

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

the class EventCache method getRegWriterMap.

public ImmutableMap<Register, ImmutableList<Event>> getRegWriterMap() {
    if (regWriterMap == null) {
        Map<Register, List<Event>> regEventMap = new HashMap<>();
        List<Event> regWriters = getEvents(FilterBasic.get(Tag.REG_WRITER));
        for (Event e : regWriters) {
            Register register = ((RegWriter) e).getResultRegister();
            regEventMap.computeIfAbsent(register, key -> new ArrayList<>(regWriters.size())).add(e);
        }
        ImmutableMap.Builder<Register, ImmutableList<Event>> builder = new ImmutableMap.Builder<>();
        for (Register register : regEventMap.keySet()) {
            List<Event> list = regEventMap.get(register);
            Collections.sort(list);
            builder.put(register, ImmutableList.copyOf(list));
        }
        regWriterMap = builder.build();
    }
    return regWriterMap;
}
Also used : FilterAbstract(com.dat3m.dartagnan.program.filter.FilterAbstract) java.util(java.util) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Event(com.dat3m.dartagnan.program.event.core.Event) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) Event(com.dat3m.dartagnan.program.event.core.Event) ImmutableList(com.google.common.collect.ImmutableList)

Example 83 with Register

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

the class ProgramEncoder method dependencyEdge.

/**
 * @param writer
 * Overwrites some register.
 * @param reader
 * Happens on the same thread as {@code writer} and could use its value,
 * meaning that {@code writer} appears in {@code may(reader,R)} for some register {@code R}.
 * @param ctx
 * Builder of expressions and formulas.
 * @return
 * Proposition that {@code reader} directly uses the value from {@code writer}, if both are executed.
 * Contextualized with the result of {@link #encodeDependencies(SolverContext) encode}.
 */
public BooleanFormula dependencyEdge(Event writer, Event reader, SolverContext ctx) {
    Preconditions.checkArgument(writer instanceof RegWriter);
    Register register = ((RegWriter) writer).getResultRegister();
    Dependency.State r = dep.of(reader, register);
    Preconditions.checkArgument(r.may.contains(writer));
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    return r.must.contains(writer) ? execution(writer, reader, exec, ctx) : dependencyEdgeVariable(writer, reader, bmgr);
}
Also used : Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) Dependency(com.dat3m.dartagnan.program.analysis.Dependency)

Example 84 with Register

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

the class ProgramEncoder method encodeFinalRegisterValues.

public BooleanFormula encodeFinalRegisterValues(SolverContext ctx) {
    checkInitialized();
    logger.info("Encoding final register values");
    FormulaManager fmgr = ctx.getFormulaManager();
    BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    for (Map.Entry<Register, Dependency.State> e : dep.finalWriters().entrySet()) {
        Formula value = e.getKey().getLastValueExpr(ctx);
        Dependency.State state = e.getValue();
        List<Event> writers = state.may;
        if (initializeRegisters && !state.initialized) {
            BooleanFormula clause = generalEqualZero(value, ctx);
            for (Event w : writers) {
                clause = bmgr.or(clause, w.exec());
            }
            enc = bmgr.and(enc, clause);
        }
        for (int i = 0; i < writers.size(); i++) {
            Event writer = writers.get(i);
            BooleanFormula clause = bmgr.or(generalEqual(value, ((RegWriter) writer).getResultRegisterExpr(), ctx), bmgr.not(writer.exec()));
            for (Event w : writers.subList(i + 1, writers.size())) {
                if (!exec.areMutuallyExclusive(writer, w)) {
                    clause = bmgr.or(clause, w.exec());
                }
            }
            enc = bmgr.and(enc, clause);
        }
    }
    return enc;
}
Also used : Dependency(com.dat3m.dartagnan.program.analysis.Dependency) 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)

Example 85 with Register

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

the class VisitorLitmusC method visitReCast.

@Override
public ExprInterface visitReCast(LitmusCParser.ReCastContext ctx) {
    Register register = getReturnRegister(false);
    ExprInterface result = (ExprInterface) ctx.re().accept(this);
    return assignToReturnRegister(register, result);
}
Also used : Register(com.dat3m.dartagnan.program.Register)

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