Search in sources :

Example 6 with MemEvent

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

Example 7 with MemEvent

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

the class Encodings method getReachedStateLow.

public static BoolExpr getReachedStateLow(Program p, Model model, Context ctx) {
    Set<Location> locs = p.getEvents().stream().filter(e -> e instanceof MemEvent).map(e -> e.getLoc()).filter(l -> !(l instanceof HighLocation)).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))));
    }
    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) MemEvent(dartagnan.program.MemEvent) HighLocation(dartagnan.program.HighLocation) Location(dartagnan.program.Location)

Example 8 with MemEvent

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

the class Encodings method getExecutedInstanciatedEvents.

public static BoolExpr getExecutedInstanciatedEvents(Program p, Model model, Context ctx) {
    BoolExpr enc = ctx.mkTrue();
    for (Event e : p.getEvents()) {
        if (!(e instanceof MemEvent)) {
            continue;
        }
        if (model.getConstInterp(e.executes(ctx)).isTrue()) {
            enc = ctx.mkAnd(enc, e.executes(ctx));
            Expr dfEvent = model.getConstInterp(((MemEvent) e).ssaLoc);
            enc = ctx.mkAnd(enc, ctx.mkEq(((MemEvent) e).ssaLoc, dfEvent));
        }
    }
    return enc;
}
Also used : MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent)

Example 9 with MemEvent

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

the class Utils method drawGraph.

public static void drawGraph(Program p, Context ctx, Model model, String filename, String[] relations) throws IOException {
    File newTextFile = new File(filename);
    FileWriter fw = new FileWriter(newTextFile);
    GraphViz gv = new GraphViz();
    gv.addln(gv.start_graph());
    gv.addln("  subgraph cluster_Source { rank=sink; fontsize=20; label = \"Program Compiled to Source Architecture\"; color=red; shape=box;");
    int tid = 0;
    for (dartagnan.program.Thread t : p.getThreads()) {
        tid++;
        if (!(t instanceof Init)) {
            gv.addln("    subgraph cluster_Thread_Source" + t.getTId() + " { rank=sink; fontsize=15; label = \"Thread " + tid + "\"; color=magenta; shape=box;");
        }
        for (Event e : p.getEvents()) {
            String label = "";
            if (!(e instanceof MemEvent)) {
                continue;
            }
            if ((e instanceof Store || e instanceof Init) && model.getConstInterp(e.executes(ctx)).isTrue()) {
                label = "W_" + e.getLoc() + "_" + model.getConstInterp(((MemEvent) e).ssaLoc).toString() + "\\n";
            }
            if (e instanceof Load && model.getConstInterp(e.executes(ctx)).isTrue()) {
                label = "R_" + e.getLoc() + "_" + model.getConstInterp(((MemEvent) e).ssaLoc).toString() + "\\n";
            }
            for (Event eHL : p.getEvents().stream().filter(x -> x instanceof MemEvent).collect(Collectors.toSet())) {
                if (!(e instanceof Init) && e.getHLId() != null && e.getHLId() == eHL.hashCode()) {
                    label = label + eHL.toString().replaceAll("\\s", "");
                }
            }
            if ((e instanceof Store || e instanceof Load) && e.getMainThread() == t.getTId() && model.getConstInterp(e.executes(ctx)).isTrue()) {
                gv.addln("      " + e.repr() + " [label=\"" + label + "\", shape=\"box\", color=\"blue\", group=s" + e.getMainThread() + "];");
            }
            if (e instanceof Init && e.getMainThread() == t.getTId() && model.getConstInterp(e.executes(ctx)).isTrue()) {
                gv.addln("      " + e.repr() + " [label=\"" + label + "\", shape=\"box\", color=\"blue\", root=true];");
            }
        }
        if (!(t instanceof Init)) {
            gv.addln("    }");
        }
    }
    for (Event e1 : p.getEvents()) {
        for (Event e2 : p.getEvents()) {
            if (!(e1 instanceof MemEvent && e2 instanceof MemEvent)) {
                continue;
            }
            if (!(model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue())) {
                continue;
            }
            if (model.getConstInterp(edge("rf", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
                gv.addln("      " + e1.repr() + " -> " + e2.repr() + " [label=\"rf\", color=\"red\", fontcolor=\"red\", weight=1];");
            }
            if (model.getConstInterp(edge("fr", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
                gv.addln("      " + e1.repr() + " -> " + e2.repr() + " [label=\"fr\", color=\"#ffa040\", fontcolor=\"#ffa040\", weight=1];");
            }
            if (e1.getLoc() == e2.getLoc() && (e1 instanceof Store || e1 instanceof Init) && (e2 instanceof Store || e2 instanceof Init) && Integer.parseInt(model.getConstInterp(intVar("co", e1, ctx)).toString()) == Integer.parseInt(model.getConstInterp(intVar("co", e2, ctx)).toString()) - 1 && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
                gv.addln("      " + e1.repr() + " -> " + e2.repr() + " [label=\"co\", color=\"brown\", fontcolor=\"brown\", weight=1];");
            }
            if (model.getConstInterp(edge("sync", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
                gv.addln("      " + e1.repr() + " -> " + e2.repr() + " [label=\"sync\", color=\"black\", fontcolor=\"black\", weight=1];");
            }
            if (model.getConstInterp(edge("lwsync", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
                gv.addln("      " + e1.repr() + " -> " + e2.repr() + " [label=\"lwsync\", color=\"black\", fontcolor=\"black\", weight=1];");
            }
            if (model.getConstInterp(edge("mfence", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
                gv.addln("      " + e1.repr() + " -> " + e2.repr() + " [label=\"mfence\", color=\"black\", fontcolor=\"black\", weight=1];");
            }
        }
    }
    gv.addln("  }");
    gv.addln(gv.end_graph());
    fw.write(gv.getDotSource());
    fw.close();
    return;
}
Also used : Arrays(java.util.Arrays) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Init(dartagnan.program.Init) Register(dartagnan.program.Register) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Program(dartagnan.program.Program) Store(dartagnan.program.Store) Location(dartagnan.program.Location) Load(dartagnan.program.Load) FileWriter(java.io.FileWriter) Store(dartagnan.program.Store) Init(dartagnan.program.Init) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) File(java.io.File)

Example 10 with MemEvent

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

the class ARM 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", "ctrlisb", "detour", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "ctrl", events, ctx));
    enc = ctx.mkAnd(enc, satComp("addr", "po", events, ctx));
    enc = ctx.mkAnd(enc, satARMPPO(events, ctx));
    enc = ctx.mkAnd(enc, satUnion("cc0", "(dp+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-arm", "(RR&ii)", "(RW&ic)", events, ctx));
    // Happens before
    enc = ctx.mkAnd(enc, satUnion("po-arm", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("hb-arm", "(po-arm+rfe)", "ish", events, ctx));
    // Prop-base
    enc = ctx.mkAnd(enc, satComp("rfe", "ish", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ish", "(rfe;ish)", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("hb-arm", events, ctx));
    enc = ctx.mkAnd(enc, satComp("prop-base", "(ish+(rfe;ish))", "(hb-arm)*", events, ctx));
    // Propagation for ARM
    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)*)", "ish", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(((com)*;(prop-base)*);ish)", "(hb-arm)*", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("WW", "prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("prop", "(WW&prop-base)", "((((com)*;(prop-base)*);ish);(hb-arm)*)", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "prop", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(fre;prop)", "(hb-arm)*", 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) Utils(dartagnan.utils.Utils) 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.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)

Aggregations

Event (dartagnan.program.Event)16 MemEvent (dartagnan.program.MemEvent)16 Program (dartagnan.program.Program)15 Collectors (java.util.stream.Collectors)15 Local (dartagnan.program.Local)14 Set (java.util.Set)14 com.microsoft.z3 (com.microsoft.z3)11 Init (dartagnan.program.Init)11 Load (dartagnan.program.Load)11 Location (dartagnan.program.Location)11 Register (dartagnan.program.Register)11 Store (dartagnan.program.Store)11 Utils.edge (dartagnan.utils.Utils.edge)10 Utils (dartagnan.utils.Utils)6 Utils.lastValueLoc (dartagnan.utils.Utils.lastValueLoc)6 Utils.lastValueReg (dartagnan.utils.Utils.lastValueReg)6 Utils.ssaReg (dartagnan.utils.Utils.ssaReg)6 HighLocation (dartagnan.program.HighLocation)5 If (dartagnan.program.If)5 MapSSA (dartagnan.utils.MapSSA)5