use of dartagnan.program.Local 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;
}
use of dartagnan.program.Local 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;
}
use of dartagnan.program.Local in project Dat3M by hernanponcedeleon.
the class Encodings method encodeMissingIndexes.
public static BoolExpr encodeMissingIndexes(If t, MapSSA map1, MapSSA map2, Context ctx) throws Z3Exception {
BoolExpr ret = ctx.mkTrue();
BoolExpr index = ctx.mkTrue();
for (Object o : map1.keySet()) {
Integer i1 = map1.get(o);
Integer i2 = map2.get(o);
if (i1 > i2) {
if (o instanceof Register) {
// for testing reachability
for (Event e : t.getEvents()) {
if (!(e instanceof Load || e instanceof Local)) {
continue;
}
if (e.getSsaRegIndex() == i1 && e.getReg() == o) {
ret = ctx.mkAnd(ret, ctx.mkImplies(ctx.mkNot(e.executes(ctx)), ctx.mkEq(ssaReg((Register) o, i1, ctx), ssaReg((Register) o, i1 - 1, ctx))));
}
}
index = ctx.mkEq(ssaReg((Register) o, i1, ctx), ssaReg((Register) o, i2, ctx));
}
if (o instanceof Location) {
index = ctx.mkEq(ctx.mkIntConst(String.format("%s_%s", o, i1)), ctx.mkIntConst(String.format("%s_%s", o, i2)));
}
ret = ctx.mkAnd(ret, ctx.mkImplies(ctx.mkBoolConst(t.getT2().cfVar()), index));
}
}
for (Object o : map2.keySet()) {
Integer i1 = map1.get(o);
Integer i2 = map2.get(o);
if (i2 > i1) {
if (o instanceof Register) {
for (Event e : t.getEvents()) {
if (!(e instanceof Load || e instanceof Local)) {
continue;
}
if (e.getSsaRegIndex() == i2 && e.getReg() == o) {
ret = ctx.mkAnd(ret, ctx.mkImplies(ctx.mkNot(e.executes(ctx)), ctx.mkEq(ssaReg((Register) o, i2, ctx), ssaReg((Register) o, i2 - 1, ctx))));
}
}
index = ctx.mkEq(ssaReg((Register) o, i2, ctx), ssaReg((Register) o, i1, ctx));
}
if (o instanceof Location) {
index = ctx.mkEq(ctx.mkIntConst(String.format("%s_%s", o, i2)), ctx.mkIntConst(String.format("%s_%s", o, i1)));
}
ret = ctx.mkAnd(ret, ctx.mkImplies(ctx.mkBoolConst(t.getT1().cfVar()), index));
}
}
return ret;
}
use of dartagnan.program.Local 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;
}
Aggregations