Skip to content

Commit 1196c67

Browse files
Seal the body block immediately after the condition in while stmt
1 parent 2fba28c commit 1196c67

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,10 @@ private void compileWhile(AST.WhileStmt whileStmt) {
225225
codeIndexedLoad();
226226
codeCBR(currentBlock, pop(), bodyBlock, exitBlock);
227227
assert vstackEmpty();
228-
startBlock(bodyBlock); // ISSA If we seal this here fib test fails, wrong code generated, why?
228+
startSealedBlock(bodyBlock); // ISSA If we seal this here fib test fails, wrong code generated, why?
229229
compileStatement(whileStmt.stmt);
230230
if (!isBlockTerminated(currentBlock))
231231
jumpTo(loopHead);
232-
issa.sealBlock(bodyBlock);
233232
issa.sealBlock(loopHead);
234233
startSealedBlock(exitBlock);
235234
currentContinueTarget = savedContinueTarget;
@@ -900,7 +899,7 @@ private Register readVariable(Register variable, BasicBlock block) {
900899
*/
901900
private Register readVariableRecursive(Register variable, BasicBlock block) {
902901
Register val;
903-
if (!sealedBlocks.get(block.bid)) {
902+
if (!isSealed(block)) {
904903
// incomplete CFG
905904
val = makeVersion(variable);
906905
Instruction.Phi phi = makePhi(val, block);

optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestIncrementalSSA.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
public class TestIncrementalSSA {
88
String compileSrc(String src) {
99
var compiler = new Compiler();
10-
var typeDict = compiler.compileSrc(src, EnumSet.of(Options.ISSA));
11-
return compiler.dumpIR(typeDict);
10+
var typeDict = compiler.compileSrc(src, EnumSet.of(Options.ISSA,Options.DUMP_SSA_IR));
11+
return compiler.dumpIR(typeDict,true);
1212
}
1313

1414
@Test
@@ -104,4 +104,29 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) {
104104
String result = compileSrc(src);
105105
System.out.println(result);
106106
}
107+
108+
@Test
109+
public void test5() {
110+
String src = """
111+
func fib(n: Int)->Int {
112+
var i: Int;
113+
var temp: Int;
114+
var f1=1;
115+
var f2=1;
116+
i=n;
117+
while( i>1 ){
118+
temp = f1+f2;
119+
f1=f2;
120+
f2=temp;
121+
i=i-1;
122+
}
123+
return f2;
124+
}
125+
func foo()->Int {
126+
return fib(10);
127+
}
128+
""";
129+
String result = compileSrc(src);
130+
System.out.println(result);
131+
}
107132
}

0 commit comments

Comments
 (0)