Search in sources :

Example 6 with RegWriter

use of com.dat3m.dartagnan.program.event.core.utils.RegWriter in project Dat3M by hernanponcedeleon.

the class BasicRegRelation method doEncodeApprox.

BooleanFormula doEncodeApprox(Collection<Event> regReaders, SolverContext ctx) {
    FormulaManager fmgr = ctx.getFormulaManager();
    BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
    for (Event regReader : regReaders) {
        Set<Tuple> writerReaders = maxTupleSet.getBySecond(regReader);
        for (Register register : getRegisters(regReader)) {
            List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
            List<Event> possibleWriters = writers.stream().filter(x -> writerReaders.contains(new Tuple(x, regReader))).collect(Collectors.toList());
            if (writers.isEmpty() || writers.get(0).getCId() >= regReader.getCId()) {
                BooleanFormula equal = generalEqual(register.toIntFormula(regReader, ctx), new IValue(BigInteger.ZERO, register.getPrecision()).toIntFormula(ctx), ctx);
                enc = bmgr.and(enc, equal);
            } else {
                for (int i = 0; i < possibleWriters.size(); i++) {
                    Event regWriter = possibleWriters.get(i);
                    // RegReader uses the value of RegWriter if it is executed ..
                    BooleanFormula clause = getExecPair(regWriter, regReader, ctx);
                    BooleanFormula edge = this.getSMTVar(regWriter, regReader, ctx);
                    // .. and no other write to the same register is executed in between
                    for (int j = i + 1; j < possibleWriters.size(); j++) {
                        clause = bmgr.and(clause, bmgr.not(possibleWriters.get(j).exec()));
                    }
                    // Encode edge and value binding
                    enc = bmgr.and(enc, bmgr.equivalence(edge, clause));
                    BooleanFormula equal = generalEqual(((RegWriter) regWriter).getResultRegisterExpr(), register.toIntFormula(regReader, ctx), ctx);
                    enc = bmgr.and(enc, bmgr.implication(edge, equal));
                }
            }
        }
    }
    return enc;
}
Also used : FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Collection(java.util.Collection) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Set(java.util.Set) Collectors(java.util.stream.Collectors) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) SolverContext(org.sosy_lab.java_smt.api.SolverContext) IValue(com.dat3m.dartagnan.expression.IValue) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) StaticRelation(com.dat3m.dartagnan.wmm.relation.base.stat.StaticRelation) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) ImmutableList(com.google.common.collect.ImmutableList) IValue(com.dat3m.dartagnan.expression.IValue) FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Register(com.dat3m.dartagnan.program.Register) Event(com.dat3m.dartagnan.program.event.core.Event) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 7 with RegWriter

use of com.dat3m.dartagnan.program.event.core.utils.RegWriter in project Dat3M by hernanponcedeleon.

the class BasicRegRelation method mkTupleSets.

void mkTupleSets(Collection<Event> regReaders) {
    maxTupleSet = new TupleSet();
    minTupleSet = new TupleSet();
    ExecutionAnalysis exec = analysisContext.requires(ExecutionAnalysis.class);
    ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
    for (Event regReader : regReaders) {
        for (Register register : getRegisters(regReader)) {
            List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
            // =============== Reduce set of writes ==================
            // TODO: We assume that any Register-Write is always executed
            // if it is contained in the program flow
            // This may fail for RMWReadCond?! It seems to work fine for the litmus tests though.
            // =========================
            List<Event> possibleWriters = writers.stream().filter(x -> x.getCId() < regReader.getCId() && !exec.areMutuallyExclusive(x, regReader)).collect(Collectors.toList());
            List<Event> impliedWriters = possibleWriters.stream().filter(x -> exec.isImplied(regReader, x)).collect(Collectors.toList());
            if (!impliedWriters.isEmpty()) {
                Event lastImplied = impliedWriters.get(impliedWriters.size() - 1);
                possibleWriters.removeIf(x -> x.getCId() < lastImplied.getCId());
            }
            possibleWriters.removeIf(x -> possibleWriters.stream().anyMatch(y -> x.getCId() < y.getCId() && exec.isImplied(x, y)));
            // --- Min sets ---
            if (possibleWriters.size() == 1) {
                // there is only a single regWriter
                minTupleSet.add(new Tuple(possibleWriters.stream().findAny().get(), regReader));
            } else {
                // there are multiple regWriters, but some are exclusive to all others
                for (Event writer : possibleWriters) {
                    if (possibleWriters.stream().allMatch(x -> x == writer || exec.areMutuallyExclusive(x, writer))) {
                        minTupleSet.add(new Tuple(writer, regReader));
                    }
                }
            }
            // --- Max sets ---
            for (Event regWriter : possibleWriters) {
                maxTupleSet.add(new Tuple(regWriter, regReader));
            }
        }
    }
}
Also used : FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Collection(java.util.Collection) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Set(java.util.Set) Collectors(java.util.stream.Collectors) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) SolverContext(org.sosy_lab.java_smt.api.SolverContext) IValue(com.dat3m.dartagnan.expression.IValue) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) StaticRelation(com.dat3m.dartagnan.wmm.relation.base.stat.StaticRelation) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) ExecutionAnalysis(com.dat3m.dartagnan.program.analysis.ExecutionAnalysis) Register(com.dat3m.dartagnan.program.Register) ImmutableList(com.google.common.collect.ImmutableList) Event(com.dat3m.dartagnan.program.event.core.Event) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 8 with RegWriter

use of com.dat3m.dartagnan.program.event.core.utils.RegWriter 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 9 with RegWriter

use of com.dat3m.dartagnan.program.event.core.utils.RegWriter 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 10 with RegWriter

use of com.dat3m.dartagnan.program.event.core.utils.RegWriter 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)

Aggregations

RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)15 Register (com.dat3m.dartagnan.program.Register)13 Event (com.dat3m.dartagnan.program.event.core.Event)9 Thread (com.dat3m.dartagnan.program.Thread)4 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)4 RegReaderData (com.dat3m.dartagnan.program.event.core.utils.RegReaderData)4 ImmutableList (com.google.common.collect.ImmutableList)4 BigInteger (java.math.BigInteger)4 Collectors (java.util.stream.Collectors)4 Program (com.dat3m.dartagnan.program.Program)3 Dependency (com.dat3m.dartagnan.program.analysis.Dependency)3 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 java.util (java.util)3 Set (java.util.Set)3 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)3 SolverContext (org.sosy_lab.java_smt.api.SolverContext)3 IValue (com.dat3m.dartagnan.expression.IValue)2 Utils.generalEqual (com.dat3m.dartagnan.expression.utils.Utils.generalEqual)2 ExecutionAnalysis (com.dat3m.dartagnan.program.analysis.ExecutionAnalysis)2