From 239ce6790f5acfe517097f7f35a71b2d4a73511b Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Wed, 18 Dec 2024 19:03:26 +0000 Subject: [PATCH] Revise the return instruction --- .../ezlang/compiler/CompiledFunction.java | 6 +- .../ezlang/compiler/Instruction.java | 29 ++- .../ezlang/compiler/RegisterPool.java | 7 - .../ezlang/interpreter/Interpreter.java | 13 +- .../ezlang/compiler/TestCompiler.java | 134 +++++----- .../ezlang/compiler/TestLiveness.java | 125 +++++----- .../ezlang/compiler/TestSSATransform.java | 230 +++++++++--------- 7 files changed, 277 insertions(+), 267 deletions(-) diff --git a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java index 4028bfd..ed7502c 100644 --- a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java +++ b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java @@ -39,7 +39,7 @@ public class CompiledFunction { public CompiledFunction(Symbol.FunctionTypeSymbol functionSymbol) { AST.FuncDecl funcDecl = (AST.FuncDecl) functionSymbol.functionDecl; this.functionType = (Type.TypeFunction) functionSymbol.type; - this.registerPool = new RegisterPool("%ret", functionType == null?null:functionType.returnType); + this.registerPool = new RegisterPool(); setVirtualRegisters(funcDecl.scope); this.bid = 0; this.entry = this.currentBlock = createBlock(); @@ -54,7 +54,7 @@ public CompiledFunction(Symbol.FunctionTypeSymbol functionSymbol) { public CompiledFunction(Type.TypeFunction functionType) { this.functionType = (Type.TypeFunction) functionType; - this.registerPool = new RegisterPool("%ret", functionType == null?null:functionType.returnType); + this.registerPool = new RegisterPool(); this.bid = 0; this.entry = this.currentBlock = createBlock(); this.exit = createBlock(); @@ -115,7 +115,7 @@ private void compileReturn(AST.ReturnStmt returnStmt) { if (isIndexed) codeIndexedLoad(); if (virtualStack.size() == 1) - code(new Instruction.Return(pop(), registerPool.returnRegister)); + code(new Instruction.Ret(pop())); else if (virtualStack.size() > 1) throw new CompilerException("Virtual stack has more than one item at return"); } diff --git a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/Instruction.java b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/Instruction.java index 5c27ff0..42bfdef 100644 --- a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/Instruction.java +++ b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/Instruction.java @@ -347,9 +347,32 @@ public StringBuilder toStr(StringBuilder sb) { .append(sourceOperand); } } - public static class Return extends Move { - public Return(Operand from, Register reg) { - super(from, new Operand.ReturnRegisterOperand(reg)); + public static class Ret extends Instruction { + public final Operand value; + public Ret(Operand value) { + this.value = value; + } + @Override + public boolean usesVars() { + return value != null && value instanceof Operand.RegisterOperand registerOperand; + } + @Override + public List uses() { + if (value != null && value instanceof Operand.RegisterOperand registerOperand) + return List.of(registerOperand.reg); + return Collections.emptyList(); + } + @Override + public void replaceUses(Register[] newUses) { + if (newUses.length > 0) + value.replaceRegister(newUses[0]); + } + @Override + public StringBuilder toStr(StringBuilder sb) { + sb.append("ret"); + if (value != null) + sb.append(" ").append(value); + return sb; } } public static class Unary extends Instruction { diff --git a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/RegisterPool.java b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/RegisterPool.java index 23ec8f3..0b86738 100644 --- a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/RegisterPool.java +++ b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/RegisterPool.java @@ -14,14 +14,7 @@ */ public class RegisterPool { private final ArrayList registers = new ArrayList<>(); - public final Register returnRegister; - public RegisterPool(String returnVarName, Type type) { - if (type != null) - returnRegister = newReg(returnVarName, type); - else - returnRegister = null; - } public Register getReg(int regNumber) { return registers.get(regNumber); } diff --git a/optvm/src/main/java/com/compilerprogramming/ezlang/interpreter/Interpreter.java b/optvm/src/main/java/com/compilerprogramming/ezlang/interpreter/Interpreter.java index 3e95085..d98352e 100644 --- a/optvm/src/main/java/com/compilerprogramming/ezlang/interpreter/Interpreter.java +++ b/optvm/src/main/java/com/compilerprogramming/ezlang/interpreter/Interpreter.java @@ -44,16 +44,17 @@ public Value interpret(ExecutionStack execStack, Frame frame) { ip++; instruction = currentBlock.instructions.get(ip); switch (instruction) { - case Instruction.Return returnInst -> { - if (returnInst.from instanceof Operand.ConstantOperand constantOperand) { + case Instruction.Ret retInst -> { + if (retInst.value instanceof Operand.ConstantOperand constantOperand) { execStack.stack[base] = new Value.IntegerValue(constantOperand.value); } - else if (returnInst.from instanceof Operand.RegisterOperand registerOperand) { + else if (retInst.value instanceof Operand.RegisterOperand registerOperand) { execStack.stack[base] = execStack.stack[base+registerOperand.slot()]; } else throw new IllegalStateException(); returnValue = execStack.stack[base]; } + case Instruction.Move moveInst -> { if (moveInst.to instanceof Operand.RegisterOperand toReg) { if (moveInst.from instanceof Operand.RegisterOperand fromReg) { @@ -98,11 +99,7 @@ else if (cbrInst.condition instanceof Operand.ConstantOperand constantOperand) { case Instruction.Call callInst -> { // Copy args to new frame int baseReg = base+currentFunction.frameSize(); - int offset = 0; - // In this version return reg - if (!(callInst.callee.returnType instanceof Type.TypeVoid)) - offset = 1; - int reg = baseReg + offset; + int reg = baseReg; for (Operand.RegisterOperand arg: callInst.args) { execStack.stack[base + reg] = execStack.stack[base + arg.slot()]; reg += 1; diff --git a/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestCompiler.java b/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestCompiler.java index 047e8a3..15c31d4 100644 --- a/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestCompiler.java +++ b/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestCompiler.java @@ -22,7 +22,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = 1 + ret 1 goto L1 L1: """, result); @@ -39,7 +39,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = -1 + ret -1 goto L1 L1: """, result); @@ -56,7 +56,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = n + ret n goto L1 L1: """, result); @@ -73,8 +73,8 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %t2 = -n - %ret = %t2 + %t1 = -n + ret %t1 goto L1 L1: """, result); @@ -91,8 +91,8 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %t2 = n+1 - %ret = %t2 + %t1 = n+1 + ret %t1 goto L1 L1: """, result); @@ -109,7 +109,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = 2 + ret 2 goto L1 L1: """, result); @@ -126,7 +126,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = 1 + ret 1 goto L1 L1: """, result); @@ -143,7 +143,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = 1 + ret 1 goto L1 L1: """, result); @@ -160,7 +160,7 @@ func foo(n: Int)->Int { Assert.assertEquals(""" L0: arg n - %ret = 0 + ret 0 goto L1 L1: """, result); @@ -177,8 +177,8 @@ func foo(n: [Int])->Int { Assert.assertEquals(""" L0: arg n - %t2 = n[0] - %ret = %t2 + %t1 = n[0] + ret %t1 goto L1 L1: """, result); @@ -195,10 +195,10 @@ func foo(n: [Int])->Int { Assert.assertEquals(""" L0: arg n - %t2 = n[0] - %t3 = n[1] - %t4 = %t2+%t3 - %ret = %t4 + %t1 = n[0] + %t2 = n[1] + %t3 = %t1+%t2 + ret %t3 goto L1 L1: """, result); @@ -214,11 +214,11 @@ func foo()->[Int] { String result = compileSrc(src); Assert.assertEquals(""" L0: - %t1 = New([Int,Int]) - %t1.append(1) - %t1.append(2) - %t1.append(3) - %ret = %t1 + %t0 = New([Int,Int]) + %t0.append(1) + %t0.append(2) + %t0.append(3) + ret %t0 goto L1 L1: """, result); @@ -235,9 +235,9 @@ func foo(n: Int) -> [Int] { Assert.assertEquals(""" L0: arg n - %t2 = New([Int,Int]) - %t2.append(n) - %ret = %t2 + %t1 = New([Int,Int]) + %t1.append(n) + ret %t1 goto L1 L1: """, result); @@ -255,8 +255,8 @@ func add(x: Int, y: Int) -> Int { L0: arg x arg y - %t3 = x+y - %ret = %t3 + %t2 = x+y + ret %t2 goto L1 L1: """, result); @@ -299,10 +299,10 @@ func foo() -> Person { String result = compileSrc(src); Assert.assertEquals(""" L0: - %t1 = New(Person) - %t1.age = 10 - %t1.children = 0 - %ret = %t1 + %t0 = New(Person) + %t0.age = 10 + %t0.children = 0 + ret %t0 goto L1 L1: """, result); @@ -341,14 +341,14 @@ func min(x: Int, y: Int) -> Int { L0: arg x arg y - %t3 = x0 - if %t2 goto L3 else goto L4 + %t1 = n>0 + if %t1 goto L3 else goto L4 L3: - %t3 = n-1 - n = %t3 + %t2 = n-1 + n = %t2 goto L2 L4: goto L1 @@ -459,9 +459,9 @@ func foo(x: Int, y: Int) {} goto L1 L1: L0: - %t1 = 1 - %t2 = 2 - call foo params %t1, %t2 + %t0 = 1 + %t1 = 2 + call foo params %t0, %t1 goto L1 L1: """, result); @@ -478,17 +478,17 @@ public void testFunction24() { L0: arg x arg y - %t3 = x+y - %ret = %t3 + %t2 = x+y + ret %t2 goto L1 L1: L0: - %t2 = 1 - %t3 = 2 - %t4 = call foo params %t2, %t3 - t = %t4 - %t5 = t+1 - %ret = %t5 + %t1 = 1 + %t2 = 2 + %t3 = call foo params %t1, %t2 + t = %t3 + %t4 = t+1 + ret %t4 goto L1 L1: """, result); @@ -510,8 +510,8 @@ func foo(p: Person) -> Int { Assert.assertEquals(""" L0: arg p - %t2 = p.age - %ret = %t2 + %t1 = p.age + ret %t1 goto L1 L1: """, result); @@ -533,9 +533,9 @@ func foo(p: Person) -> Int { Assert.assertEquals(""" L0: arg p - %t2 = p.parent - %t3 = %t2.age - %ret = %t3 + %t1 = p.parent + %t2 = %t1.age + ret %t2 goto L1 L1: """, result); @@ -558,10 +558,10 @@ func foo(p: [Person], i: Int) -> Int { L0: arg p arg i - %t3 = p[i] - %t4 = %t3.parent - %t5 = %t4.age - %ret = %t5 + %t2 = p[i] + %t3 = %t2.parent + %t4 = %t3.age + ret %t4 goto L1 L1: """, result); @@ -578,18 +578,18 @@ public void testFunction28() { L0: arg x arg y - %t3 = x+y - %ret = %t3 + %t2 = x+y + ret %t2 goto L1 L1: L0: arg a - %t3 = a - %t4 = 2 - %t5 = call foo params %t3, %t4 - t = %t5 - %t6 = t+1 - %ret = %t6 + %t2 = a + %t3 = 2 + %t4 = call foo params %t2, %t3 + t = %t4 + %t5 = t+1 + ret %t5 goto L1 L1: """, result); diff --git a/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestLiveness.java b/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestLiveness.java index da2890e..6511a95 100644 --- a/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestLiveness.java +++ b/optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestLiveness.java @@ -37,79 +37,77 @@ func foo() { var liveness = new Liveness(); liveness.computeLiveness(func); String output = Compiler.dumpIR(typeDict, true); - Assert.assertEquals(output, """ + Assert.assertEquals(""" func print(n: Int) -Reg #0 %ret -Reg #1 n +Reg #0 n L0: arg n goto L1 L1: func foo() -Reg #0 %ret -Reg #1 i -Reg #2 s +Reg #0 i +Reg #1 s +Reg #2 %t2 Reg #3 %t3 Reg #4 %t4 Reg #5 %t5 Reg #6 %t6 -Reg #7 %t7 L0: i = 1 s = 1 goto L2 #UEVAR = {} - #VARKILL = {1, 2} - #LIVEOUT = {1, 2} + #VARKILL = {0, 1} + #LIVEOUT = {0, 1} L2: if 1 goto L3 else goto L4 #UEVAR = {} #VARKILL = {} - #LIVEOUT = {1, 2} + #LIVEOUT = {0, 1} L3: - %t3 = i==5 - if %t3 goto L5 else goto L6 - #UEVAR = {1} - #VARKILL = {3} - #LIVEOUT = {1, 2} + %t2 = i==5 + if %t2 goto L5 else goto L6 + #UEVAR = {0} + #VARKILL = {2} + #LIVEOUT = {0, 1} L5: s = 0 goto L6 #UEVAR = {} - #VARKILL = {2} - #LIVEOUT = {1, 2} + #VARKILL = {1} + #LIVEOUT = {0, 1} L6: - %t4 = s+1 - s = %t4 - %t5 = i+1 - i = %t5 - %t6 = i<10 - if %t6 goto L7 else goto L8 - #UEVAR = {1, 2} - #VARKILL = {1, 2, 4, 5, 6} - #LIVEOUT = {1, 2} + %t3 = s+1 + s = %t3 + %t4 = i+1 + i = %t4 + %t5 = i<10 + if %t5 goto L7 else goto L8 + #UEVAR = {0, 1} + #VARKILL = {0, 1, 3, 4, 5} + #LIVEOUT = {0, 1} L7: goto L2 #UEVAR = {} #VARKILL = {} - #LIVEOUT = {1, 2} + #LIVEOUT = {0, 1} L8: goto L4 #UEVAR = {} #VARKILL = {} - #LIVEOUT = {2} + #LIVEOUT = {1} L4: - %t7 = s - call print params %t7 + %t6 = s + call print params %t6 goto L1 - #UEVAR = {2} - #VARKILL = {7} + #UEVAR = {1} + #VARKILL = {6} #LIVEOUT = {} L1: #UEVAR = {} #VARKILL = {} #LIVEOUT = {} -"""); +""", output); } @Test @@ -133,56 +131,55 @@ func foo(a: Int, b: Int) { var liveness = new Liveness(); liveness.computeLiveness(func); String output = Compiler.dumpIR(typeDict, true); - Assert.assertEquals(output, """ + Assert.assertEquals(""" func foo(a: Int,b: Int) -Reg #0 %ret -Reg #1 a -Reg #2 b +Reg #0 a +Reg #1 b +Reg #2 %t2 Reg #3 %t3 Reg #4 %t4 Reg #5 %t5 Reg #6 %t6 -Reg #7 %t7 L0: arg a arg b goto L2 #UEVAR = {} - #VARKILL = {1, 2} - #LIVEOUT = {1, 2} + #VARKILL = {0, 1} + #LIVEOUT = {0, 1} L2: - %t3 = b<10 - if %t3 goto L3 else goto L4 - #UEVAR = {2} - #VARKILL = {3} - #LIVEOUT = {1, 2} + %t2 = b<10 + if %t2 goto L3 else goto L4 + #UEVAR = {1} + #VARKILL = {2} + #LIVEOUT = {0, 1} L3: - %t4 = bInt { a = 42 if d goto L2 else goto L3 L2: - %t3 = a+1 - a = %t3 + %t2 = a+1 + a = %t2 goto L4 L4: - %ret = a + ret a goto L1 L1: L3: - %t4 = a-1 - a = %t4 + %t3 = a-1 + a = %t3 goto L4 After SSA ========= @@ -139,17 +139,17 @@ func foo(d: Int)->Int { a_0 = 42 if d_0 goto L2 else goto L3 L2: - %t3_0 = a_0+1 - a_2 = %t3_0 + %t2_0 = a_0+1 + a_2 = %t2_0 goto L4 L4: a_3 = phi(a_2, a_1) - %ret_0 = a_3 + ret a_3 goto L1 L1: L3: - %t4_0 = a_0-1 - a_1 = %t4_0 + %t3_0 = a_0-1 + a_1 = %t3_0 goto L4 After exiting SSA ================= @@ -158,17 +158,17 @@ func foo(d: Int)->Int { a_0 = 42 if d_0 goto L2 else goto L3 L2: - %t3_0 = a_0+1 - a_2 = %t3_0 + %t2_0 = a_0+1 + a_2 = %t2_0 a_3 = a_2 goto L4 L4: - %ret_0 = a_3 + ret a_3 goto L1 L1: L3: - %t4_0 = a_0-1 - a_1 = %t4_0 + %t3_0 = a_0-1 + a_1 = %t3_0 a_3 = a_1 goto L4 """, result); @@ -198,16 +198,16 @@ func factorial(num: Int)->Int { result = 1 goto L2 L2: - %t3 = num>1 - if %t3 goto L3 else goto L4 + %t2 = num>1 + if %t2 goto L3 else goto L4 L3: - %t4 = result*num - result = %t4 - %t5 = num-1 - num = %t5 + %t3 = result*num + result = %t3 + %t4 = num-1 + num = %t4 goto L2 L4: - %ret = result + ret result goto L1 L1: After SSA @@ -219,16 +219,16 @@ func factorial(num: Int)->Int { L2: result_1 = phi(result_0, result_2) num_1 = phi(num_0, num_2) - %t3_0 = num_1>1 - if %t3_0 goto L3 else goto L4 + %t2_0 = num_1>1 + if %t2_0 goto L3 else goto L4 L3: - %t4_0 = result_1*num_1 - result_2 = %t4_0 - %t5_0 = num_1-1 - num_2 = %t5_0 + %t3_0 = result_1*num_1 + result_2 = %t3_0 + %t4_0 = num_1-1 + num_2 = %t4_0 goto L2 L4: - %ret_0 = result_1 + ret result_1 goto L1 L1: After exiting SSA @@ -240,18 +240,18 @@ func factorial(num: Int)->Int { num_1 = num_0 goto L2 L2: - %t3_0 = num_1>1 - if %t3_0 goto L3 else goto L4 + %t2_0 = num_1>1 + if %t2_0 goto L3 else goto L4 L3: - %t4_0 = result_1*num_1 - result_2 = %t4_0 - %t5_0 = num_1-1 - num_2 = %t5_0 + %t3_0 = result_1*num_1 + result_2 = %t3_0 + %t4_0 = num_1-1 + num_2 = %t4_0 result_1 = result_2 num_1 = num_2 goto L2 L4: - %ret_0 = result_1 + ret result_1 goto L1 L1: """, result); @@ -350,34 +350,34 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { l = 2 goto L10 L10: - %t10 = k+1 - k = %t10 + %t9 = k+1 + k = %t9 goto L7 L7: - %t12 = i - %t13 = j - %t14 = k - %t15 = l - call print params %t12, %t13, %t14, %t15 + %t11 = i + %t12 = j + %t13 = k + %t14 = l + call print params %t11, %t12, %t13, %t14 goto L11 L11: if 1 goto L12 else goto L13 L12: if r goto L14 else goto L15 L14: - %t16 = l+4 - l = %t16 + %t15 = l+4 + l = %t15 goto L15 L15: - %t17 = !s - if %t17 goto L16 else goto L17 + %t16 = !s + if %t16 goto L16 else goto L17 L16: goto L13 L13: - %t18 = i+6 - i = %t18 - %t19 = !t - if %t19 goto L18 else goto L19 + %t17 = i+6 + i = %t17 + %t18 = !t + if %t18 goto L18 else goto L19 L18: goto L4 L4: @@ -391,8 +391,8 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { l = 3 goto L10 L6: - %t11 = k+2 - k = %t11 + %t10 = k+2 + k = %t10 goto L7 After SSA ========= @@ -423,18 +423,18 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { goto L10 L10: l_4 = phi(l_3, l_2) - %t10_0 = k_1+1 - k_3 = %t10_0 + %t9_0 = k_1+1 + k_3 = %t9_0 goto L7 L7: l_5 = phi(l_4, l_1) k_4 = phi(k_3, k_2) j_3 = phi(j_2, j_1) - %t12_0 = i_1 - %t13_0 = j_3 - %t14_0 = k_4 - %t15_0 = l_5 - call print params %t12_0, %t13_0, %t14_0, %t15_0 + %t11_0 = i_1 + %t12_0 = j_3 + %t13_0 = k_4 + %t14_0 = l_5 + call print params %t11_0, %t12_0, %t13_0, %t14_0 goto L11 L11: l_6 = phi(l_5, l_8) @@ -442,21 +442,21 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { L12: if r_0 goto L14 else goto L15 L14: - %t16_0 = l_6+4 - l_7 = %t16_0 + %t15_0 = l_6+4 + l_7 = %t15_0 goto L15 L15: l_8 = phi(l_6, l_7) - %t17_0 = !s_0 - if %t17_0 goto L16 else goto L17 + %t16_0 = !s_0 + if %t16_0 goto L16 else goto L17 L16: goto L13 L13: l_9 = phi(l_6, l_8) - %t18_0 = i_1+6 - i_2 = %t18_0 - %t19_0 = !t_0 - if %t19_0 goto L18 else goto L19 + %t17_0 = i_1+6 + i_2 = %t17_0 + %t18_0 = !t_0 + if %t18_0 goto L18 else goto L19 L18: goto L4 L4: @@ -474,8 +474,8 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { l_2 = 3 goto L10 L6: - %t11_0 = k_1+2 - k_2 = %t11_0 + %t10_0 = k_1+2 + k_2 = %t10_0 goto L7 After exiting SSA ================= @@ -510,18 +510,18 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { l_4 = l_3 goto L10 L10: - %t10_0 = k_1+1 - k_3 = %t10_0 + %t9_0 = k_1+1 + k_3 = %t9_0 l_5 = l_4 k_4 = k_3 j_3 = j_2 goto L7 L7: - %t12_0 = i_1 - %t13_0 = j_3 - %t14_0 = k_4 - %t15_0 = l_5 - call print params %t12_0, %t13_0, %t14_0, %t15_0 + %t11_0 = i_1 + %t12_0 = j_3 + %t13_0 = k_4 + %t14_0 = l_5 + call print params %t11_0, %t12_0, %t13_0, %t14_0 l_6 = l_5 goto L11 L11: @@ -531,21 +531,21 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { l_8 = l_6 if r_0 goto L14 else goto L15 L14: - %t16_0 = l_6+4 - l_7 = %t16_0 + %t15_0 = l_6+4 + l_7 = %t15_0 l_8 = l_7 goto L15 L15: - %t17_0 = !s_0 - if %t17_0 goto L16 else goto L17 + %t16_0 = !s_0 + if %t16_0 goto L16 else goto L17 L16: l_9 = l_8 goto L13 L13: - %t18_0 = i_1+6 - i_2 = %t18_0 - %t19_0 = !t_0 - if %t19_0 goto L18 else goto L19 + %t17_0 = i_1+6 + i_2 = %t17_0 + %t18_0 = !t_0 + if %t18_0 goto L18 else goto L19 L18: l_10 = l_9 k_5 = k_4 @@ -569,8 +569,8 @@ func example14_66(p: Int, q: Int, r: Int, s: Int, t: Int) { l_4 = l_2 goto L10 L6: - %t11_0 = k_1+2 - k_2 = %t11_0 + %t10_0 = k_1+2 + k_2 = %t10_0 l_5 = l_1 k_4 = k_2 j_3 = j_1 @@ -596,11 +596,11 @@ func bar(arg: Int)->Int { arg arg if arg goto L2 else goto L3 L2: - %ret = 42 + ret 42 goto L1 L1: L3: - %ret = 0 + ret 0 goto L1 After SSA ========= @@ -608,11 +608,11 @@ func bar(arg: Int)->Int { arg arg_0 if arg_0 goto L2 else goto L3 L2: - %ret_1 = 42 + ret 42 goto L1 L1: L3: - %ret_0 = 0 + ret 0 goto L1 After exiting SSA ================= @@ -620,11 +620,11 @@ func bar(arg: Int)->Int { arg arg_0 if arg_0 goto L2 else goto L3 L2: - %ret_1 = 42 + ret 42 goto L1 L1: L3: - %ret_0 = 0 + ret 0 goto L1 """, result); } @@ -658,7 +658,7 @@ private CompiledFunction buildLostCopyTest() { function.code(new Instruction.ConditionalBranch(B2, new Operand.RegisterOperand(p), B2, function.exit)); function.startBlock(function.exit); - function.code(new Instruction.Return(new Operand.RegisterOperand(x2), regPool.returnRegister)); + function.code(new Instruction.Ret(new Operand.RegisterOperand(x2))); function.isSSA = true; return function; } @@ -676,7 +676,7 @@ public void testLostCopyProblem() { x3 = x2+1 if p goto L2 else goto L1 L1: - %ret = x2 + ret x2 """; Assert.assertEquals(expected, function.toStr(new StringBuilder(), false).toString()); new ExitSSA(function); @@ -687,12 +687,12 @@ public void testLostCopyProblem() { x2 = x1 goto L2 L2: - x2_5 = x2 + x2_4 = x2 x3 = x2+1 x2 = x3 if p goto L2 else goto L1 L1: - %ret = x2_5 + ret x2_4 """; Assert.assertEquals(expected, function.toStr(new StringBuilder(), false).toString()); }