Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzun66 committed Oct 30, 2024
1 parent f9cfe32 commit 4a1107f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ protected boolean isMergeable(
}
// if we are here the datastructure should have managed that the next if is true..
final List<MutableBasicBlock> sBlockPredecessors = followingBlock.getPredecessors();
if (sBlockPredecessors.size() > 1 || (sBlockPredecessors.size()==1 && sBlockPredecessors.get(0) != firstBlock)) {
if (sBlockPredecessors.size() > 1
|| (sBlockPredecessors.size() == 1 && sBlockPredecessors.get(0) != firstBlock)) {
return false;
}
// check if the same traps are applied to both blocks
Expand Down Expand Up @@ -1128,7 +1129,7 @@ public BasicBlock<?> insertBefore(
}
}

private void checkAndResetStartingStmt(Stmt beforeStmt, List<FallsThroughStmt> stmts){
private void checkAndResetStartingStmt(Stmt beforeStmt, List<FallsThroughStmt> stmts) {
if (beforeStmt == getStartingStmt()) {
setStartingStmt(stmts.get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view)
// delete meaningless phiStmts and add other phiStmts into stmtGraph
addPhiStmts(blockToPhiStmts, stmtGraph, blockToDefs);

//some blocks are modified, so DominanceFinder must be updated for building dominance tree
// some blocks are modified, so DominanceFinder must be updated for building dominance tree
DominanceTree tree = new DominanceTree(new DominanceFinder(stmtGraph));

Map<Local, Stack<Local>> localToNameStack = new HashMap<>();
Expand Down Expand Up @@ -312,14 +312,14 @@ private void addPhiStmts(
}
for (FallsThroughStmt phi : phis) {
BasicBlock<?> updatedBlock = blockGraph.insertBefore(block.getHead(), phi);
if(!updatedBlock.equals(block)){
if (!updatedBlock.equals(block)) {
old2UpdatedBlock.put(block, updatedBlock);
}
}
}
//update new blocks in blockToPhiStmts
if(!old2UpdatedBlock.isEmpty()){
for(BasicBlock<?> oldB : old2UpdatedBlock.keySet()){
// update new blocks in blockToPhiStmts
if (!old2UpdatedBlock.isEmpty()) {
for (BasicBlock<?> oldB : old2UpdatedBlock.keySet()) {
Set<FallsThroughStmt> phis = blockToPhiStmts.get(oldB);
blockToPhiStmts.remove(oldB);
blockToPhiStmts.put(old2UpdatedBlock.get(oldB), phis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ public class StaticSingleAssignmentFormerTest {
Local stack4 = JavaJimple.newLocal("stack4", refType);

JIdentityStmt startingStmt = JavaJimple.newIdentityStmt(l0, identityRef, noStmtPositionInfo);
JAssignStmt assign1tol1 = JavaJimple.newAssignStmt(l1, IntConstant.getInstance(1), noStmtPositionInfo);
JAssignStmt assign1tol2 = JavaJimple.newAssignStmt(l2, IntConstant.getInstance(2), noStmtPositionInfo);
JAssignStmt assign0tol3 = JavaJimple.newAssignStmt(l3, IntConstant.getInstance(0), noStmtPositionInfo);
JAssignStmt assign1tol1 =
JavaJimple.newAssignStmt(l1, IntConstant.getInstance(1), noStmtPositionInfo);
JAssignStmt assign1tol2 =
JavaJimple.newAssignStmt(l2, IntConstant.getInstance(2), noStmtPositionInfo);
JAssignStmt assign0tol3 =
JavaJimple.newAssignStmt(l3, IntConstant.getInstance(0), noStmtPositionInfo);
BranchingStmt ifStmt =
JavaJimple.newIfStmt(
JavaJimple.newLtExpr(l3, IntConstant.getInstance(100)), noStmtPositionInfo);
Expand Down Expand Up @@ -86,43 +89,43 @@ public void testSSA() {
ssa.interceptBody(builder, new JavaView(Collections.emptyList()));
System.out.println(builder.build());
String expectedBodyString =
"{\n" +
" Test l0, l0#0;\n" +
" int l1, l1#1, l2, l2#10, l2#2, l2#4, l2#6, l2#8, l3, l3#11, l3#3, l3#5, l3#7, l3#9;\n" +
"\n" +
"\n" +
" l0#0 := @this: Test;\n" +
" l1#1 = 1;\n" +
" l2#2 = 2;\n" +
" l3#3 = 0;\n" +
"\n" +
" label1:\n" +
" l2#4 = phi(l2#2, l2#10);\n" +
" l3#5 = phi(l3#3, l3#11);\n" +
"\n" +
" if l3#5 < 100 goto label2;\n" +
"\n" +
" return l2#4;\n" +
"\n" +
" label2:\n" +
" if l2#4 < 20 goto label3;\n" +
" l2#8 = l3#5;\n" +
" l3#9 = l3#5 + 2;\n" +
"\n" +
" goto label4;\n" +
"\n" +
" label3:\n" +
" l2#6 = l1#1;\n" +
" l3#7 = l3#5 + 1;\n" +
"\n" +
" goto label4;\n" +
"\n" +
" label4:\n" +
" l2#10 = phi(l2#6, l2#8);\n" +
" l3#11 = phi(l3#7, l3#9);\n" +
"\n" +
" goto label1;\n" +
"}\n";
"{\n"
+ " Test l0, l0#0;\n"
+ " int l1, l1#1, l2, l2#10, l2#2, l2#4, l2#6, l2#8, l3, l3#11, l3#3, l3#5, l3#7, l3#9;\n"
+ "\n"
+ "\n"
+ " l0#0 := @this: Test;\n"
+ " l1#1 = 1;\n"
+ " l2#2 = 2;\n"
+ " l3#3 = 0;\n"
+ "\n"
+ " label1:\n"
+ " l2#4 = phi(l2#2, l2#10);\n"
+ " l3#5 = phi(l3#3, l3#11);\n"
+ "\n"
+ " if l3#5 < 100 goto label2;\n"
+ "\n"
+ " return l2#4;\n"
+ "\n"
+ " label2:\n"
+ " if l2#4 < 20 goto label3;\n"
+ " l2#8 = l3#5;\n"
+ " l3#9 = l3#5 + 2;\n"
+ "\n"
+ " goto label4;\n"
+ "\n"
+ " label3:\n"
+ " l2#6 = l1#1;\n"
+ " l3#7 = l3#5 + 1;\n"
+ "\n"
+ " goto label4;\n"
+ "\n"
+ " label4:\n"
+ " l2#10 = phi(l2#6, l2#8);\n"
+ " l3#11 = phi(l3#7, l3#9);\n"
+ "\n"
+ " goto label1;\n"
+ "}\n";

assertEquals(expectedBodyString, builder.build().toString());
}
Expand Down Expand Up @@ -218,32 +221,32 @@ public void testTrappedSSA() {
private Body.BodyBuilder createBody() {
MutableBlockStmtGraph graph = new MutableBlockStmtGraph();

//Block0
// Block0
graph.setStartingStmt(startingStmt);
graph.putEdge(startingStmt, assign1tol1);
graph.putEdge(assign1tol1, assign1tol2);
graph.putEdge(assign1tol2, assign0tol3);

//block1
// block1
graph.putEdge(assign0tol3, ifStmt);

//block2
graph.putEdge(ifStmt,JIfStmt.TRUE_BRANCH_IDX, ifStmt2);
// block2
graph.putEdge(ifStmt, JIfStmt.TRUE_BRANCH_IDX, ifStmt2);

//block3
graph.putEdge(ifStmt,JIfStmt.FALSE_BRANCH_IDX, returnStmt);
// block3
graph.putEdge(ifStmt, JIfStmt.FALSE_BRANCH_IDX, returnStmt);

//block4
// block4
graph.putEdge(ifStmt2, JIfStmt.TRUE_BRANCH_IDX, assignl1tol2);
graph.putEdge(assignl1tol2, assignl3plus1tol3);
graph.putEdge(assignl3plus1tol3, gotoStmt1);

//block 5
// block 5
graph.putEdge(ifStmt2, JIfStmt.FALSE_BRANCH_IDX, assignl3tol2);
graph.putEdge(assignl3tol2, assignl3plus2tol3);
graph.putEdge(assignl3plus2tol3, gotoStmt2);

//block 6
// block 6
graph.putEdge(gotoStmt1, JGotoStmt.BRANCH_IDX, goTo);
graph.putEdge(gotoStmt2, JGotoStmt.BRANCH_IDX, goTo);
graph.putEdge(goTo, JGotoStmt.BRANCH_IDX, ifStmt);
Expand Down

0 comments on commit 4a1107f

Please sign in to comment.