use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class VisitorNone method visitRMWXchg.
@Override
public List<Event> visitRMWXchg(RMWXchg e) {
Register resultRegister = e.getResultRegister();
String mo = e.getMo();
IExpr address = e.getAddress();
Register dummy = resultRegister;
if (resultRegister == e.getMemValue()) {
dummy = new Register(null, resultRegister.getThreadId(), resultRegister.getPrecision());
}
Fence optionalMbBefore = mo.equals(Tag.Linux.MO_MB) ? Linux.newMemoryBarrier() : null;
Load load = newRMWLoad(dummy, address, Tag.Linux.loadMO(mo));
Local optionalUpdateReg = dummy != resultRegister ? newLocal(resultRegister, dummy) : null;
Fence optionalMbAfter = mo.equals(Tag.Linux.MO_MB) ? Linux.newMemoryBarrier() : null;
return eventSequence(optionalMbBefore, load, newRMWStore(load, address, e.getMemValue(), Tag.Linux.storeMO(mo)), optionalUpdateReg, optionalMbAfter);
}
use of com.dat3m.dartagnan.program.Register 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.Register in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method dependencyEdge.
/**
* @param writer
* Overwrites some register.
* @param reader
* Happens on the same thread as {@code writer} and could use its value,
* meaning that {@code writer} appears in {@code may(reader,R)} for some register {@code R}.
* @param ctx
* Builder of expressions and formulas.
* @return
* Proposition that {@code reader} directly uses the value from {@code writer}, if both are executed.
* Contextualized with the result of {@link #encodeDependencies(SolverContext) encode}.
*/
public BooleanFormula dependencyEdge(Event writer, Event reader, SolverContext ctx) {
Preconditions.checkArgument(writer instanceof RegWriter);
Register register = ((RegWriter) writer).getResultRegister();
Dependency.State r = dep.of(reader, register);
Preconditions.checkArgument(r.may.contains(writer));
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
return r.must.contains(writer) ? execution(writer, reader, exec, ctx) : dependencyEdgeVariable(writer, reader, bmgr);
}
use of com.dat3m.dartagnan.program.Register 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.Register in project Dat3M by hernanponcedeleon.
the class VisitorLitmusC method visitReCast.
@Override
public ExprInterface visitReCast(LitmusCParser.ReCastContext ctx) {
Register register = getReturnRegister(false);
ExprInterface result = (ExprInterface) ctx.re().accept(this);
return assignToReturnRegister(register, result);
}
Aggregations