use of com.dat3m.dartagnan.expression.IExprBin in project Dat3M by hernanponcedeleon.
the class AndersenAliasAnalysis method processRegs.
private void processRegs(Program program) {
for (Event ev : program.getCache().getEvents(FilterBasic.get(Tag.LOCAL))) {
if (ev instanceof Local) {
Local e = (Local) ev;
Register register = e.getResultRegister();
ExprInterface expr = e.getExpr();
if (expr instanceof Register) {
// r1 = r2 -> add edge r2 --> r1
graph.addEdge(expr, register);
} else if (expr instanceof IExprBin && ((IExprBin) expr).getBase() instanceof Register) {
graph.addAllAddresses(register, maxAddressSet);
variables.add(register);
} else if (expr instanceof MemoryObject) {
// r = &a
graph.addAddress(register, new Location((MemoryObject) expr, 0));
variables.add(register);
}
// FIXME if the expression is too complicated, the register should receive maxAddressSet
}
}
}
use of com.dat3m.dartagnan.expression.IExprBin 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));
}
}
use of com.dat3m.dartagnan.expression.IExprBin in project Dat3M by hernanponcedeleon.
the class VisitorLitmusAArch64 method visitOffset.
private Register visitOffset(LitmusAArch64Parser.OffsetContext ctx, Register register) {
Register result = programBuilder.getOrCreateRegister(mainThread, null, ARCH_PRECISION);
IExpr expr = ctx.immediate() == null ? programBuilder.getOrErrorRegister(mainThread, ctx.expressionConversion().register32().id) : new IValue(new BigInteger(ctx.immediate().constant().getText()), ARCH_PRECISION);
programBuilder.addChild(mainThread, EventFactory.newLocal(result, new IExprBin(register, IOpBin.PLUS, expr)));
return result;
}
use of com.dat3m.dartagnan.expression.IExprBin in project Dat3M by hernanponcedeleon.
the class VisitorLitmusAArch64 method visitExpressionRegister32.
@Override
public IExpr visitExpressionRegister32(LitmusAArch64Parser.ExpressionRegister32Context ctx) {
IExpr expr = programBuilder.getOrCreateRegister(mainThread, ctx.register32().id, ARCH_PRECISION);
if (ctx.shift() != null) {
IValue val = new IValue(new BigInteger(ctx.shift().immediate().constant().getText()), ARCH_PRECISION);
expr = new IExprBin(expr, ctx.shift().shiftOperator().op, val);
}
return expr;
}
Aggregations