use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.
the class ARM 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-arm", events, ctx), satCycleDef("(co+prop)", events, ctx), satCycleDef("(poloc+com)", events, ctx));
enc = ctx.mkAnd(enc, ctx.mkOr(satCycle("hb-arm", events, ctx), ctx.mkNot(satIrref("((fre;prop);(hb-arm)*)", events, ctx)), satCycle("(co+prop)", events, ctx), satCycle("(poloc+com)", events, ctx)));
return enc;
}
use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.
the class Domain method encode.
public static BoolExpr encode(Program program, Context ctx) throws Z3Exception {
BoolExpr enc = ctx.mkTrue();
Set<Event> mEvents = program.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
Set<Event> barriers = program.getEvents().stream().filter(e -> e instanceof Barrier).collect(Collectors.toSet());
Set<Event> eventsL = program.getEvents().stream().filter(e -> e instanceof MemEvent || e instanceof Local).collect(Collectors.toSet());
for (Event e : eventsL) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ii", e, e, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ic", e, e, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ci", e, e, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("cc", e, e, ctx)));
}
for (Event e1 : mEvents) {
for (Event e2 : mEvents) {
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("rf", e1, e2, ctx), ctx.mkAnd(e1.executes(ctx), e2.executes(ctx))));
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("co", e1, e2, ctx), ctx.mkAnd(e1.executes(ctx), e2.executes(ctx))));
if (!(e1 instanceof Init)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("IM", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("IW", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("IR", e1, e2, ctx)));
} else {
enc = ctx.mkAnd(enc, edge("IM", e1, e2, ctx));
}
if (!(e2 instanceof Init)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("MI", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("WI", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("RI", e1, e2, ctx)));
} else {
enc = ctx.mkAnd(enc, edge("MI", e1, e2, ctx));
}
if (!(e1 instanceof Load)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("RM", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("RW", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("RR", e1, e2, ctx)));
} else {
enc = ctx.mkAnd(enc, edge("RM", e1, e2, ctx));
}
if (!(e2 instanceof Load)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("MR", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("WR", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("RR", e1, e2, ctx)));
} else {
enc = ctx.mkAnd(enc, edge("MR", e1, e2, ctx));
}
if (!(e1 instanceof Store || e1 instanceof Init)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("WM", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("WW", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("WR", e1, e2, ctx)));
} else {
enc = ctx.mkAnd(enc, edge("WM", e1, e2, ctx));
}
if (!(e2 instanceof Store || e2 instanceof Init)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("MW", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("WW", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("RW", e1, e2, ctx)));
} else {
enc = ctx.mkAnd(enc, edge("MW", e1, e2, ctx));
}
if (e1 instanceof Load && e2 instanceof Load) {
enc = ctx.mkAnd(enc, edge("RR", e1, e2, ctx));
}
if (e1 instanceof Load && (e2 instanceof Init || e2 instanceof Store)) {
enc = ctx.mkAnd(enc, edge("RW", e1, e2, ctx));
}
if ((e1 instanceof Init || e1 instanceof Store) && (e2 instanceof Init || e2 instanceof Store)) {
enc = ctx.mkAnd(enc, edge("WW", e1, e2, ctx));
}
if ((e1 instanceof Init || e1 instanceof Store) && e2 instanceof Load) {
enc = ctx.mkAnd(enc, edge("WR", e1, e2, ctx));
}
if (e1 == e2) {
enc = ctx.mkAnd(enc, edge("id", e1, e2, ctx));
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("id", e1, e2, ctx)));
}
if (e1.getMainThread() == e2.getMainThread()) {
enc = ctx.mkAnd(enc, edge("int", e1, e2, ctx));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ext", e1, e2, ctx)));
if (e1.getEId() < e2.getEId()) {
enc = ctx.mkAnd(enc, edge("po", e1, e2, ctx));
if (e1.getCondLevel() < e2.getCondLevel() && e1 instanceof Load && e2.getCondRegs().contains(e1.getReg())) {
enc = ctx.mkAnd(enc, edge("ctrlDirect", e1, e2, ctx));
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ctrlDirect", e1, e2, ctx)));
}
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("po", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ctrl", e1, e2, ctx)));
}
boolean noMfence = true;
boolean noSync = true;
boolean noLwsync = true;
boolean noIsync = true;
boolean noIsh = true;
boolean noIsb = true;
for (Event b : barriers.stream().filter(e -> e.getMainThread() == e1.getMainThread() && e1.getEId() < e.getEId() && e.getEId() < e2.getEId()).collect(Collectors.toSet())) {
if (b instanceof Mfence) {
noMfence = false;
}
if (b instanceof Sync) {
noSync = false;
}
if (b instanceof Lwsync) {
noLwsync = false;
}
if (b instanceof Isync) {
noIsync = false;
}
if (b instanceof Ish) {
noIsh = false;
}
if (b instanceof Isb) {
noIsb = false;
}
}
if (noMfence) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("mfence", e1, e2, ctx)));
}
if (noSync) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("sync", e1, e2, ctx)));
}
if (noLwsync) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("lwsync", e1, e2, ctx)));
}
if (noIsync) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("isync", e1, e2, ctx)));
}
if (noIsh) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ish", e1, e2, ctx)));
}
if (noIsb) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("isb", e1, e2, ctx)));
}
} else {
enc = ctx.mkAnd(enc, edge("ext", e1, e2, ctx));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("int", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("po", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ctrl", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ii", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ic", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ci", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("cc", e1, e2, ctx)));
}
if (e1.getLoc() == e2.getLoc()) {
enc = ctx.mkAnd(enc, edge("loc", e1, e2, ctx));
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("loc", e1, e2, ctx)));
}
if (!((e1 instanceof Store || e1 instanceof Init) && e2 instanceof Load && e1.getLoc() == e2.getLoc())) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("rf", e1, e2, ctx)));
}
if (!((e1 instanceof Store || e1 instanceof Init) && (e2 instanceof Store || e2 instanceof Init) && e1.getLoc() == e2.getLoc())) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("co", e1, e2, ctx)));
}
if (!(e1.getMainThread() == e2.getMainThread() && e1.getEId() < e2.getEId())) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("mfence", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("sync", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("lwsync", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("isync", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("ish", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("isb", e1, e2, ctx)));
}
enc = ctx.mkAnd(enc, ctx.mkEq(edge("rfe", e1, e2, ctx), ctx.mkAnd(edge("rf", e1, e2, ctx), edge("ext", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("rfi", e1, e2, ctx), ctx.mkAnd(edge("rf", e1, e2, ctx), edge("int", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("coe", e1, e2, ctx), ctx.mkAnd(edge("co", e1, e2, ctx), edge("ext", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("coi", e1, e2, ctx), ctx.mkAnd(edge("co", e1, e2, ctx), edge("int", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("fre", e1, e2, ctx), ctx.mkAnd(edge("fr", e1, e2, ctx), edge("ext", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("fri", e1, e2, ctx), ctx.mkAnd(edge("fr", e1, e2, ctx), edge("int", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("poloc", e1, e2, ctx), ctx.mkAnd(edge("po", e1, e2, ctx), edge("loc", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("ctrlisync", e1, e2, ctx), ctx.mkAnd(edge("ctrl", e1, e2, ctx), edge("isync", e1, e2, ctx))));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("ctrlisb", e1, e2, ctx), ctx.mkAnd(edge("ctrl", e1, e2, ctx), edge("isb", e1, e2, ctx))));
}
}
for (Event e1 : mEvents) {
for (Event e2 : mEvents) {
BoolExpr mfences = ctx.mkFalse();
BoolExpr syncs = ctx.mkFalse();
BoolExpr lwsyncs = ctx.mkFalse();
BoolExpr isyncs = ctx.mkFalse();
BoolExpr ishs = ctx.mkFalse();
BoolExpr isbs = ctx.mkFalse();
for (Event b : barriers) {
if (b instanceof Mfence && e1.getMainThread() == b.getMainThread() && b.getMainThread() == e2.getMainThread() && e1.getEId() < b.getEId() && b.getEId() < e2.getEId()) {
mfences = ctx.mkOr(mfences, b.executes(ctx));
enc = ctx.mkAnd(enc, ctx.mkImplies(ctx.mkAnd(e1.executes(ctx), ctx.mkAnd(b.executes(ctx), e2.executes(ctx))), edge("mfence", e1, e2, ctx)));
}
if (b instanceof Sync && e1.getMainThread() == b.getMainThread() && b.getMainThread() == e2.getMainThread() && e1.getEId() < b.getEId() && b.getEId() < e2.getEId()) {
syncs = ctx.mkOr(syncs, b.executes(ctx));
enc = ctx.mkAnd(enc, ctx.mkImplies(ctx.mkAnd(e1.executes(ctx), ctx.mkAnd(b.executes(ctx), e2.executes(ctx))), edge("sync", e1, e2, ctx)));
}
if (b instanceof Lwsync && e1.getMainThread() == b.getMainThread() && b.getMainThread() == e2.getMainThread() && e1.getEId() < b.getEId() && b.getEId() < e2.getEId()) {
lwsyncs = ctx.mkOr(lwsyncs, b.executes(ctx));
enc = ctx.mkAnd(enc, ctx.mkImplies(ctx.mkAnd(e1.executes(ctx), ctx.mkAnd(b.executes(ctx), e2.executes(ctx))), edge("lwsync", e1, e2, ctx)));
}
if (b instanceof Isync && e1.getMainThread() == b.getMainThread() && b.getMainThread() == e2.getMainThread() && e1.getEId() < b.getEId() && b.getEId() < e2.getEId()) {
isyncs = ctx.mkOr(isyncs, b.executes(ctx));
enc = ctx.mkAnd(enc, ctx.mkImplies(ctx.mkAnd(e1.executes(ctx), ctx.mkAnd(b.executes(ctx), e2.executes(ctx))), edge("isync", e1, e2, ctx)));
}
if (b instanceof Ish && e1.getMainThread() == b.getMainThread() && b.getMainThread() == e2.getMainThread() && e1.getEId() < b.getEId() && b.getEId() < e2.getEId()) {
ishs = ctx.mkOr(ishs, b.executes(ctx));
enc = ctx.mkAnd(enc, ctx.mkImplies(ctx.mkAnd(e1.executes(ctx), ctx.mkAnd(b.executes(ctx), e2.executes(ctx))), edge("ish", e1, e2, ctx)));
}
if (b instanceof Isb && e1.getMainThread() == b.getMainThread() && b.getMainThread() == e2.getMainThread() && e1.getEId() < b.getEId() && b.getEId() < e2.getEId()) {
isbs = ctx.mkOr(isbs, b.executes(ctx));
enc = ctx.mkAnd(enc, ctx.mkImplies(ctx.mkAnd(e1.executes(ctx), ctx.mkAnd(b.executes(ctx), e2.executes(ctx))), edge("isb", e1, e2, ctx)));
}
}
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("mfence", e1, e2, ctx), mfences));
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("sync", e1, e2, ctx), syncs));
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("lwsync", e1, e2, ctx), lwsyncs));
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("isync", e1, e2, ctx), isyncs));
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("ish", e1, e2, ctx), ishs));
enc = ctx.mkAnd(enc, ctx.mkImplies(edge("isb", e1, e2, ctx), isbs));
}
}
for (Event e1 : eventsL) {
for (Event e2 : eventsL) {
if (e1.getMainThread() != e2.getMainThread() || e2.getEId() < e1.getEId() || e1 == e2) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", e1, e2, ctx)));
enc = ctx.mkAnd(enc, ctx.mkNot(edge("data", e1, e2, ctx)));
}
if (e2 instanceof Store) {
if (!e2.getLastModMap().get(e2.getReg()).contains(e1)) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", e1, e2, ctx)));
}
}
if (e2 instanceof Load) {
if (!e2.getLastModMap().keySet().contains(e2.getLoc())) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", e1, e2, ctx)));
}
}
if (e2 instanceof Local && e2.getExpr() instanceof AConst) {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", e1, e2, ctx)));
}
}
}
for (Event e : eventsL) {
if (e instanceof Store) {
BoolExpr orClause = ctx.mkFalse();
for (Event x : eventsL) {
if (e.getLastModMap().get(e.getReg()).contains(x)) {
orClause = ctx.mkOr(orClause, edge("idd", x, e, ctx));
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", x, e, ctx)));
}
}
enc = ctx.mkAnd(enc, orClause);
}
if (e instanceof Load) {
if (!e.getLastModMap().keySet().contains(e.getLoc())) {
continue;
}
BoolExpr orClause = ctx.mkFalse();
for (Event x : eventsL) {
if (e.getLastModMap().get(e.getLoc()).contains(x)) {
orClause = ctx.mkOr(orClause, edge("idd", x, e, ctx));
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", x, e, ctx)));
}
}
enc = ctx.mkAnd(enc, orClause);
}
if (e instanceof Local) {
for (Register reg : e.getExpr().getRegs()) {
BoolExpr orClause = ctx.mkFalse();
for (Event x : eventsL) {
if (e.getLastModMap().get(reg).contains(x)) {
orClause = ctx.mkOr(orClause, edge("idd", x, e, ctx));
} else {
enc = ctx.mkAnd(enc, ctx.mkNot(edge("idd", x, e, ctx)));
}
}
enc = ctx.mkAnd(enc, orClause);
}
}
}
for (Event e1 : mEvents) {
for (Event e2 : mEvents) {
BoolExpr ctrlClause = edge("ctrlDirect", e1, e2, ctx);
BoolExpr orClause = ctx.mkFalse();
for (Event e3 : mEvents) {
ctrlClause = ctx.mkOr(ctrlClause, ctx.mkAnd(edge("ctrl", e1, e3, ctx), edge("po", e3, e2, ctx)));
orClause = ctx.mkOr(orClause, ctx.mkAnd(edge("rf", e3, e1, ctx), edge("co", e3, e2, ctx)));
}
enc = ctx.mkAnd(enc, ctx.mkEq(edge("fr", e1, e2, ctx), orClause));
enc = ctx.mkAnd(enc, ctx.mkEq(edge("ctrl", e1, e2, ctx), ctrlClause));
}
}
Set<Location> locs = mEvents.stream().filter(e -> e instanceof MemEvent).map(e -> e.getLoc()).collect(Collectors.toSet());
for (Location loc : locs) {
Set<Event> writesEventsLoc = mEvents.stream().filter(e -> (e instanceof Store || e instanceof Init) && e.getLoc() == loc).collect(Collectors.toSet());
enc = ctx.mkAnd(enc, satTO("co", writesEventsLoc, ctx));
}
for (Event e : mEvents.stream().filter(e -> e instanceof Init).collect(Collectors.toSet())) {
enc = ctx.mkAnd(enc, ctx.mkEq(intVar("co", e, ctx), ctx.mkInt(1)));
}
for (Event w1 : mEvents.stream().filter(e -> e instanceof Init || e instanceof Store).collect(Collectors.toSet())) {
Set<Event> writeSameLoc = mEvents.stream().filter(e -> (e instanceof Init || e instanceof Store) && w1.getLoc() == e.getLoc()).collect(Collectors.toSet());
BoolExpr lastCoOrder = w1.executes(ctx);
for (Event w2 : writeSameLoc) {
lastCoOrder = ctx.mkAnd(lastCoOrder, ctx.mkNot(edge("co", w1, w2, ctx)));
}
enc = ctx.mkAnd(enc, ctx.mkImplies(lastCoOrder, ctx.mkEq(lastValueLoc(w1.getLoc(), ctx), ((MemEvent) w1).ssaLoc)));
}
for (Event r1 : eventsL.stream().filter(e -> e instanceof Load || e instanceof Local).collect(Collectors.toSet())) {
Set<Event> modRegLater = eventsL.stream().filter(e -> (e instanceof Load || e instanceof Local) && r1.getReg() == e.getReg() && r1.getEId() < e.getEId()).collect(Collectors.toSet());
BoolExpr lastModReg = r1.executes(ctx);
for (Event r2 : modRegLater) {
lastModReg = ctx.mkAnd(lastModReg, ctx.mkNot(r2.executes(ctx)));
}
enc = ctx.mkAnd(enc, ctx.mkImplies(lastModReg, ctx.mkEq(lastValueReg(r1.getReg(), ctx), ssaReg(r1.getReg(), r1.getSsaRegIndex(), ctx))));
}
for (Event e : mEvents.stream().filter(e -> e instanceof Load).collect(Collectors.toSet())) {
Set<Event> storeEventsLoc = mEvents.stream().filter(x -> (x instanceof Store || x instanceof Init) && e.getLoc() == x.getLoc()).collect(Collectors.toSet());
Set<BoolExpr> rfPairs = new HashSet<BoolExpr>();
for (Event w : storeEventsLoc) {
rfPairs.add(edge("rf", w, e, ctx));
}
enc = ctx.mkAnd(enc, ctx.mkImplies(e.executes(ctx), encodeEO(rfPairs, ctx)));
}
return enc;
}
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())) {
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;
}
use of com.microsoft.z3.Z3Exception 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;
}
use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.
the class Porthos method main.
public static void main(String[] args) throws Z3Exception, IOException {
List<String> MCMs = Arrays.asList("sc", "tso", "pso", "rmo", "alpha", "power", "arm");
Options options = new Options();
Option sourceOpt = new Option("s", "source", true, "source MCM");
sourceOpt.setRequired(true);
options.addOption(sourceOpt);
Option targetOpt = new Option("t", "target", true, "target MCM");
targetOpt.setRequired(true);
options.addOption(targetOpt);
Option inputOpt = new Option("i", "input", true, "input file path");
inputOpt.setRequired(true);
options.addOption(inputOpt);
options.addOption("state", false, "PORTHOS performs state portability");
options.addOption(Option.builder("draw").hasArg().desc("If a buf is found, it outputs a graph \\path_to_file.dot").build());
options.addOption(Option.builder("rels").hasArgs().desc("Relations to be drawn in the graph").build());
options.addOption(Option.builder("unroll").hasArg().desc("Unrolling steps").build());
CommandLineParser parserCmd = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd;
try {
cmd = parserCmd.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("PORTHOS", options);
System.exit(1);
return;
}
String source = cmd.getOptionValue("source");
if (!MCMs.stream().anyMatch(mcms -> mcms.trim().equals(source))) {
System.out.println("Unrecognized source");
System.exit(0);
return;
}
String target = cmd.getOptionValue("target");
if (!MCMs.stream().anyMatch(mcms -> mcms.trim().equals(target))) {
System.out.println("Unrecognized target");
System.exit(0);
return;
}
String inputFilePath = cmd.getOptionValue("input");
if (!inputFilePath.endsWith("pts") && !inputFilePath.endsWith("litmus")) {
System.out.println("Unrecognized program format");
System.exit(0);
return;
}
File file = new File(inputFilePath);
boolean statePortability = cmd.hasOption("state");
String[] rels = new String[100];
if (cmd.hasOption("rels")) {
rels = cmd.getOptionValues("rels");
}
String program = FileUtils.readFileToString(file, "UTF-8");
ANTLRInputStream input = new ANTLRInputStream(program);
Program p = new Program(inputFilePath);
if (inputFilePath.endsWith("litmus")) {
LitmusLexer lexer = new LitmusLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
LitmusParser parser = new LitmusParser(tokens);
p = parser.program(inputFilePath).p;
}
if (inputFilePath.endsWith("pts")) {
PorthosLexer lexer = new PorthosLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PorthosParser parser = new PorthosParser(tokens);
p = parser.program(inputFilePath).p;
}
int steps = 1;
if (cmd.hasOption("unroll")) {
steps = Integer.parseInt(cmd.getOptionValue("unroll"));
}
p.initialize(steps);
Program pSource = p.clone();
Program pTarget = p.clone();
pSource.compile(source, false, true);
Integer startEId = Collections.max(pSource.getEvents().stream().filter(e -> e instanceof Init).map(e -> e.getEId()).collect(Collectors.toSet())) + 1;
pTarget.compile(target, false, true, startEId);
Context ctx = new Context();
ctx.setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB_FULL);
Solver s = ctx.mkSolver();
Solver s2 = ctx.mkSolver();
BoolExpr sourceDF = pSource.encodeDF(ctx);
BoolExpr sourceCF = pSource.encodeCF(ctx);
BoolExpr sourceDF_RF = pSource.encodeDF_RF(ctx);
BoolExpr sourceDomain = Domain.encode(pSource, ctx);
BoolExpr sourceMM = pSource.encodeMM(ctx, source);
s.add(pTarget.encodeDF(ctx));
s.add(pTarget.encodeCF(ctx));
s.add(pTarget.encodeDF_RF(ctx));
s.add(Domain.encode(pTarget, ctx));
s.add(pTarget.encodeMM(ctx, target));
s.add(pTarget.encodeConsistent(ctx, target));
s.add(sourceDF);
s.add(sourceCF);
s.add(sourceDF_RF);
s.add(sourceDomain);
s.add(sourceMM);
s.add(pSource.encodeInconsistent(ctx, source));
s.add(encodeCommonExecutions(pTarget, pSource, ctx));
s2.add(sourceDF);
s2.add(sourceCF);
s2.add(sourceDF_RF);
s2.add(sourceDomain);
s2.add(sourceMM);
s2.add(pSource.encodeConsistent(ctx, source));
if (!statePortability) {
if (s.check() == Status.SATISFIABLE) {
System.out.println("The program is not portable");
// System.out.println(" 0");
if (cmd.hasOption("draw")) {
String outputPath = cmd.getOptionValue("draw");
Utils.drawGraph(p, pSource, pTarget, ctx, s.getModel(), outputPath, rels);
}
return;
} else {
System.out.println("The program is portable");
// System.out.println(" 1");
return;
}
}
int iterations = 0;
Status lastCheck = Status.SATISFIABLE;
Set<Expr> visited = new HashSet<Expr>();
while (lastCheck == Status.SATISFIABLE) {
lastCheck = s.check();
if (lastCheck == Status.SATISFIABLE) {
iterations = iterations + 1;
Model model = s.getModel();
s2.push();
BoolExpr reachedState = encodeReachedState(pTarget, model, ctx);
visited.add(reachedState);
assert (iterations == visited.size());
s2.add(reachedState);
if (s2.check() == Status.UNSATISFIABLE) {
System.out.println("The program is not state-portable");
System.out.println("Iterations: " + iterations);
// System.out.println(" 0");
return;
} else {
s2.pop();
s.add(ctx.mkNot(reachedState));
}
} else {
System.out.println("The program is state-portable");
System.out.println("Iterations: " + iterations);
// System.out.println(" 1");
return;
}
}
}
Aggregations