use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class CoreReasoner method toCoreReason.
public Conjunction<CoreLiteral> toCoreReason(Conjunction<CAATLiteral> baseReason) {
RelationRepository repo = memoryModel.getRelationRepository();
EventDomain domain = executionGraph.getDomain();
List<CoreLiteral> coreReason = new ArrayList<>(baseReason.getSize());
for (CAATLiteral lit : baseReason.getLiterals()) {
if (lit instanceof ElementLiteral) {
Event e = domain.getObjectById(((ElementLiteral) lit).getElement().getId()).getEvent();
// We only have static tags, so all of them reduce to execution literals
coreReason.add(new ExecLiteral(e, lit.isNegative()));
} else {
EdgeLiteral edgeLit = (EdgeLiteral) lit;
Edge edge = edgeLit.getEdge();
Event e1 = domain.getObjectById(edge.getFirst()).getEvent();
Event e2 = domain.getObjectById(edge.getSecond()).getEvent();
Tuple tuple = new Tuple(e1, e2);
Relation rel = repo.getRelation(lit.getName());
if (lit.isPositive() && rel.getMinTupleSet().contains(tuple)) {
// Statically present edges
addExecReason(tuple, coreReason);
} else if (lit.isNegative() && !rel.getMaxTupleSet().contains(tuple)) {
// Statically absent edges
} else {
if (rel instanceof RelFencerel) {
// We should do this transformation directly on the Wmm to avoid this special reasoning
if (lit.isNegative()) {
throw new UnsupportedOperationException(String.format("FenceRel %s is not allowed on the rhs of differences.", rel));
}
addFenceReason(rel, edge, coreReason);
} else if (rel.getName().equals(LOC)) {
coreReason.add(new AddressLiteral(tuple, lit.isNegative()));
} else if (rel.getName().equals(RF) || rel.getName().equals(CO)) {
coreReason.add(new RelLiteral(rel.getName(), tuple, lit.isNegative()));
} else {
// TODO: Right now, we assume many relations like Data, Ctrl and Addr to be
// static.
addExecReason(tuple, coreReason);
}
}
}
}
minimize(coreReason);
return new Conjunction<>(coreReason);
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class RelCo method getMaxTupleSet.
@Override
public TupleSet getMaxTupleSet() {
if (maxTupleSet == null) {
logger.info("Computing maxTupleSet for " + getName());
AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
WmmAnalysis wmmAnalysis = analysisContext.get(WmmAnalysis.class);
maxTupleSet = new TupleSet();
List<Event> eventsInit = task.getProgram().getCache().getEvents(FilterBasic.get(INIT));
List<Event> eventsStore = task.getProgram().getCache().getEvents(FilterMinus.get(FilterBasic.get(WRITE), FilterBasic.get(INIT)));
for (Event e1 : eventsInit) {
for (Event e2 : eventsStore) {
if (alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
maxTupleSet.add(new Tuple(e1, e2));
}
}
}
for (Event e1 : eventsStore) {
for (Event e2 : eventsStore) {
if (e1.getCId() != e2.getCId() && alias.mayAlias((MemEvent) e1, (MemEvent) e2)) {
maxTupleSet.add(new Tuple(e1, e2));
}
}
}
removeMutuallyExclusiveTuples(maxTupleSet);
if (wmmAnalysis.isLocallyConsistent()) {
applyLocalConsistencyMaxSet();
}
logger.info("maxTupleSet size for " + getName() + ": " + maxTupleSet.size());
}
return maxTupleSet;
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class RelCo method applyLocalConsistencyMinSet.
private void applyLocalConsistencyMinSet() {
for (Tuple t : getMaxTupleSet()) {
AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
MemEvent w1 = (MemEvent) t.getFirst();
MemEvent w2 = (MemEvent) t.getSecond();
if (!w1.is(INIT) && alias.mustAlias(w1, w2) && (w1.is(INIT) || t.isForward())) {
minTupleSet.add(t);
}
}
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class RelLoc method getMinTupleSet.
@Override
public TupleSet getMinTupleSet() {
if (minTupleSet == null) {
AliasAnalysis alias = analysisContext.get(AliasAnalysis.class);
minTupleSet = new TupleSet();
for (Tuple t : getMaxTupleSet()) {
if (alias.mustAlias((MemEvent) t.getFirst(), (MemEvent) t.getSecond())) {
minTupleSet.add(t);
}
}
}
return minTupleSet;
}
use of com.dat3m.dartagnan.wmm.utils.Tuple in project Dat3M by hernanponcedeleon.
the class RelRf method encodeApprox.
@Override
protected BooleanFormula encodeApprox(SolverContext ctx) {
FormulaManager fmgr = ctx.getFormulaManager();
BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
Map<MemEvent, List<BooleanFormula>> edgeMap = new HashMap<>();
for (Tuple tuple : maxTupleSet) {
MemEvent w = (MemEvent) tuple.getFirst();
MemEvent r = (MemEvent) tuple.getSecond();
BooleanFormula edge = this.getSMTVar(tuple, ctx);
// The boogie file might have a different type (Ints vs BVs) that the imposed by ARCH_PRECISION
// In such cases we perform the transformation
Formula a1 = w.getMemAddressExpr();
Formula a2 = r.getMemAddressExpr();
BooleanFormula sameAddress = generalEqual(a1, a2, ctx);
Formula v1 = w.getMemValueExpr();
Formula v2 = r.getMemValueExpr();
BooleanFormula sameValue = generalEqual(v1, v2, ctx);
edgeMap.computeIfAbsent(r, key -> new ArrayList<>()).add(edge);
enc = bmgr.and(enc, bmgr.implication(edge, bmgr.and(getExecPair(w, r, ctx), sameAddress, sameValue)));
}
for (MemEvent r : edgeMap.keySet()) {
enc = bmgr.and(enc, encodeEdgeSeq(r, edgeMap.get(r), ctx));
}
return enc;
}
Aggregations