use of com.dat3m.dartagnan.program.event.core.utils.RegWriter in project Dat3M by hernanponcedeleon.
the class BasicRegRelation method doEncodeApprox.
BooleanFormula doEncodeApprox(Collection<Event> regReaders, SolverContext ctx) {
FormulaManager fmgr = ctx.getFormulaManager();
BooleanFormulaManager bmgr = fmgr.getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
for (Event regReader : regReaders) {
Set<Tuple> writerReaders = maxTupleSet.getBySecond(regReader);
for (Register register : getRegisters(regReader)) {
List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
List<Event> possibleWriters = writers.stream().filter(x -> writerReaders.contains(new Tuple(x, regReader))).collect(Collectors.toList());
if (writers.isEmpty() || writers.get(0).getCId() >= regReader.getCId()) {
BooleanFormula equal = generalEqual(register.toIntFormula(regReader, ctx), new IValue(BigInteger.ZERO, register.getPrecision()).toIntFormula(ctx), ctx);
enc = bmgr.and(enc, equal);
} else {
for (int i = 0; i < possibleWriters.size(); i++) {
Event regWriter = possibleWriters.get(i);
// RegReader uses the value of RegWriter if it is executed ..
BooleanFormula clause = getExecPair(regWriter, regReader, ctx);
BooleanFormula edge = this.getSMTVar(regWriter, regReader, ctx);
// .. and no other write to the same register is executed in between
for (int j = i + 1; j < possibleWriters.size(); j++) {
clause = bmgr.and(clause, bmgr.not(possibleWriters.get(j).exec()));
}
// Encode edge and value binding
enc = bmgr.and(enc, bmgr.equivalence(edge, clause));
BooleanFormula equal = generalEqual(((RegWriter) regWriter).getResultRegisterExpr(), register.toIntFormula(regReader, ctx), ctx);
enc = bmgr.and(enc, bmgr.implication(edge, equal));
}
}
}
}
return enc;
}
use of com.dat3m.dartagnan.program.event.core.utils.RegWriter in project Dat3M by hernanponcedeleon.
the class BasicRegRelation method mkTupleSets.
void mkTupleSets(Collection<Event> regReaders) {
maxTupleSet = new TupleSet();
minTupleSet = new TupleSet();
ExecutionAnalysis exec = analysisContext.requires(ExecutionAnalysis.class);
ImmutableMap<Register, ImmutableList<Event>> regWriterMap = task.getProgram().getCache().getRegWriterMap();
for (Event regReader : regReaders) {
for (Register register : getRegisters(regReader)) {
List<Event> writers = regWriterMap.getOrDefault(register, ImmutableList.of());
// =============== Reduce set of writes ==================
// TODO: We assume that any Register-Write is always executed
// if it is contained in the program flow
// This may fail for RMWReadCond?! It seems to work fine for the litmus tests though.
// =========================
List<Event> possibleWriters = writers.stream().filter(x -> x.getCId() < regReader.getCId() && !exec.areMutuallyExclusive(x, regReader)).collect(Collectors.toList());
List<Event> impliedWriters = possibleWriters.stream().filter(x -> exec.isImplied(regReader, x)).collect(Collectors.toList());
if (!impliedWriters.isEmpty()) {
Event lastImplied = impliedWriters.get(impliedWriters.size() - 1);
possibleWriters.removeIf(x -> x.getCId() < lastImplied.getCId());
}
possibleWriters.removeIf(x -> possibleWriters.stream().anyMatch(y -> x.getCId() < y.getCId() && exec.isImplied(x, y)));
// --- Min sets ---
if (possibleWriters.size() == 1) {
// there is only a single regWriter
minTupleSet.add(new Tuple(possibleWriters.stream().findAny().get(), regReader));
} else {
// there are multiple regWriters, but some are exclusive to all others
for (Event writer : possibleWriters) {
if (possibleWriters.stream().allMatch(x -> x == writer || exec.areMutuallyExclusive(x, writer))) {
minTupleSet.add(new Tuple(writer, regReader));
}
}
}
// --- Max sets ---
for (Event regWriter : possibleWriters) {
maxTupleSet.add(new Tuple(regWriter, regReader));
}
}
}
}
use of com.dat3m.dartagnan.program.event.core.utils.RegWriter 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.utils.RegWriter 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.event.core.utils.RegWriter 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;
}
Aggregations