Search in sources :

Example 11 with Z3Exception

use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.

the class ARM method satARMPPO.

private static BoolExpr satARMPPO(Set<Event> events, Context ctx) throws Z3Exception {
    BoolExpr enc = ctx.mkTrue();
    for (Event e1 : events) {
        for (Event e2 : events) {
            BoolExpr orClause1 = ctx.mkFalse();
            BoolExpr orClause2 = ctx.mkFalse();
            BoolExpr orClause3 = ctx.mkFalse();
            BoolExpr orClause4 = ctx.mkFalse();
            BoolExpr orClause5 = ctx.mkFalse();
            BoolExpr orClause6 = ctx.mkFalse();
            BoolExpr orClause7 = ctx.mkFalse();
            BoolExpr orClause8 = ctx.mkFalse();
            for (Event e3 : events) {
                orClause1 = ctx.mkOr(orClause1, ctx.mkAnd(Utils.edge("ic", e1, e3, ctx), edge("ci", e3, e2, ctx)));
                orClause2 = ctx.mkOr(orClause2, ctx.mkAnd(Utils.edge("ii", e1, e3, ctx), edge("ii", e3, e2, ctx)));
                orClause3 = ctx.mkOr(orClause3, ctx.mkAnd(Utils.edge("ic", e1, e3, ctx), edge("cc", e3, e2, ctx)));
                orClause4 = ctx.mkOr(orClause4, ctx.mkAnd(Utils.edge("ii", e1, e3, ctx), edge("ic", e3, e2, ctx)));
                orClause5 = ctx.mkOr(orClause5, ctx.mkAnd(Utils.edge("ci", e1, e3, ctx), edge("ii", e3, e2, ctx)));
                orClause6 = ctx.mkOr(orClause6, ctx.mkAnd(Utils.edge("cc", e1, e3, ctx), edge("ci", e3, e2, ctx)));
                orClause7 = ctx.mkOr(orClause7, ctx.mkAnd(Utils.edge("ci", e1, e3, ctx), edge("ic", e3, e2, ctx)));
                orClause8 = ctx.mkOr(orClause8, ctx.mkAnd(Utils.edge("cc", e1, e3, ctx), edge("cc", e3, e2, ctx)));
            }
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ic;ci", e1, e2, ctx), orClause1));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ii;ii", e1, e2, ctx), orClause2));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ic;cc", e1, e2, ctx), orClause3));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ii;ic", e1, e2, ctx), orClause4));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ci;ii", e1, e2, ctx), orClause5));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("cc;ci", e1, e2, ctx), orClause6));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ci;ic", e1, e2, ctx), orClause7));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("cc;cc", e1, e2, ctx), orClause8));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ii", e1, e2, ctx), ctx.mkOr(edge("ii0", e1, e2, ctx), edge("ci", e1, e2, ctx), edge("ic;ci", e1, e2, ctx), edge("ii;ii", e1, e2, ctx))));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ic", e1, e2, ctx), ctx.mkOr(edge("ic0", e1, e2, ctx), edge("ii", e1, e2, ctx), edge("cc", e1, e2, ctx), edge("ic;cc", e1, e2, ctx), edge("ii;ic", e1, e2, ctx))));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("ci", e1, e2, ctx), ctx.mkOr(edge("ci0", e1, e2, ctx), edge("ci;ii", e1, e2, ctx), edge("cc;ci", e1, e2, ctx))));
            enc = ctx.mkAnd(enc, ctx.mkEq(edge("cc", e1, e2, ctx), ctx.mkOr(edge("cc0", e1, e2, ctx), edge("ci", e1, e2, ctx), edge("ci;ic", e1, e2, ctx), edge("cc;cc", e1, e2, ctx))));
            enc = ctx.mkAnd(enc, ctx.mkImplies(edge("ii", e1, e2, ctx), ctx.mkOr(ctx.mkAnd(edge("ii0", e1, e2, ctx), ctx.mkGt(intCount("ii", e1, e2, ctx), intCount("ii0", e1, e2, ctx))), ctx.mkAnd(edge("ci", e1, e2, ctx), ctx.mkGt(intCount("ii", e1, e2, ctx), intCount("ci", e1, e2, ctx))), ctx.mkAnd(edge("ic;ci", e1, e2, ctx), ctx.mkGt(intCount("ii", e1, e2, ctx), intCount("ic;ci", e1, e2, ctx))), ctx.mkAnd(edge("ii;ii", e1, e2, ctx), ctx.mkGt(intCount("ii", e1, e2, ctx), intCount("ii;ii", e1, e2, ctx))))));
            enc = ctx.mkAnd(enc, ctx.mkImplies(edge("ic", e1, e2, ctx), ctx.mkOr(ctx.mkAnd(edge("ic0", e1, e2, ctx), ctx.mkGt(intCount("ic", e1, e2, ctx), intCount("ic0", e1, e2, ctx))), ctx.mkAnd(edge("ii", e1, e2, ctx), ctx.mkGt(intCount("ic", e1, e2, ctx), intCount("ii", e1, e2, ctx))), ctx.mkAnd(edge("cc", e1, e2, ctx), ctx.mkGt(intCount("ic", e1, e2, ctx), intCount("cc", e1, e2, ctx))), ctx.mkAnd(edge("ic;cc", e1, e2, ctx), ctx.mkGt(intCount("ic", e1, e2, ctx), intCount("ic;cc", e1, e2, ctx))), ctx.mkAnd(edge("ii;ic", e1, e2, ctx), ctx.mkGt(intCount("ic", e1, e2, ctx), intCount("ii;ic", e1, e2, ctx))))));
            enc = ctx.mkAnd(enc, ctx.mkImplies(edge("ci", e1, e2, ctx), ctx.mkOr(ctx.mkAnd(edge("ci0", e1, e2, ctx), ctx.mkGt(intCount("ci", e1, e2, ctx), intCount("ci0", e1, e2, ctx))), ctx.mkAnd(edge("ci;ii", e1, e2, ctx), ctx.mkGt(intCount("ci", e1, e2, ctx), intCount("ci;ii", e1, e2, ctx))), ctx.mkAnd(edge("cc;ci", e1, e2, ctx), ctx.mkGt(intCount("ci", e1, e2, ctx), intCount("cc;ci", e1, e2, ctx))))));
            enc = ctx.mkAnd(enc, ctx.mkImplies(edge("cc", e1, e2, ctx), ctx.mkOr(ctx.mkAnd(edge("cc0", e1, e2, ctx), ctx.mkGt(intCount("cc", e1, e2, ctx), intCount("cc0", e1, e2, ctx))), ctx.mkAnd(edge("ci", e1, e2, ctx), ctx.mkGt(intCount("cc", e1, e2, ctx), intCount("ci", e1, e2, ctx))), ctx.mkAnd(edge("ci;ic", e1, e2, ctx), ctx.mkGt(intCount("cc", e1, e2, ctx), intCount("ci;ic", e1, e2, ctx))), ctx.mkAnd(edge("cc;cc", e1, e2, ctx), ctx.mkGt(intCount("cc", e1, e2, ctx), intCount("cc;cc", e1, e2, ctx))))));
        }
    }
    return enc;
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Example 12 with Z3Exception

use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.

the class Power method Inconsistent.

public static BoolExpr Inconsistent(Program program, Context ctx) throws Z3Exception {
    Set<Event> events = program.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
    BoolExpr enc = ctx.mkAnd(satCycleDef("hb-power", events, ctx), satCycleDef("(co+prop)", events, ctx), satCycleDef("(poloc+com)", events, ctx));
    enc = ctx.mkAnd(enc, ctx.mkOr(satCycle("hb-power", events, ctx), ctx.mkNot(satIrref("((fre;prop);(hb-power)*)", events, ctx)), satCycle("(co+prop)", events, ctx), satCycle("(poloc+com)", events, ctx)));
    return enc;
}
Also used : EncodingsCAT.satTransFixPoint(dartagnan.wmm.EncodingsCAT.satTransFixPoint) EncodingsCAT.satCycle(dartagnan.wmm.EncodingsCAT.satCycle) EncodingsCAT.satTransRef(dartagnan.wmm.EncodingsCAT.satTransRef) Event(dartagnan.program.Event) Context(com.microsoft.z3.Context) Set(java.util.Set) Collectors(java.util.stream.Collectors) Utils.intCount(dartagnan.utils.Utils.intCount) EncodingsCAT.satEmpty(dartagnan.wmm.EncodingsCAT.satEmpty) EncodingsCAT.satUnion(dartagnan.wmm.EncodingsCAT.satUnion) EncodingsCAT.satComp(dartagnan.wmm.EncodingsCAT.satComp) EncodingsCAT.satIrref(dartagnan.wmm.EncodingsCAT.satIrref) EncodingsCAT.satCycleDef(dartagnan.wmm.EncodingsCAT.satCycleDef) EncodingsCAT.satAcyclic(dartagnan.wmm.EncodingsCAT.satAcyclic) Local(dartagnan.program.Local) MemEvent(dartagnan.program.MemEvent) BoolExpr(com.microsoft.z3.BoolExpr) Z3Exception(com.microsoft.z3.Z3Exception) Program(dartagnan.program.Program) Utils.edge(dartagnan.utils.Utils.edge) EncodingsCAT.satMinus(dartagnan.wmm.EncodingsCAT.satMinus) EncodingsCAT.satIntersection(dartagnan.wmm.EncodingsCAT.satIntersection) BoolExpr(com.microsoft.z3.BoolExpr) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Example 13 with Z3Exception

use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.

the class Power method encode.

public static BoolExpr encode(Program program, Context ctx) throws Z3Exception {
    Set<Event> events = program.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
    Set<Event> eventsL = program.getEvents().stream().filter(e -> e instanceof MemEvent || e instanceof Local).collect(Collectors.toSet());
    BoolExpr enc = satUnion("co", "fr", events, ctx);
    enc = ctx.mkAnd(enc, satUnion("com", "(co+fr)", "rf", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("poloc", "com", events, ctx));
    enc = ctx.mkAnd(enc, satTransFixPoint("idd", eventsL, ctx));
    enc = ctx.mkAnd(enc, satIntersection("data", "idd^+", "RW", events, ctx));
    enc = ctx.mkAnd(enc, satEmpty("addr", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "addr", "data", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satComp("coe", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("rdw", "poloc", "(fre;rfe)", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("detour", "poloc", "(coe;rfe)", events, ctx));
    // Base case for program order
    enc = ctx.mkAnd(enc, satUnion("dp", "rdw", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ii0", "(dp+rdw)", "rfi", events, ctx));
    enc = ctx.mkAnd(enc, satEmpty("ic0", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ci0", "ctrlisync", "detour", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "poloc", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("(dp+poloc)", "ctrl", events, ctx));
    enc = ctx.mkAnd(enc, satComp("addr", "po", events, ctx));
    enc = ctx.mkAnd(enc, satPowerPPO(events, ctx));
    enc = ctx.mkAnd(enc, satUnion("cc0", "((dp+poloc)+ctrl)", "(addr;po)", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("RR", "ii", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("RW", "ic", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("po-power", "(RR&ii)", "(RW&ic)", events, ctx));
    // Fences in Power
    enc = ctx.mkAnd(enc, satMinus("lwsync", "WR", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("fence-power", "sync", "(lwsync\\WR)", events, ctx));
    // Happens before
    enc = ctx.mkAnd(enc, satUnion("po-power", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("hb-power", "(po-power+rfe)", "fence-power", events, ctx));
    // Prop-base
    enc = ctx.mkAnd(enc, satComp("rfe", "fence-power", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("fence-power", "(rfe;fence-power)", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("hb-power", events, ctx));
    enc = ctx.mkAnd(enc, satComp("prop-base", "(fence-power+(rfe;fence-power))", "(hb-power)*", events, ctx));
    // Propagation for Power
    enc = ctx.mkAnd(enc, satTransRef("com", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(com)*", "(prop-base)*", events, ctx));
    enc = ctx.mkAnd(enc, satComp("((com)*;(prop-base)*)", "sync", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(((com)*;(prop-base)*);sync)", "(hb-power)*", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("WW", "prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("prop", "(WW&prop-base)", "((((com)*;(prop-base)*);sync);(hb-power)*)", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "prop", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(fre;prop)", "(hb-power)*", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("co", "prop", events, ctx));
    return enc;
}
Also used : EncodingsCAT.satTransFixPoint(dartagnan.wmm.EncodingsCAT.satTransFixPoint) EncodingsCAT.satCycle(dartagnan.wmm.EncodingsCAT.satCycle) EncodingsCAT.satTransRef(dartagnan.wmm.EncodingsCAT.satTransRef) Event(dartagnan.program.Event) Context(com.microsoft.z3.Context) Set(java.util.Set) Collectors(java.util.stream.Collectors) Utils.intCount(dartagnan.utils.Utils.intCount) EncodingsCAT.satEmpty(dartagnan.wmm.EncodingsCAT.satEmpty) EncodingsCAT.satUnion(dartagnan.wmm.EncodingsCAT.satUnion) EncodingsCAT.satComp(dartagnan.wmm.EncodingsCAT.satComp) EncodingsCAT.satIrref(dartagnan.wmm.EncodingsCAT.satIrref) EncodingsCAT.satCycleDef(dartagnan.wmm.EncodingsCAT.satCycleDef) EncodingsCAT.satAcyclic(dartagnan.wmm.EncodingsCAT.satAcyclic) Local(dartagnan.program.Local) MemEvent(dartagnan.program.MemEvent) BoolExpr(com.microsoft.z3.BoolExpr) Z3Exception(com.microsoft.z3.Z3Exception) Program(dartagnan.program.Program) Utils.edge(dartagnan.utils.Utils.edge) EncodingsCAT.satMinus(dartagnan.wmm.EncodingsCAT.satMinus) EncodingsCAT.satIntersection(dartagnan.wmm.EncodingsCAT.satIntersection) BoolExpr(com.microsoft.z3.BoolExpr) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Local(dartagnan.program.Local)

Example 14 with Z3Exception

use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.

the class Encodings method encodeCommonExecutions.

public static BoolExpr encodeCommonExecutions(Program p1, Program p2, Context ctx) throws Z3Exception {
    BoolExpr enc = ctx.mkTrue();
    Set<Event> lEventsP1 = p1.getEvents().stream().filter(e -> e instanceof MemEvent | e instanceof Local).collect(Collectors.toSet());
    Set<Event> lEventsP2 = p2.getEvents().stream().filter(e -> e instanceof MemEvent | e instanceof Local).collect(Collectors.toSet());
    Set<Event> rEventsP1 = p1.getEvents().stream().filter(e -> e instanceof Load).collect(Collectors.toSet());
    Set<Event> wEventsP1 = p1.getEvents().stream().filter(e -> e instanceof Store || e instanceof Init).collect(Collectors.toSet());
    Set<Event> rEventsP2 = p2.getEvents().stream().filter(e -> e instanceof Load).collect(Collectors.toSet());
    Set<Event> wEventsP2 = p2.getEvents().stream().filter(e -> e instanceof Store || e instanceof Init).collect(Collectors.toSet());
    for (Event e1 : lEventsP1) {
        for (Event e2 : lEventsP2) {
            if (e1.getHLId().equals(e2.getHLId()) && e1.getUnfCopy().equals(e2.getUnfCopy())) {
                enc = ctx.mkAnd(enc, ctx.mkEq(e1.executes(ctx), e2.executes(ctx)));
            }
        }
    }
    for (Event r1 : rEventsP1) {
        for (Event r2 : rEventsP2) {
            if (r1.getHLId().equals(r2.getHLId()) && r1.getUnfCopy().equals(r2.getUnfCopy())) {
                for (Event w1 : wEventsP1) {
                    for (Event w2 : wEventsP2) {
                        if (r1.getLoc() != w1.getLoc()) {
                            continue;
                        }
                        if (r2.getLoc() != w2.getLoc()) {
                            continue;
                        }
                        if (w1.getHLId().equals(w2.getHLId()) && w1.getUnfCopy().equals(w2.getUnfCopy())) {
                            enc = ctx.mkAnd(enc, ctx.mkEq(edge("rf", w1, r1, ctx), edge("rf", w2, r2, ctx)));
                        }
                    }
                }
            }
        }
    }
    for (Event w1P1 : wEventsP1) {
        for (Event w1P2 : wEventsP2) {
            if (w1P1.getHLId().equals(w1P2.getHLId()) && w1P1.getUnfCopy().equals(w1P2.getUnfCopy())) {
                for (Event w2P1 : wEventsP1) {
                    for (Event w2P2 : wEventsP2) {
                        if (w1P1.getLoc() != w2P1.getLoc()) {
                            continue;
                        }
                        if (w1P1.getLoc() != w2P2.getLoc()) {
                            continue;
                        }
                        if (w1P1 == w2P1 | w1P2 == w2P2) {
                            continue;
                        }
                        if (w2P1.getHLId().equals(w2P2.getHLId()) && w2P1.getUnfCopy().equals(w2P2.getUnfCopy())) {
                            enc = ctx.mkAnd(enc, ctx.mkEq(edge("co", w1P1, w2P1, ctx), edge("co", w1P2, w2P2, ctx)));
                        }
                    }
                }
            }
        }
    }
    return enc;
}
Also used : HighLocation(dartagnan.program.HighLocation) Utils.lastValueReg(dartagnan.utils.Utils.lastValueReg) Utils.uniqueValue(dartagnan.utils.Utils.uniqueValue) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) Set(java.util.Set) If(dartagnan.program.If) Collectors(java.util.stream.Collectors) Utils.initValue(dartagnan.utils.Utils.initValue) Init(dartagnan.program.Init) Register(dartagnan.program.Register) Utils.initValue2(dartagnan.utils.Utils.initValue2) Local(dartagnan.program.Local) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Utils.ssaReg(dartagnan.utils.Utils.ssaReg) Program(dartagnan.program.Program) Utils.edge(dartagnan.utils.Utils.edge) Utils.lastValueLoc(dartagnan.utils.Utils.lastValueLoc) Store(dartagnan.program.Store) MapSSA(dartagnan.utils.MapSSA) Location(dartagnan.program.Location) Load(dartagnan.program.Load) Init(dartagnan.program.Init) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Local(dartagnan.program.Local) Store(dartagnan.program.Store)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)9 Context (com.microsoft.z3.Context)9 Z3Exception (com.microsoft.z3.Z3Exception)9 Event (dartagnan.program.Event)9 MemEvent (dartagnan.program.MemEvent)9 Program (dartagnan.program.Program)9 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 Local (dartagnan.program.Local)7 Utils.edge (dartagnan.utils.Utils.edge)6 Utils (dartagnan.utils.Utils)5 Status (com.microsoft.z3.Status)4 Init (dartagnan.program.Init)4 com.microsoft.z3 (com.microsoft.z3)3 Load (dartagnan.program.Load)3 Location (dartagnan.program.Location)3 Register (dartagnan.program.Register)3 Store (dartagnan.program.Store)3 Utils.intCount (dartagnan.utils.Utils.intCount)3 EncodingsCAT.satAcyclic (dartagnan.wmm.EncodingsCAT.satAcyclic)3