use of com.dat3m.dartagnan.expression.ExprInterface in project Dat3M by hernanponcedeleon.
the class AndersenAliasAnalysis method processLocs.
private void processLocs(Program program) {
for (Event ev : program.getCache().getEvents(FilterBasic.get(Tag.MEMORY))) {
MemEvent e = (MemEvent) ev;
IExpr address = e.getAddress();
// Collect for each v events of form: p = *v, *v = q
if (address instanceof Register) {
graph.addEvent((Register) address, e);
continue;
}
Constant addressConstant = new Constant(address);
if (addressConstant.failed) {
// r = *(CompExpr) -> loc(r) = max
if (e instanceof RegWriter) {
Register register = ((RegWriter) e).getResultRegister();
graph.addAllAddresses(register, maxAddressSet);
variables.add(register);
}
// FIXME if e is a store event, then all locations should include its values
eventAddressSpaceMap.put(e, maxAddressSet);
continue;
}
// address is a constant
Location location = addressConstant.location;
if (location == null) {
throw new RuntimeException("memory event accessing a pure constant address");
}
eventAddressSpaceMap.put(e, ImmutableSet.of(location));
if (e instanceof RegWriter) {
graph.addEdge(location, ((RegWriter) e).getResultRegister());
continue;
}
// event is a store operation
Verify.verify(e.is(Tag.WRITE), "memory event that is neither tagged \"W\" nor a register writer");
ExprInterface value = e.getMemValue();
if (value instanceof Register) {
graph.addEdge(value, location);
continue;
}
Constant v = new Constant(value);
if (v.failed) {
graph.addAllAddresses(location, maxAddressSet);
} else if (v.location != null) {
graph.addAddress(location, v.location);
}
variables.add(location);
}
}
use of com.dat3m.dartagnan.expression.ExprInterface in project Dat3M by hernanponcedeleon.
the class AndersenAliasAnalysis method processResults.
private void processResults(Program program) {
// Used to have pointer analysis when having arrays and structures
Map<Register, Set<Location>> targets = new HashMap<>();
BiConsumer<Register, Location> addTarget = (r, l) -> targets.put(r, Set.of(l));
BiConsumer<Register, MemoryObject> addTargetArray = (r, b) -> targets.put(r, IntStream.range(0, b.size()).mapToObj(i -> new Location(b, i)).collect(Collectors.toSet()));
for (Event ev : program.getCache().getEvents(FilterBasic.get(Tag.LOCAL))) {
// Not only Local events have EType.LOCAL tag
if (!(ev instanceof Local)) {
continue;
}
Local l = (Local) ev;
ExprInterface exp = l.getExpr();
Register reg = l.getResultRegister();
if (exp instanceof MemoryObject) {
addTarget.accept(reg, new Location((MemoryObject) exp, 0));
} else if (exp instanceof IExprBin) {
IExpr base = ((IExprBin) exp).getBase();
if (base instanceof MemoryObject) {
IExpr rhs = ((IExprBin) exp).getRHS();
// FIXME Address extends IConst
if (rhs instanceof IConst) {
addTarget.accept(reg, new Location((MemoryObject) base, ((IConst) rhs).getValueAsInt()));
} else {
addTargetArray.accept(reg, (MemoryObject) base);
}
continue;
}
if (!(base instanceof Register)) {
continue;
}
// accept register2 = register1 + constant
for (Location target : targets.getOrDefault(base, Set.of())) {
IExpr rhs = ((IExprBin) exp).getRHS();
// FIXME Address extends IConst
if (rhs instanceof IConst) {
int o = target.offset + ((IConst) rhs).getValueAsInt();
if (o < target.base.size()) {
addTarget.accept(reg, new Location(target.base, o));
}
} else {
addTargetArray.accept(reg, target.base);
}
}
}
}
for (Event e : program.getCache().getEvents(FilterBasic.get(Tag.MEMORY))) {
IExpr address = ((MemEvent) e).getAddress();
Set<Location> addresses;
if (address instanceof Register) {
Set<Location> target = targets.get(address);
if (target != null) {
addresses = target;
} else {
addresses = graph.getAddresses(address);
}
} else {
Constant addressConstant = new Constant(address);
if (addressConstant.failed) {
addresses = maxAddressSet;
} else {
Verify.verify(addressConstant.location != null, "memory event accessing a pure constant address");
addresses = ImmutableSet.of(addressConstant.location);
}
}
if (addresses.size() == 0) {
addresses = maxAddressSet;
}
eventAddressSpaceMap.put((MemEvent) e, ImmutableSet.copyOf(addresses));
}
}
Aggregations