Search in sources :

Example 21 with TupleSet

use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.

the class RelMinus method encodeApprox.

@Override
protected BooleanFormula encodeApprox(SolverContext ctx) {
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    TupleSet min = getMinTupleSet();
    for (Tuple tuple : encodeTupleSet) {
        if (min.contains(tuple)) {
            enc = bmgr.and(enc, bmgr.equivalence(this.getSMTVar(tuple, ctx), getExecPair(tuple, ctx)));
            continue;
        }
        BooleanFormula opt1 = r1.getSMTVar(tuple, ctx);
        BooleanFormula opt2 = bmgr.not(r2.getSMTVar(tuple, ctx));
        if (Relation.PostFixApprox) {
            enc = bmgr.and(enc, bmgr.implication(bmgr.and(opt1, opt2), this.getSMTVar(tuple, ctx)));
        } else {
            enc = bmgr.and(enc, bmgr.equivalence(this.getSMTVar(tuple, ctx), bmgr.and(opt1, opt2)));
        }
    }
    return enc;
}
Also used : TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 22 with TupleSet

use of com.dat3m.dartagnan.wmm.utils.TupleSet 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 23 with TupleSet

use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.

the class RelCo method getMaxTupleSet.

@Override
public TupleSet getMaxTupleSet() {
    if (maxTupleSet == null) {
        logger.info("Computing maxTupleSet for " + getName());
        AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
        WmmAnalysis wmmAnalysis = analysisContext.get(WmmAnalysis.class);
        maxTupleSet = new TupleSet();
        List<Event> eventsInit = task.getProgram().getCache().getEvents(FilterBasic.get(INIT));
        List<Event> eventsStore = task.getProgram().getCache().getEvents(FilterMinus.get(FilterBasic.get(WRITE), FilterBasic.get(INIT)));
        for (Event e1 : eventsInit) {
            for (Event e2 : eventsStore) {
                if (alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
                    maxTupleSet.add(new Tuple(e1, e2));
                }
            }
        }
        for (Event e1 : eventsStore) {
            for (Event e2 : eventsStore) {
                if (e1.getCId() != e2.getCId() && alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
                    maxTupleSet.add(new Tuple(e1, e2));
                }
            }
        }
        removeMutuallyExclusiveTuples(maxTupleSet);
        if (wmmAnalysis.isLocallyConsistent()) {
            applyLocalConsistencyMaxSet();
        }
        logger.info("maxTupleSet size for " + getName() + ": " + maxTupleSet.size());
    }
    return maxTupleSet;
}
Also used : TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) WmmAnalysis(com.dat3m.dartagnan.wmm.analysis.WmmAnalysis) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 24 with TupleSet

use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.

the class RelLoc method getMinTupleSet.

@Override
public TupleSet getMinTupleSet() {
    if (minTupleSet == null) {
        AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
        minTupleSet = new TupleSet();
        for (Tuple t : getMaxTupleSet()) {
            if (alias.mustAlias((MemEvent) t.getFirst(), (MemEvent) t.getSecond())) {
                minTupleSet.add(t);
            }
        }
    }
    return minTupleSet;
}
Also used : TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 25 with TupleSet

use of com.dat3m.dartagnan.wmm.utils.TupleSet in project Dat3M by hernanponcedeleon.

the class RelRf method getMaxTupleSet.

@Override
public TupleSet getMaxTupleSet() {
    if (maxTupleSet == null) {
        AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
        WmmAnalysis wmmAnalysis = analysisContext.get(WmmAnalysis.class);
        logger.info("Computing maxTupleSet for " + getName());
        maxTupleSet = new TupleSet();
        List<Event> loadEvents = task.getProgram().getCache().getEvents(FilterBasic.get(READ));
        List<Event> storeEvents = task.getProgram().getCache().getEvents(FilterBasic.get(WRITE));
        for (Event e1 : storeEvents) {
            for (Event e2 : loadEvents) {
                if (alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
                    maxTupleSet.add(new Tuple(e1, e2));
                }
            }
        }
        removeMutuallyExclusiveTuples(maxTupleSet);
        if (wmmAnalysis.isLocallyConsistent()) {
            applyLocalConsistency();
        }
        if (wmmAnalysis.doesRespectAtomicBlocks()) {
            atomicBlockOptimization();
        }
        logger.info("maxTupleSet size for " + getName() + ": " + maxTupleSet.size());
    }
    return maxTupleSet;
}
Also used : TupleSet(com.dat3m.dartagnan.wmm.utils.TupleSet) WmmAnalysis(com.dat3m.dartagnan.wmm.analysis.WmmAnalysis) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Aggregations

TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)47 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)36 Event (com.dat3m.dartagnan.program.event.core.Event)27 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)16 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)16 ExecutionAnalysis (com.dat3m.dartagnan.program.analysis.ExecutionAnalysis)11 Thread (com.dat3m.dartagnan.program.Thread)10 Relation (com.dat3m.dartagnan.wmm.relation.Relation)8 SolverContext (org.sosy_lab.java_smt.api.SolverContext)8 Sets (com.google.common.collect.Sets)7 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)5 Set (java.util.Set)5 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)4 HashSet (java.util.HashSet)4 Collectors (java.util.stream.Collectors)4 Tag (com.dat3m.dartagnan.program.event.Tag)3 WmmAnalysis (com.dat3m.dartagnan.wmm.analysis.WmmAnalysis)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 GlobalSettings (com.dat3m.dartagnan.GlobalSettings)2