use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class BranchEquivalence method run.
private void run() {
Map<Thread, Map<Event, Branch>> threadBranches = new HashMap<>();
for (Thread t : program.getThreads()) {
// Step (1)
Map<Event, Branch> branchMap = new HashMap<>();
Map<Event, Branch> finalBranchMap = new HashMap<>();
threadBranches.put(t, branchMap);
computeBranches(t.getEntry(), branchMap, finalBranchMap);
// Step (2)-(3)
for (Branch b : branchMap.values()) {
computeMustPredSet(b);
computeMustSuccSet(b);
computeReachableBranches(b);
}
// Step (4)-(5)
createBranchClasses(branchMap);
}
// Step (6)
mergeInitialClasses();
// Step (7)
computeUnreachableClass();
// Bonus
computeExclusiveClasses(threadBranches);
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class Dependency method process.
private void process(Thread thread, ExecutionAnalysis exec) {
Map<Event, Set<Writer>> jumps = new HashMap<>();
Set<Writer> state = new HashSet<>();
for (Register register : thread.getRegisters()) {
state.add(new Writer(register, null));
}
for (Event event : thread.getEvents()) {
// merge with incoming jumps
Set<Writer> j = jumps.remove(event);
if (j != null) {
state.addAll(j);
}
// collecting dependencies, mixing 'data' and 'addr'
Set<Register> registers = new HashSet<>();
if (event instanceof RegReaderData) {
registers.addAll(((RegReaderData) event).getDataRegs());
}
if (event instanceof MemEvent) {
registers.addAll(((MemEvent) event).getAddress().getRegs());
}
if (!registers.isEmpty()) {
Map<Register, State> result = new HashMap<>();
for (Register register : registers) {
if (register.getThreadId() == Register.NO_THREAD) {
continue;
}
State writers;
if (register.getThreadId() != event.getThread().getId()) {
writers = finalWriters.get(register);
checkArgument(writers != null, "Helper thread %s should be listed after their creator thread %s.", thread.getId(), register.getThreadId());
if (writers.may.size() != 1) {
logger.warn("Writers {} for inter-thread register {} read by event {} of thread {}", writers.may, register, event, thread.getId());
}
} else {
writers = process(state, register, exec);
if (!writers.initialized) {
logger.warn("Uninitialized register {} read by event {} of thread {}", register, event, thread.getId());
}
}
result.put(register, writers);
}
map.put(event, result);
}
// update state, if changed by event
if (event instanceof RegWriter) {
Register register = ((RegWriter) event).getResultRegister();
if (event.cfImpliesExec()) {
state.removeIf(e -> e.register.equals(register));
}
state.add(new Writer(register, event));
}
// copy state, if branching
if (event instanceof CondJump) {
jumps.computeIfAbsent(((CondJump) event).getLabel(), k -> new HashSet<>()).addAll(state);
if (((CondJump) event).isGoto()) {
state.clear();
}
}
}
if (!jumps.isEmpty()) {
logger.warn("Thread {} contains jumps to removed labels {}", thread.getId(), jumps.keySet());
for (Set<Writer> j : jumps.values()) {
state.addAll(j);
}
}
for (Register register : thread.getRegisters()) {
finalWriters.put(register, process(state, register, exec));
}
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class EventCache method getEvents.
public ImmutableList<Event> getEvents(FilterAbstract filter) {
if (!events.containsKey(filter)) {
ImmutableList.Builder<Event> builder = new ImmutableList.Builder<>();
for (Event e : getEvents(FilterBasic.get(Tag.ANY))) {
if (filter.filter(e)) {
builder.add(e);
}
}
events.put(filter, builder.build());
}
return events.get(filter);
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ProgramBuilder method buildInitThreads.
private void buildInitThreads() {
int nextThreadId = nextThreadId();
for (MemoryObject a : memory.getObjects()) {
for (int i = 0; i < a.size(); i++) {
Event e = EventFactory.newInit(a, i);
Thread thread = new Thread(nextThreadId, e);
threads.put(nextThreadId, thread);
nextThreadId++;
}
}
}
use of com.dat3m.dartagnan.program.event.core.Event in project Dat3M by hernanponcedeleon.
the class ProgramBuilder method validateLabels.
private void validateLabels(Thread thread) throws MalformedProgramException {
Map<String, Label> threadLabels = new HashMap<>();
Set<String> referencedLabels = new HashSet<>();
Event e = thread.getEntry();
while (e != null) {
if (e instanceof CondJump) {
referencedLabels.add(((CondJump) e).getLabel().getName());
} else if (e instanceof Label) {
Label label = labels.remove(((Label) e).getName());
if (label == null) {
throw new MalformedProgramException("Duplicated label " + ((Label) e).getName());
}
threadLabels.put(label.getName(), label);
}
e = e.getSuccessor();
}
for (String labelName : referencedLabels) {
if (!threadLabels.containsKey(labelName)) {
throw new MalformedProgramException("Illegal jump to label " + labelName);
}
}
}
Aggregations