use of com.dat3m.dartagnan.program.event.arch.aarch64.StoreExclusive in project Dat3M by hernanponcedeleon.
the class ConstantPropagation method getSimplifiedCopy.
// Creates a copy of the provided event, using the <propagationMap> to simplify expressions.
// Can return the original event if no simplifications are performed
private Event getSimplifiedCopy(Event ev, Map<Register, IExpr> propagationMap) {
Event copy = ev;
if (ev instanceof MemEvent && !ev.is(Tag.C11.PTHREAD) && !ev.is(Tag.C11.LOCK)) {
MemEvent m = (MemEvent) ev;
String mo = m.getMo();
// All events for which we use reg are RegWriters
Register reg = ev instanceof RegWriter ? ((RegWriter) ev).getResultRegister() : null;
IExpr oldAddress = m.getAddress();
IExpr newAddress = evaluate(oldAddress, propagationMap);
newAddress = newAddress instanceof ITop ? oldAddress : newAddress;
Verify.verifyNotNull(newAddress, "Expression %s got no value after constant propagation analysis", oldAddress);
IExpr oldValue = (IExpr) ((MemEvent) ev).getMemValue();
IExpr newValue = evaluate(oldValue, propagationMap);
newValue = newValue instanceof ITop ? oldValue : newValue;
Verify.verifyNotNull(newValue, "Expression %s got no value after constant propagation analysis", oldValue);
// Atomic Events
if (ev instanceof AtomicLoad) {
copy = Atomic.newLoad(reg, newAddress, mo);
} else if (ev instanceof AtomicStore) {
copy = Atomic.newStore(newAddress, newValue, mo);
} else if (ev instanceof AtomicCmpXchg) {
IExpr oldExpectedAddr = ((AtomicCmpXchg) ev).getExpectedAddr();
IExpr newExpectedAddr = evaluate(oldExpectedAddr, propagationMap);
Verify.verifyNotNull(newExpectedAddr, "Register %s got no value after constant propagation analysis", oldExpectedAddr);
copy = Atomic.newCompareExchange(reg, newAddress, newExpectedAddr, newValue, mo, ev.is(Tag.STRONG));
} else if (ev instanceof AtomicXchg) {
copy = Atomic.newExchange(reg, newAddress, newValue, mo);
} else if (ev instanceof AtomicFetchOp) {
copy = Atomic.newFetchOp(reg, newAddress, newValue, ((AtomicFetchOp) ev).getOp(), mo);
} else // Linux Events
if (ev instanceof RMWAddUnless) {
copy = Linux.newRMWAddUnless(newAddress, reg, ((RMWAddUnless) ev).getCmp(), newValue);
} else if (ev instanceof RMWCmpXchg) {
copy = Linux.newRMWCompareExchange(newAddress, reg, ((RMWCmpXchg) ev).getCmp(), newValue, mo);
} else if (ev instanceof RMWFetchOp) {
copy = Linux.newRMWFetchOp(newAddress, reg, newValue, ((RMWFetchOp) ev).getOp(), mo);
} else if (ev instanceof RMWOp) {
copy = Linux.newRMWOp(newAddress, reg, newValue, ((RMWOp) ev).getOp());
} else if (ev instanceof RMWOpAndTest) {
copy = Linux.newRMWOpAndTest(newAddress, reg, newValue, ((RMWOpAndTest) ev).getOp());
} else if (ev instanceof RMWOpReturn) {
copy = Linux.newRMWOpReturn(newAddress, reg, newValue, ((RMWOpReturn) ev).getOp(), mo);
} else if (ev instanceof RMWXchg) {
copy = Linux.newRMWExchange(newAddress, reg, newValue, mo);
} else // Exclusive events
if (ev.is(Tag.EXCL)) {
if (ev instanceof Load) {
copy = EventFactory.newRMWLoadExclusive(reg, newAddress, mo);
} else if (ev instanceof StoreExclusive) {
copy = AArch64.newExclusiveStore(reg, newAddress, newValue, mo);
} else {
// Other EXCL events are generated during compilation (which have not yet occurred)
throw new UnsupportedOperationException(String.format("Exclusive event %s not supported by %s", ev.getClass().getSimpleName(), getClass().getSimpleName()));
}
} else // Basic Events
if (ev instanceof Load) {
copy = EventFactory.newLoad(reg, newAddress, mo);
} else if (ev instanceof Store) {
copy = EventFactory.newStore(newAddress, newValue, mo);
}
} else // Local.initialise() which is never the case for the new Event e below.
if (ev instanceof Local && ((Local) ev).getExpr() instanceof IExpr && !ev.is(Tag.ASSERTION)) {
Register reg = ((Local) ev).getResultRegister();
IExpr oldValue = (IExpr) ((Local) ev).getExpr();
IExpr newValue = evaluate(oldValue, propagationMap);
newValue = newValue instanceof ITop ? oldValue : newValue;
Verify.verify(newValue != null, String.format("Expression %s got no value after constant propagation analysis", oldValue));
copy = EventFactory.newLocal(reg, newValue);
}
if (copy != ev) {
// We made a real copy
copy.setOId(ev.getOId());
copy.setUId(ev.getUId());
copy.setCId(ev.getCId());
copy.setCLine(ev.getCLine());
copy.setThread(ev.getThread());
}
return copy;
}
use of com.dat3m.dartagnan.program.event.arch.aarch64.StoreExclusive in project Dat3M by hernanponcedeleon.
the class VisitorLitmusAArch64 method visitStoreExclusive.
@Override
public Object visitStoreExclusive(LitmusAArch64Parser.StoreExclusiveContext ctx) {
Register register = programBuilder.getOrCreateRegister(mainThread, ctx.rV, ARCH_PRECISION);
Register statusReg = programBuilder.getOrCreateRegister(mainThread, ctx.rS, ARCH_PRECISION);
Register address = programBuilder.getOrErrorRegister(mainThread, ctx.address().id);
if (ctx.offset() != null) {
address = visitOffset(ctx.offset(), address);
}
StoreExclusive event = EventFactory.AArch64.newExclusiveStore(statusReg, address, register, ctx.storeExclusiveInstruction().mo);
return programBuilder.addChild(mainThread, event);
}
Aggregations