use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class EventCache method getRegWriterMap.
public ImmutableMap<Register, ImmutableList<Event>> getRegWriterMap() {
if (regWriterMap == null) {
Map<Register, List<Event>> regEventMap = new HashMap<>();
List<Event> regWriters = getEvents(FilterBasic.get(Tag.REG_WRITER));
for (Event e : regWriters) {
Register register = ((RegWriter) e).getResultRegister();
regEventMap.computeIfAbsent(register, key -> new ArrayList<>(regWriters.size())).add(e);
}
ImmutableMap.Builder<Register, ImmutableList<Event>> builder = new ImmutableMap.Builder<>();
for (Register register : regEventMap.keySet()) {
List<Event> list = regEventMap.get(register);
Collections.sort(list);
builder.put(register, ImmutableList.copyOf(list));
}
regWriterMap = builder.build();
}
return regWriterMap;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class LoopUnrolling method updateAssertions.
private void updateAssertions(Program program) {
if (program.getAss() != null) {
// but I was under the impression that assFilter was used for Litmus tests.
return;
}
List<Event> assertions = new ArrayList<>();
for (Thread t : program.getThreads()) {
assertions.addAll(t.getCache().getEvents(FilterBasic.get(Tag.ASSERTION)));
}
AbstractAssert ass = new AssertTrue();
if (!assertions.isEmpty()) {
ass = new AssertInline((Local) assertions.get(0));
for (int i = 1; i < assertions.size(); i++) {
ass = new AssertCompositeOr(ass, new AssertInline((Local) assertions.get(i)));
}
}
program.setAss(ass);
logger.info("Updated assertions after unrolling.");
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeFinalRegisterValues.
public BooleanFormula encodeFinalRegisterValues(SolverContext ctx) {
checkInitialized();
logger.info("Encoding final register values");
FormulaManager fmgr = ctx.getFormulaManager();
BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
for (Map.Entry<Register, Dependency.State> e : dep.finalWriters().entrySet()) {
Formula value = e.getKey().getLastValueExpr(ctx);
Dependency.State state = e.getValue();
List<Event> writers = state.may;
if (initializeRegisters && !state.initialized) {
BooleanFormula clause = generalEqualZero(value, ctx);
for (Event w : writers) {
clause = bmgr.or(clause, w.exec());
}
enc = bmgr.and(enc, clause);
}
for (int i = 0; i < writers.size(); i++) {
Event writer = writers.get(i);
BooleanFormula clause = bmgr.or(generalEqual(value, ((RegWriter) writer).getResultRegisterExpr(), ctx), bmgr.not(writer.exec()));
for (Event w : writers.subList(i + 1, writers.size())) {
if (!exec.areMutuallyExclusive(writer, w)) {
clause = bmgr.or(clause, w.exec());
}
}
enc = bmgr.and(enc, clause);
}
}
return enc;
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method execution.
/**
* Simple formula proposing the execution of two events.
* Does not test for mutual exclusion.
* @param first
* Some event of a program to be encoded.
* @param second
* Another event of the same program.
* @param exec
* Analysis performed on the associated program.
* @param ctx
* Builder of expressions and formulas.
* @return
* Proposition that both {@code first} and {@code second} are included in the modelled execution.
*/
public static BooleanFormula execution(Event first, Event second, ExecutionAnalysis exec, SolverContext ctx) {
boolean b = first.getCId() < second.getCId();
Event x = b ? first : second;
Event y = b ? second : first;
if (x.exec() == y.exec() || exec.isImplied(x, y)) {
return x.exec();
}
if (exec.isImplied(y, x)) {
return y.exec();
}
return ctx.getFormulaManager().getBooleanFormulaManager().and(x.exec(), y.exec());
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class PropertyEncoder method encodeDataRaces.
public BooleanFormula encodeDataRaces(SolverContext ctx) {
final String hb = "hb";
checkState(memoryModel.getAxioms().stream().anyMatch(ax -> ax.isAcyclicity() && ax.getRelation().getName().equals(hb)), "The provided WMM needs an 'acyclic(hb)' axiom to encode data races.");
logger.info("Encoding data-races");
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
IntegerFormulaManager imgr = ctx.getFormulaManager().getIntegerFormulaManager();
BooleanFormula enc = bmgr.makeFalse();
for (Thread t1 : program.getThreads()) {
for (Thread t2 : program.getThreads()) {
if (t1.getId() == t2.getId()) {
continue;
}
for (Event e1 : t1.getCache().getEvents(FilterMinus.get(FilterBasic.get(Tag.WRITE), FilterBasic.get(Tag.INIT)))) {
MemEvent w = (MemEvent) e1;
for (Event e2 : t2.getCache().getEvents(FilterMinus.get(FilterBasic.get(Tag.MEMORY), FilterBasic.get(Tag.INIT)))) {
MemEvent m = (MemEvent) e2;
if (w.hasFilter(Tag.RMW) && m.hasFilter(Tag.RMW)) {
continue;
}
if (w.canRace() && m.canRace() && alias.mayAlias(w, m)) {
BooleanFormula conflict = bmgr.and(m.exec(), w.exec(), edge(hb, m, w, ctx), generalEqual(w.getMemAddressExpr(), m.getMemAddressExpr(), ctx), imgr.equal(intVar(hb, w, ctx), imgr.add(intVar(hb, m, ctx), imgr.makeNumber(BigInteger.ONE))));
enc = bmgr.or(enc, conflict);
}
}
}
}
}
// We use the SMT variable to extract from the model if the property was violated
enc = bmgr.equivalence(RACES.getSMTVariable(ctx), enc);
return bmgr.and(RACES.getSMTVariable(ctx), enc);
}
Aggregations