use of com.dat3m.dartagnan.program.Thread 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.Thread in project Dat3M by hernanponcedeleon.
the class ProgramEncoder method encodeControlFlow.
public BooleanFormula encodeControlFlow(SolverContext ctx) {
checkInitialized();
logger.info("Encoding program control flow");
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
for (Thread t : program.getThreads()) {
enc = bmgr.and(enc, encodeThreadCF(t, ctx));
}
return enc;
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class SymmetryEncoder method encodeSymmetryClass.
public BooleanFormula encodeSymmetryClass(EquivalenceClass<Thread> symmClass, SolverContext ctx) {
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula enc = bmgr.makeTrue();
if (rel == null || symmClass.getEquivalence() != symm) {
return enc;
}
Thread rep = symmClass.getRepresentative();
List<Thread> symmThreads = new ArrayList<>(symmClass);
symmThreads.sort(Comparator.comparingInt(Thread::getId));
// ===== Construct row =====
// IMPORTANT: Each thread writes to its own special location for the purpose of starting/terminating threads
// These need to get skipped.
Thread t1 = symmThreads.get(0);
List<Tuple> r1Tuples = new ArrayList<>();
for (Tuple t : rel.getMaxTupleSet()) {
Event a = t.getFirst();
Event b = t.getSecond();
if (!a.is(Tag.C11.PTHREAD) && !b.is(Tag.C11.PTHREAD) && a.getThread() == t1) {
r1Tuples.add(t);
}
}
sort(r1Tuples);
// Construct symmetric rows
for (int i = 1; i < symmThreads.size(); i++) {
Thread t2 = symmThreads.get(i);
Function<Event, Event> p = symm.createTransposition(t1, t2);
List<Tuple> r2Tuples = r1Tuples.stream().map(t -> t.permute(p)).collect(Collectors.toList());
List<BooleanFormula> r1 = Lists.transform(r1Tuples, t -> rel.getSMTVar(t, ctx));
List<BooleanFormula> r2 = Lists.transform(r2Tuples, t -> rel.getSMTVar(t, ctx));
final String id = "_" + rep.getId() + "_" + i;
// r1 >= r2
enc = bmgr.and(enc, encodeLexLeader(id, r2, r1, ctx));
t1 = t2;
r1Tuples = r2Tuples;
}
return enc;
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class VerificationTask method performStaticProgramAnalyses.
public void performStaticProgramAnalyses() throws InvalidConfigurationException {
analysisContext.register(BranchEquivalence.class, BranchEquivalence.fromConfig(program, config));
analysisContext.register(ExecutionAnalysis.class, ExecutionAnalysis.fromConfig(program, analysisContext, config));
analysisContext.register(Dependency.class, Dependency.fromConfig(program, analysisContext, config));
analysisContext.register(AliasAnalysis.class, AliasAnalysis.fromConfig(program, config));
analysisContext.register(ThreadSymmetry.class, ThreadSymmetry.fromConfig(program, config));
for (Thread thread : program.getThreads()) {
for (Event e : thread.getEvents()) {
// Some events perform static analyses by themselves (e.g. Svcomp's EndAtomic)
// which may rely on previous "global" analyses
e.runLocalAnalysis(program, analysisContext);
}
}
}
use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.
the class Printer method print.
public String print(Program program) {
result = new StringBuilder();
padding = new StringBuilder(paddingBase);
IDType origType = idType;
idType = resolveIDType(program);
String name = program.getName();
if (name == null) {
name = "program";
}
result.append(name).append("\n");
for (Thread thread : program.getThreads()) {
if (shouldPrintThread(thread)) {
appendThread(thread);
}
}
idType = origType;
return result.toString();
}
Aggregations