use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class FindSpinLoops method isSideEffectFree.
private boolean isSideEffectFree(Label loopBegin, CondJump loopEnd) {
Event cur = loopBegin.getSuccessor();
// Unsafe means the loop read from the registers before writing to them.
Set<Register> unsafeRegisters = new HashSet<>();
// Safe means the loop wrote to these register before using them
Set<Register> safeRegisters = new HashSet<>();
while (cur != loopEnd) {
if (cur instanceof MemEvent) {
if (cur.is(Tag.WRITE)) {
// Writes always cause side effects
return false;
}
MemEvent memEvent = (MemEvent) cur;
Set<Register> addrRegs = memEvent.getAddress().getRegs();
unsafeRegisters.addAll(Sets.difference(addrRegs, safeRegisters));
}
if (cur instanceof RegReaderData) {
RegReaderData reader = (RegReaderData) cur;
Set<Register> dataRegs = reader.getDataRegs();
unsafeRegisters.addAll(Sets.difference(dataRegs, safeRegisters));
}
if (cur instanceof RegWriter) {
RegWriter writer = (RegWriter) cur;
if (unsafeRegisters.contains(writer.getResultRegister())) {
return false;
} else {
safeRegisters.add(writer.getResultRegister());
}
}
cur = cur.getSuccessor();
}
return true;
}
use of com.dat3m.dartagnan.program.Register in project Dat3M by hernanponcedeleon.
the class FieldSensitiveAndersen method processRegs.
protected void processRegs(Local e) {
Register register = e.getResultRegister();
Collector collector = new Collector(e.getExpr());
addAllAddresses(register, collector.address());
for (Offset<Register> r : collector.register()) {
addEdge(r.base, register, r.offset, r.alignment);
}
}
use of com.dat3m.dartagnan.program.Register 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.Register 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.Register in project Dat3M by hernanponcedeleon.
the class AliasAnalysisTest method program0.
private void program0(Alias method, Result... expect) throws InvalidConfigurationException {
ProgramBuilder b = new ProgramBuilder();
MemoryObject x = b.newObject("x", 2);
MemoryObject y = b.getOrNewObject("y");
b.initThread(0);
Register r0 = b.getOrCreateRegister(0, "r0", -1);
// this is undefined behavior in C11
// the expression does not match a sum, but x occurs in it
b.addChild(0, newLocal(r0, mult(x, 1)));
Store e0 = newStore(r0);
b.addChild(0, e0);
Store e1 = newStore(plus(r0, 1));
b.addChild(0, e1);
Store e2 = newStore(x);
b.addChild(0, e2);
Store e3 = newStore(y);
b.addChild(0, e3);
AliasAnalysis a = analyze(b, method);
// precisely no
assertAlias(expect[0], a, e0, e1);
assertAlias(expect[1], a, e0, e2);
assertAlias(expect[2], a, e1, e2);
assertAlias(expect[3], a, e0, e3);
assertAlias(expect[4], a, e1, e3);
assertAlias(expect[5], a, e2, e3);
}
Aggregations