Skip to content

Commit

Permalink
Modified how to handle phi definition id
Browse files Browse the repository at this point in the history
Signed-off-by: Tianrui Zheng <tianrui.zheng@huawei.com>
  • Loading branch information
Tianrui Zheng committed Nov 11, 2024
1 parent d9b7868 commit 30cd0a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Event visitOpPhi(SpirvParser.OpPhiContext ctx) {
String labelId = pCtx.idRef(1).getText();
String expressionId = pCtx.idRef(0).getText();
cfBuilder.addPhiDefinition(labelId, register, expressionId);
cfBuilder.setPhiId(labelId, register, expressionId, id);
cfBuilder.setPhiId(labelId, register, id);
}
builder.addExpression(id, register);
cfBuilder.setPhiLocation(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ControlFlowBuilder {
protected final Deque<String> blockStack = new ArrayDeque<>();
protected final Map<String, Map<Register, String>> phiDefinitions = new HashMap<>();
protected final Map<String, SourceLocation> phiDefinitionLocations = new HashMap<>();
protected final Map<Set<Object>, String> phiDefinitionIds = new HashMap<>();
protected final Map<String, Map<Register, String>> phiDefinitionIds = new HashMap<>();
protected final Map<String, Expression> expressions;
protected SourceLocation currentLocation;

Expand All @@ -40,8 +40,7 @@ public void build() {
phiDefinitions.forEach((blockId, def) ->
def.forEach((k, v) -> {
Event event = EventFactory.newLocal(k, expressions.get(v));
Set<Object> definition = Set.of(blockId, k, v);
SourceLocation loc = getPhiLocation(definition);
SourceLocation loc = getPhiLocation(blockId, k);
if (loc != null) { event.setMetadata(loc); }
lastBlockEvents.get(blockId).getPredecessor().insertAfter(event);
}));
Expand Down Expand Up @@ -103,12 +102,15 @@ public void setPhiLocation(String id) {
}
}

public void setPhiId(String blockId, Register register, String expressionId, String id) {
Set<Object> definition = Set.of(blockId, register, expressionId);
if (phiDefinitionIds.containsKey(definition)) {
throw new ParsingException("Already set id for the Phi definition");
public void setPhiId(String blockId, Register register, String id) {
phiDefinitionIds.putIfAbsent(blockId, new HashMap<>());
String phiId = phiDefinitionIds.get(blockId).get(register);
if (phiId != null) {
throw new ParsingException(
"Already set id %s for the Phi definition in the block %s", phiId, blockId);
} else {
phiDefinitionIds.get(blockId).put(register, id);
}
phiDefinitionIds.put(definition, id);
}

private void validateBeforeBuild() {
Expand Down Expand Up @@ -141,9 +143,9 @@ private Label createLabel(String id) {
return getOrCreateLabel(id);
}

private SourceLocation getPhiLocation(Set<Object> definition) {
String id = phiDefinitionIds.get(definition);
if (phiDefinitionLocations.containsKey(id)) {
private SourceLocation getPhiLocation(String blockId, Register register) {
String id = phiDefinitionIds.get(blockId).get(register);
if (id != null) {
return phiDefinitionLocations.get(id);
}
return null;
Expand Down

0 comments on commit 30cd0a0

Please sign in to comment.