Refactor EventFactory, Compilers and Parsers#1009
Conversation
|
@xeren can you please rebase and fix the conflicts? |
…actory # Conflicts: # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusAArch64.java # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusC.java # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusPPC.java # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusPTX.java # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusRISCV.java # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusVulkan.java # dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusX86.java # dartagnan/src/test/java/com/dat3m/dartagnan/others/miscellaneous/AnalysisTest.java
hernanponcedeleon
left a comment
There was a problem hiding this comment.
Why are you adding newRMWLoadExclusive for each arch if they all end up calling the general case? While I could see an argument in the factory for having the method for each arch, we do have other "common" events that use a single method, e.g. newRMWStoreExclusiveWithMo
| AArch64.DSB.newISHLDBarrier() : | ||
| null; | ||
| Event fence = switch (e.getMo()) { | ||
| case Tag.C11.MO_RELEASE, Tag.C11.MO_SC -> AArch64.newDmbIshBarrier(); |
There was a problem hiding this comment.
You are missing the mo.equals(C11.MO_ACQUIRE_RELEASE) case
I agree with you but maybe from a different point of view. I think it becomes more and more unclear of whether a (*) It is fine to generate core events from the parser, but not if you intend to support compilation to other targets on those events (at least in our current architecture). |
|
With the different |
| private Expression addCmpXchg(Register register, Expression address, Expression expectedAddress, Expression value, | ||
| String mo, boolean strong, OpenCLScopeContext scope, ParserRuleContext ctx) { | ||
| final Event event = EventFactory.Atomic.newCompareExchange(register, address, expectedAddress, value, mo, strong); | ||
| addScopeTag(event, scope); | ||
| append(event, ctx); | ||
| return register; |
There was a problem hiding this comment.
I suggest to not return the register as it is totally unclear why this function should do that.
I would rather have the call-sites explicitly returning the register.
| private Object append(Event event, ParserRuleContext ctx) { | ||
| final int line = ctx.getStart().getLine(); | ||
| return programBuilder.addChild(currentThread, event, line); | ||
| } |
There was a problem hiding this comment.
The return type should be as specific as possible, i.e., Event.
| private Object append(Event event, ParserRuleContext ctx) { | ||
| return programBuilder.addChild(mainThread, event, ctx.getStart().getLine()); | ||
| } |
| private Object append(Event event, ParserRuleContext ctx) { | ||
| return programBuilder.addChild(mainThread, event, ctx.getStart().getLine()); | ||
| } |
| private Object append(Event event, ParserRuleContext ctx) { | ||
| return programBuilder.addChild(mainThread, event, ctx.getStart().getLine()); | ||
| } |
| public static GenericVisibleEvent newThreadFenceAcquire() { | ||
| return newThreadFence(Tag.C11.MO_ACQUIRE); | ||
| } | ||
|
|
||
| public static GenericVisibleEvent newThreadFenceRelease() { | ||
| return newThreadFence(Tag.C11.MO_RELEASE); | ||
| } | ||
|
|
||
| public static GenericVisibleEvent newThreadFenceAcquireRelease() { | ||
| return newThreadFence(Tag.C11.MO_ACQUIRE_RELEASE); | ||
| } | ||
|
|
||
| public static GenericVisibleEvent newThreadFenceSequentiallyConsistent() { | ||
| return newThreadFence(Tag.C11.MO_SC); | ||
| } |
There was a problem hiding this comment.
I don't see much benefit in these 4 functions. They are not really much cleaner just than calling newThreadFence(Tag.C11.MO_XYZ)
| Register statusReg = strong ? null : e.getFunction().newRegister("status(" + e.getLocalId() + ")", types.getBooleanType()); | ||
| ExecutionStatus optionalExecStatus = strong ? null : newExecutionStatus(statusReg, storeValue); | ||
| Local optionalUpdateCasCmpResult = strong ? null : newLocal(booleanResultRegister, expressions.makeNot(statusReg)); |
There was a problem hiding this comment.
Just FYI, eventSequence can actually take nested lists as input and it will flatten them.
So one could write:
List<Event> optional = strong ? List.of() : List.of(
newExectutionStatus(...),
newLocal(...)
);and then use the optional list as input to eventSequence. I don't know whether it's cleaner though.
Actually, I originally added this feature because I wanted to use it for fake control dependencies, where newFakeCtrlDep(Register reg) would return both the jump and the label... Well, we never used this feature and I believe that, except for me, probably no one knew that eventSequence could do this :P.
| Event optionalBarrierBefore = switch (e.getMo()) { | ||
| case C11.MO_SC -> leadingSync() ? newSync() : newLwSync(); | ||
| case C11.MO_RELEASE -> newLwSync(); | ||
| default -> null; | ||
| }; |
There was a problem hiding this comment.
You added optionalBarrierBefore/After methods that you could use here.
I think you decided halfway during the changes to add the helper function but forgot to use it for the already changed code :P
| Load load = newRMWLoadExclusive(dummy, address, ""); | ||
| Local localOp = newLocal(dummy, expressions.makeIntBinary(dummy, e.getOperator(), e.getOperand())); | ||
| Store store = newRMWStoreExclusiveWithMo(address, dummy, true, mo.equals(Tag.Linux.MO_MB) ? Tag.RISCV.MO_REL : ""); | ||
| Store store = newRMWStoreExclusiveWithMo(address, dummy, true, false, storeMo); |
There was a problem hiding this comment.
This should be a newRMWStoreConditional, no?
| newAssume(expressions.makeEQ(dummy, zero)), | ||
| newRMWStoreExclusive(e.getLock(), one, true), | ||
| RISCV.newRRWFence() | ||
| newRMWStoreExclusive(e.getLock(), one, true, false), |
There was a problem hiding this comment.
Same here: conditional store
Mostly cleans up some imports, but also
ProgramBuilder.addChildin litmus parsers.FenceNameRepositoryintoEventFactoryModifications to
EventFactoryAdded
AArch64.newRMWLoadExclusive,AArch64.newRMWStoreExclusiveX86.newLoadFence,newStoreFence(still not implemented, but merges two places)RISCV.newRMWLoadExclusivePower.newRMWLoadExclusiveModified
newRMWStoreExclusive,newRMWStoreExclusiveWithMoAArch64.newDmbBarrier, etc.AArch64.newBarrier(String,String)(moved fromnewFenceOpt)RISCV.newRMWStoreConditional