Search in sources :

Example 46 with Context

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

the class Encodings method encodePreserveFences.

public static BoolExpr encodePreserveFences(Program p1, Program p2, Context ctx) {
    BoolExpr enc = ctx.mkTrue();
    Set<Event> memEventsP1 = p1.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
    Set<Event> memEventsP2 = p2.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
    for (Event e1P1 : memEventsP1) {
        for (Event e1P2 : memEventsP2) {
            if (e1P1.getHLId().equals(e1P2.getHLId())) {
                for (Event e2P1 : memEventsP1) {
                    for (Event e2P2 : memEventsP2) {
                        if (e1P1.getMainThread() != e2P1.getMainThread()) {
                            continue;
                        }
                        if (e1P2.getMainThread() != e2P2.getMainThread()) {
                            continue;
                        }
                        if (e1P1.getEId() >= e2P1.getEId() | e1P2.getEId() >= e2P2.getEId()) {
                            continue;
                        }
                        if (e2P1.getHLId().equals(e2P2.getHLId())) {
                            enc = ctx.mkAnd(enc, ctx.mkImplies(Utils.edge("sync", e1P1, e2P1, ctx), Utils.edge("sync", e1P2, e2P2, ctx)));
                            enc = ctx.mkAnd(enc, ctx.mkImplies(Utils.edge("lwsync", e1P1, e2P1, ctx), ctx.mkOr(Utils.edge("lwsync", e1P2, e2P2, ctx), Utils.edge("sync", e1P2, e2P2, ctx))));
                        }
                    }
                }
            }
        }
    }
    return enc;
}
Also used : IntStream(java.util.stream.IntStream) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) Set(java.util.Set) Assert(dartagnan.expression.Assert) Utils(dartagnan.utils.Utils) Collectors(java.util.stream.Collectors) Init(dartagnan.program.Init) HashSet(java.util.HashSet) Register(dartagnan.program.Register) Local(dartagnan.program.Local) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Program(dartagnan.program.Program) Collections(java.util.Collections) Store(dartagnan.program.Store) Location(dartagnan.program.Location) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Example 47 with Context

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

the class Encodings method encodeReachedState.

public static BoolExpr encodeReachedState(Program p, Model model, Context ctx) {
    Set<Location> locs = p.getEvents().stream().filter(e -> e instanceof MemEvent).map(e -> e.getLoc()).collect(Collectors.toSet());
    BoolExpr reachedState = ctx.mkTrue();
    for (Location loc : locs) {
        reachedState = ctx.mkAnd(reachedState, ctx.mkEq(ctx.mkIntConst(loc.getName() + "_final"), model.getConstInterp(ctx.mkIntConst(loc.getName() + "_final"))));
    }
    Set<Event> executedEvents = p.getEvents().stream().filter(e -> model.getConstInterp(e.executes(ctx)).isTrue()).collect(Collectors.toSet());
    Set<Register> regs = executedEvents.stream().filter(e -> e instanceof Local | e instanceof Load).map(e -> e.getReg()).collect(Collectors.toSet());
    for (Register reg : regs) {
        Set<Integer> ssaRegIndexes = new HashSet<Integer>();
        for (Event e : executedEvents) {
            if (!(e instanceof Load | e instanceof Local)) {
                continue;
            }
            if (e.getReg() != reg) {
                continue;
            }
            ssaRegIndexes.add(e.getSsaRegIndex());
        }
        Integer lastRegIndex = Collections.max(ssaRegIndexes);
        String regVarName = String.format("T%s_%s_%s", reg.getMainThread(), reg.getName(), lastRegIndex);
        reachedState = ctx.mkAnd(reachedState, ctx.mkEq(ctx.mkIntConst(regVarName), model.getConstInterp(ctx.mkIntConst(regVarName))));
    }
    return reachedState;
}
Also used : IntStream(java.util.stream.IntStream) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) Set(java.util.Set) Assert(dartagnan.expression.Assert) Utils(dartagnan.utils.Utils) Collectors(java.util.stream.Collectors) Init(dartagnan.program.Init) HashSet(java.util.HashSet) Register(dartagnan.program.Register) Local(dartagnan.program.Local) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Program(dartagnan.program.Program) Collections(java.util.Collections) Store(dartagnan.program.Store) Location(dartagnan.program.Location) Load(dartagnan.program.Load) Local(dartagnan.program.Local) Register(dartagnan.program.Register) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Location(dartagnan.program.Location) HashSet(java.util.HashSet)

Example 48 with Context

use of com.microsoft.z3.Context 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())) {
                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())) {
                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())) {
                            enc = ctx.mkAnd(enc, ctx.mkEq(Utils.edge("rf", w1, r1, ctx), Utils.edge("rf", w2, r2, ctx)));
                        }
                    }
                }
            }
        }
    }
    for (Event w1P1 : wEventsP1) {
        for (Event w1P2 : wEventsP2) {
            if (w1P1.getHLId().equals(w1P2.getHLId())) {
                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())) {
                            enc = ctx.mkAnd(enc, ctx.mkEq(Utils.edge("co", w1P1, w2P1, ctx), Utils.edge("co", w1P2, w2P2, ctx)));
                        }
                    }
                }
            }
        }
    }
    return enc;
}
Also used : IntStream(java.util.stream.IntStream) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) Set(java.util.Set) Assert(dartagnan.expression.Assert) Utils(dartagnan.utils.Utils) Collectors(java.util.stream.Collectors) Init(dartagnan.program.Init) HashSet(java.util.HashSet) Register(dartagnan.program.Register) Local(dartagnan.program.Local) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Program(dartagnan.program.Program) Collections(java.util.Collections) Store(dartagnan.program.Store) 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)

Example 49 with Context

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

the class Power method satPowerPPO.

private static BoolExpr satPowerPPO(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(edge("ic", e1, e3, ctx), edge("ci", e3, e2, ctx)));
                orClause2 = ctx.mkOr(orClause2, ctx.mkAnd(edge("ii", e1, e3, ctx), edge("ii", e3, e2, ctx)));
                orClause3 = ctx.mkOr(orClause3, ctx.mkAnd(edge("ic", e1, e3, ctx), edge("cc", e3, e2, ctx)));
                orClause4 = ctx.mkOr(orClause4, ctx.mkAnd(edge("ii", e1, e3, ctx), edge("ic", e3, e2, ctx)));
                orClause5 = ctx.mkOr(orClause5, ctx.mkAnd(edge("ci", e1, e3, ctx), edge("ii", e3, e2, ctx)));
                orClause6 = ctx.mkOr(orClause6, ctx.mkAnd(edge("cc", e1, e3, ctx), edge("ci", e3, e2, ctx)));
                orClause7 = ctx.mkOr(orClause7, ctx.mkAnd(edge("ci", e1, e3, ctx), edge("ic", e3, e2, ctx)));
                orClause8 = ctx.mkOr(orClause8, ctx.mkAnd(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.mkEq(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.mkEq(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.mkEq(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.mkEq(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 50 with Context

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

the class Encodings method initsUniquePath.

public static BoolExpr initsUniquePath(Program p, Context ctx) {
    BoolExpr prec = ctx.mkTrue();
    BoolExpr post = ctx.mkTrue();
    for (Event e : p.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet())) {
        prec = ctx.mkAnd(prec, ctx.mkOr(e.getGuard(), ctx.mkNot(e.executes(ctx))));
    }
    for (Event e : p.getEvents().stream().filter(e -> e instanceof Init && e.getLoc() instanceof HighLocation).collect(Collectors.toSet())) {
        BoolExpr guards = ctx.mkAnd(ctx.mkLt(ctx.mkSub(uniqueValue(e, ctx), ctx.mkInt(1)), initValue(e, ctx)), ctx.mkGt(ctx.mkAdd(uniqueValue(e, ctx), ctx.mkInt(1)), initValue(e, ctx)));
        post = ctx.mkAnd(post, guards);
    }
    return ctx.mkImplies(prec, post);
}
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) HighLocation(dartagnan.program.HighLocation) Init(dartagnan.program.Init) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)34 BoolExpr (com.microsoft.z3.BoolExpr)31 Test (org.junit.Test)24 List (java.util.List)21 Event (dartagnan.program.Event)19 MemEvent (dartagnan.program.MemEvent)19 Program (dartagnan.program.Program)19 IOException (java.io.IOException)19 Set (java.util.Set)19 Collectors (java.util.stream.Collectors)19 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 Local (dartagnan.program.Local)16 HashMap (java.util.HashMap)16 Map (java.util.Map)15 Solver (com.microsoft.z3.Solver)14 Init (dartagnan.program.Init)14 File (java.io.File)14