Search in sources :

Example 71 with Register

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

the class FindSpinLoops method isSideEffectFree.

private boolean isSideEffectFree(Label loopBegin, CondJump loopEnd) {
    Event cur = loopBegin.getSuccessor();
    // Unsafe means the loop read from the registers before writing to them.
    Set<Register> unsafeRegisters = new HashSet<>();
    // Safe means the loop wrote to these register before using them
    Set<Register> safeRegisters = new HashSet<>();
    while (cur != loopEnd) {
        if (cur instanceof MemEvent) {
            if (cur.is(Tag.WRITE)) {
                // Writes always cause side effects
                return false;
            }
            MemEvent memEvent = (MemEvent) cur;
            Set<Register> addrRegs = memEvent.getAddress().getRegs();
            unsafeRegisters.addAll(Sets.difference(addrRegs, safeRegisters));
        }
        if (cur instanceof RegReaderData) {
            RegReaderData reader = (RegReaderData) cur;
            Set<Register> dataRegs = reader.getDataRegs();
            unsafeRegisters.addAll(Sets.difference(dataRegs, safeRegisters));
        }
        if (cur instanceof RegWriter) {
            RegWriter writer = (RegWriter) cur;
            if (unsafeRegisters.contains(writer.getResultRegister())) {
                return false;
            } else {
                safeRegisters.add(writer.getResultRegister());
            }
        }
        cur = cur.getSuccessor();
    }
    return true;
}
Also used : Register(com.dat3m.dartagnan.program.Register) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) RegReaderData(com.dat3m.dartagnan.program.event.core.utils.RegReaderData) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) HashSet(java.util.HashSet)

Example 72 with Register

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

the class FieldSensitiveAndersen method processRegs.

protected void processRegs(Local e) {
    Register register = e.getResultRegister();
    Collector collector = new Collector(e.getExpr());
    addAllAddresses(register, collector.address());
    for (Offset<Register> r : collector.register()) {
        addEdge(r.base, register, r.offset, r.alignment);
    }
}
Also used : Register(com.dat3m.dartagnan.program.Register)

Example 73 with Register

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

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

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

the class AliasAnalysisTest method program0.

private void program0(Alias method, Result... expect) throws InvalidConfigurationException {
    ProgramBuilder b = new ProgramBuilder();
    MemoryObject x = b.newObject("x", 2);
    MemoryObject y = b.getOrNewObject("y");
    b.initThread(0);
    Register r0 = b.getOrCreateRegister(0, "r0", -1);
    // this is undefined behavior in C11
    // the expression does not match a sum, but x occurs in it
    b.addChild(0, newLocal(r0, mult(x, 1)));
    Store e0 = newStore(r0);
    b.addChild(0, e0);
    Store e1 = newStore(plus(r0, 1));
    b.addChild(0, e1);
    Store e2 = newStore(x);
    b.addChild(0, e2);
    Store e3 = newStore(y);
    b.addChild(0, e3);
    AliasAnalysis a = analyze(b, method);
    // precisely no
    assertAlias(expect[0], a, e0, e1);
    assertAlias(expect[1], a, e0, e2);
    assertAlias(expect[2], a, e1, e2);
    assertAlias(expect[3], a, e0, e3);
    assertAlias(expect[4], a, e1, e3);
    assertAlias(expect[5], a, e2, e3);
}
Also used : Register(com.dat3m.dartagnan.program.Register) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis)

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