use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class VisitorNone method visitRMWAddUnless.
@Override
public List<Event> visitRMWAddUnless(RMWAddUnless e) {
Register resultRegister = e.getResultRegister();
Register dummy = new Register(null, resultRegister.getThreadId(), resultRegister.getPrecision());
RMWReadCondUnless load = Linux.newRMWReadCondUnless(dummy, e.getCmp(), e.getAddress(), Tag.Linux.MO_RELAXED);
return eventSequence(Linux.newConditionalMemoryBarrier(load), load, Linux.newRMWStoreCond(load, e.getAddress(), new IExprBin(dummy, IOpBin.PLUS, (IExpr) e.getMemValue()), Tag.Linux.MO_RELAXED), newLocal(resultRegister, new Atom(dummy, NEQ, e.getCmp())), Linux.newConditionalMemoryBarrier(load));
}
use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class VisitorNone method visitJoin.
@Override
public List<Event> visitJoin(Join e) {
Register resultRegister = e.getResultRegister();
Load load = newLoad(resultRegister, e.getAddress(), e.getMo());
load.addFilters(C11.PTHREAD);
return eventSequence(load, newJumpUnless(new Atom(resultRegister, EQ, IValue.ZERO), e.getLabel()));
}
use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class VisitorNone method visitRMWOp.
@Override
public List<Event> visitRMWOp(RMWOp e) {
IExpr address = e.getAddress();
Register resultRegister = e.getResultRegister();
Load load = newRMWLoad(resultRegister, address, Tag.Linux.MO_RELAXED);
load.addFilters(Tag.Linux.NORETURN);
return eventSequence(load, newRMWStore(load, address, new IExprBin(resultRegister, e.getOp(), (IExpr) e.getMemValue()), Tag.Linux.MO_RELAXED));
}
use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeThreadCF.
private BooleanFormula encodeThreadCF(Thread thread, SolverContext ctx) {
checkInitialized();
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
BiFunction<BooleanFormula, BooleanFormula, BooleanFormula> cfEncoder = shouldAllowPartialExecutions ? bmgr::implication : bmgr::equivalence;
Map<Label, Set<Event>> labelJumpMap = new HashMap<>();
Event pred = null;
for (Event e : thread.getEntry().getSuccessors()) {
// Immediate control flow
BooleanFormula cfCond = pred == null ? bmgr.makeTrue() : pred.cf();
if (pred instanceof CondJump) {
CondJump jump = (CondJump) pred;
cfCond = bmgr.and(cfCond, bmgr.not(jump.getGuard().toBoolFormula(jump, ctx)));
// NOTE: we need to register the actual jumps here, because the
// listener sets of labels is too large (it contains old copies)
labelJumpMap.computeIfAbsent(jump.getLabel(), key -> new HashSet<>()).add(jump);
}
// Control flow via jumps
if (e instanceof Label) {
for (Event jump : labelJumpMap.getOrDefault(e, Collections.emptySet())) {
CondJump j = (CondJump) jump;
cfCond = bmgr.or(cfCond, bmgr.and(j.cf(), j.getGuard().toBoolFormula(j, ctx)));
}
}
enc = bmgr.and(enc, cfEncoder.apply(e.cf(), cfCond), e.encodeExec(ctx));
pred = e;
}
return enc;
}
use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeDependencies.
/**
* @param ctx
* Builder of expressions and formulas.
* @return
* Describes that for each pair of events, if the reader uses the result of the writer,
* then the value the reader gets from the register is exactly the value that the writer computed.
* Also, the reader may only use the value of the latest writer that is executed.
* Also, if no fitting writer is executed, the reader uses 0.
*/
public BooleanFormula encodeDependencies(SolverContext ctx) {
logger.info("Encoding dependencies");
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
for (Map.Entry<Event, Map<Register, Dependency.State>> e : dep.getAll()) {
Event reader = e.getKey();
for (Map.Entry<Register, Dependency.State> r : e.getValue().entrySet()) {
Formula value = r.getKey().toIntFormula(reader, ctx);
Dependency.State state = r.getValue();
BooleanFormula overwrite = bmgr.makeFalse();
for (Event writer : reverse(state.may)) {
assert writer instanceof RegWriter;
BooleanFormula edge;
if (state.must.contains(writer)) {
edge = writer.exec();
} else {
edge = dependencyEdgeVariable(writer, reader, bmgr);
enc = bmgr.and(enc, bmgr.equivalence(edge, bmgr.and(writer.exec(), reader.cf(), bmgr.not(overwrite))));
}
enc = bmgr.and(enc, bmgr.implication(edge, generalEqual(value, ((RegWriter) writer).getResultRegisterExpr(), ctx)));
overwrite = bmgr.or(overwrite, writer.exec());
}
if (initializeRegisters && !state.initialized) {
enc = bmgr.and(enc, bmgr.or(overwrite, bmgr.not(reader.cf()), generalEqualZero(value, ctx)));
}
}
}
return enc;
}
Aggregations