Search in sources :

Example 16 with Program

use of dartagnan.program.Program 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)

Example 17 with Program

use of dartagnan.program.Program 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(edge("sync", e1P1, e2P1, ctx), edge("sync", e1P2, e2P2, ctx)));
                            enc = ctx.mkAnd(enc, ctx.mkImplies(edge("lwsync", e1P1, e2P1, ctx), ctx.mkOr(edge("lwsync", e1P2, e2P2, ctx), edge("sync", e1P2, e2P2, 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) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Example 18 with Program

use of dartagnan.program.Program in project Dat3M by hernanponcedeleon.

the class Encodings method getInitialHigh.

public static BoolExpr getInitialHigh(Program p, Model model, Context ctx, boolean var1, boolean val1) {
    Set<Event> highInits = p.getEvents().stream().filter(e -> e instanceof Init).filter(e -> e.getLoc() instanceof HighLocation).collect(Collectors.toSet());
    BoolExpr reachedState = ctx.mkTrue();
    for (Event e : highInits) {
        IntExpr var = var1 ? initValue(e, ctx) : initValue2(e, ctx);
        IntExpr val = val1 ? initValue(e, ctx) : initValue2(e, ctx);
        if (e.getLoc().getIValue() == null) {
            reachedState = ctx.mkAnd(reachedState, ctx.mkEq(var, model.getConstInterp(val)));
        }
    }
    return reachedState;
}
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) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Example 19 with Program

use of dartagnan.program.Program 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(lastValueLoc(loc, ctx), model.getConstInterp(lastValueLoc(loc, ctx))));
    }
    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) {
        reachedState = ctx.mkAnd(reachedState, ctx.mkEq(lastValueReg(reg, ctx), model.getConstInterp(lastValueReg(reg, ctx))));
    }
    return reachedState;
}
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) Register(dartagnan.program.Register) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Local(dartagnan.program.Local) HighLocation(dartagnan.program.HighLocation) Location(dartagnan.program.Location)

Aggregations

Program (dartagnan.program.Program)19 Collectors (java.util.stream.Collectors)18 Event (dartagnan.program.Event)17 MemEvent (dartagnan.program.MemEvent)17 Set (java.util.Set)17 Local (dartagnan.program.Local)16 Init (dartagnan.program.Init)14 com.microsoft.z3 (com.microsoft.z3)13 Load (dartagnan.program.Load)13 Location (dartagnan.program.Location)13 Register (dartagnan.program.Register)13 Store (dartagnan.program.Store)13 Utils.edge (dartagnan.utils.Utils.edge)12 Utils (dartagnan.utils.Utils)8 Utils.lastValueLoc (dartagnan.utils.Utils.lastValueLoc)8 Utils.lastValueReg (dartagnan.utils.Utils.lastValueReg)8 Utils.ssaReg (dartagnan.utils.Utils.ssaReg)8 HighLocation (dartagnan.program.HighLocation)7 If (dartagnan.program.If)7 MapSSA (dartagnan.utils.MapSSA)7