use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class PropertyEncoder method encodeLiveness.
public BooleanFormula encodeLiveness(SolverContext ctx) {
// Further, we assume that the spinloops are indeed correct, i.e., side-effect free
class SpinLoop {
public List<Load> loads = new ArrayList<>();
public Event bound;
}
logger.info("Encoding liveness");
Map<Thread, List<SpinLoop>> spinloopsMap = new HashMap<>();
// Find spinloops of all threads
for (Thread t : program.getThreads()) {
List<Event> spinStarts = t.getEvents().stream().filter(e -> e instanceof Label && e.is(Tag.SPINLOOP)).collect(Collectors.toList());
List<SpinLoop> spinLoops = new ArrayList<>();
spinloopsMap.put(t, spinLoops);
for (Event start : spinStarts) {
SpinLoop loop = new SpinLoop();
Event cur = start.getSuccessor();
while (!cur.is(Tag.SPINLOOP)) {
if (cur.is(Tag.READ)) {
loop.loads.add((Load) cur);
}
cur = cur.getSuccessor();
}
loop.bound = cur;
spinLoops.add(loop);
}
}
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
RelRf rf = (RelRf) memoryModel.getRelationRepository().getRelation(RelationNameRepository.RF);
RelCo co = (RelCo) memoryModel.getRelationRepository().getRelation(RelationNameRepository.CO);
// Compute "stuckness": A thread is stuck if it reaches a spinloop bound event
// while reading from a co-maximal write.
Map<Thread, BooleanFormula> isStuckMap = new HashMap<>();
for (Thread t : program.getThreads()) {
List<SpinLoop> loops = spinloopsMap.get(t);
if (loops.isEmpty()) {
continue;
}
BooleanFormula isStuck = bmgr.makeFalse();
for (SpinLoop pair : loops) {
BooleanFormula allCoMaximalLoad = bmgr.makeTrue();
for (Load load : pair.loads) {
BooleanFormula coMaximalLoad = bmgr.makeFalse();
for (Tuple rfEdge : rf.getMaxTupleSet().getBySecond(load)) {
coMaximalLoad = bmgr.or(coMaximalLoad, bmgr.and(rf.getSMTVar(rfEdge, ctx), co.getLastCoVar(rfEdge.getFirst(), ctx)));
}
allCoMaximalLoad = bmgr.and(allCoMaximalLoad, coMaximalLoad);
}
isStuck = bmgr.or(isStuck, bmgr.and(pair.bound.exec(), allCoMaximalLoad));
}
isStuckMap.put(t, isStuck);
}
// LivenessViolation <=> allStuckOrDone /\ atLeastOneStuck
BooleanFormula allStuckOrDone = bmgr.makeTrue();
BooleanFormula atLeastOneStuck = bmgr.makeFalse();
for (Thread t : program.getThreads()) {
BooleanFormula isStuck = isStuckMap.getOrDefault(t, bmgr.makeFalse());
BooleanFormula isDone = t.getCache().getEvents(FilterBasic.get(Tag.BOUND)).stream().map(e -> bmgr.not(e.exec())).reduce(bmgr.makeTrue(), bmgr::and);
atLeastOneStuck = bmgr.or(atLeastOneStuck, isStuck);
allStuckOrDone = bmgr.and(allStuckOrDone, bmgr.or(isStuck, isDone));
}
// We use the SMT variable to extract from the model if the property was violated
BooleanFormula enc = bmgr.equivalence(LIVENESS.getSMTVariable(ctx), bmgr.and(allStuckOrDone, atLeastOneStuck));
return bmgr.and(LIVENESS.getSMTVariable(ctx), enc);
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class SymmetryEncoder method sort.
private void sort(List<Tuple> row) {
if (!breakBySyncDegree) {
// ===== Natural order =====
row.sort(Comparator.naturalOrder());
return;
}
// ====== Sync-degree based order ======
// Setup of data structures
Set<Event> inEvents = new HashSet<>();
Set<Event> outEvents = new HashSet<>();
for (Tuple t : row) {
inEvents.add(t.getFirst());
outEvents.add(t.getSecond());
}
Map<Event, Integer> combInDegree = new HashMap<>(inEvents.size());
Map<Event, Integer> combOutDegree = new HashMap<>(outEvents.size());
List<Axiom> axioms = memoryModel.getAxioms();
for (Event e : inEvents) {
int syncDeg = axioms.stream().mapToInt(ax -> ax.getRelation().getMinTupleSet().getBySecond(e).size() + 1).max().orElse(0);
combInDegree.put(e, syncDeg);
}
for (Event e : outEvents) {
int syncDec = axioms.stream().mapToInt(ax -> ax.getRelation().getMinTupleSet().getByFirst(e).size() + 1).max().orElse(0);
combOutDegree.put(e, syncDec);
}
// Sort by sync degrees
row.sort(Comparator.<Tuple>comparingInt(t -> combInDegree.get(t.getFirst()) * combOutDegree.get(t.getSecond())).reversed());
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class VisitorLitmusC method visitReAtomicOpReturn.
// ----------------------------------------------------------------------------------------------------------------
// Return expressions (memory reads, must have register for return value)
// Returns new value (the value after computation)
@Override
public IExpr visitReAtomicOpReturn(LitmusCParser.ReAtomicOpReturnContext ctx) {
Register register = getReturnRegister(true);
IExpr value = returnExpressionOrDefault(ctx.value, BigInteger.ONE);
Event event = EventFactory.Linux.newRMWOpReturn(getAddress(ctx.address), register, value, ctx.op, ctx.mo);
programBuilder.addChild(currentThread, event);
return register;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class VisitorLitmusC method visitReAtomicFetchOp.
// Returns old value (the value before computation)
@Override
public IExpr visitReAtomicFetchOp(LitmusCParser.ReAtomicFetchOpContext ctx) {
Register register = getReturnRegister(true);
IExpr value = returnExpressionOrDefault(ctx.value, BigInteger.ONE);
Event event = EventFactory.Linux.newRMWFetchOp(getAddress(ctx.address), register, value, ctx.op, ctx.mo);
programBuilder.addChild(currentThread, event);
return register;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class VisitorLitmusC method visitReReadNa.
@Override
public IExpr visitReReadNa(LitmusCParser.ReReadNaContext ctx) {
Register register = getReturnRegister(true);
Event event = EventFactory.newLoad(register, getAddress(ctx.address), "NA");
programBuilder.addChild(currentThread, event);
return register;
}
Aggregations