From 7108b4e265b7e346e399c1b400e2d799cffd2852 Mon Sep 17 00:00:00 2001
From: aaicy64 <1106721455@qq.com>
Date: Tue, 26 Jul 2022 14:17:57 +0800
Subject: [PATCH] =?UTF-8?q?bugfix:=20idom=E5=9C=A8=E9=87=8D=E6=96=B0?=
 =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=97=B6=E6=B2=A1=E6=B8=85=E7=A9=BA=EF=BC=8C?=
 =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=AC=AC=E4=BA=8C=E6=AC=A1=E8=BF=90=E8=A1=8C?=
 =?UTF-8?q?mem2reg=E5=B0=91=E6=8F=92=E4=BA=86phi?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/ir/MyModule.java               | 18 ++++++++++++++++++
 src/ir/value/BasicBlock.java       |  1 +
 test/parser/MySysYVisitorTest.java |  5 +++--
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/ir/MyModule.java b/src/ir/MyModule.java
index 95e8560b..35e81c65 100644
--- a/src/ir/MyModule.java
+++ b/src/ir/MyModule.java
@@ -68,6 +68,24 @@ public class MyModule {
         );
     }
 
+    public void updateBbelongTo() {
+        functions.forEach(
+                functionNode-> {
+                    Function function = functionNode.getValue();
+                    function.getList().forEach(
+                            bbNode->{
+                                BasicBlock bb = bbNode.getValue();
+                                bb.getList().forEach(
+                                        instrNode-> {
+                                            instrNode.getValue().setBbelongTo(bb);
+                                        }
+                                );
+                            }
+                    );
+                }
+        );
+    }
+
     public void updateUses() {
         functions.forEach(
                 functionNode-> {
diff --git a/src/ir/value/BasicBlock.java b/src/ir/value/BasicBlock.java
index 957fc381..d744a028 100644
--- a/src/ir/value/BasicBlock.java
+++ b/src/ir/value/BasicBlock.java
@@ -35,6 +35,7 @@ public class BasicBlock extends User {
     public void clearDominationInfo() {
         dominator.clear();
         dominating.clear();
+        idominating.clear();
         idominator = null;
         df.clear();
     }
diff --git a/test/parser/MySysYVisitorTest.java b/test/parser/MySysYVisitorTest.java
index 83db4f99..ba8235de 100644
--- a/test/parser/MySysYVisitorTest.java
+++ b/test/parser/MySysYVisitorTest.java
@@ -20,7 +20,7 @@ import static org.junit.Assert.*;
 public class MySysYVisitorTest {
     @Test
     public void runParser() throws IOException { // testcases\functional_2022\51_short_circuit3.sy
-        var input = CharStreams.fromFileName("D:\\Compile\\compiler\\testcases\\functional_2022\\78_side_effect.sy");//86_long_code2.sy
+        var input = CharStreams.fromFileName("D:\\Compile\\compiler\\testcases\\functional_2022\\64_calculator.sy");//86_long_code2.sy
         //D:\Compile\compiler\testcases\functional_test\089_hidden_var.sy
         SysYLexer lexer = new SysYLexer(input);
         CommonTokenStream tokens = new CommonTokenStream(lexer);
@@ -39,12 +39,13 @@ public class MySysYVisitorTest {
         m.updateUses();
         new FuncInline().run(m);
         m.updateUses();
-
+        m.updateBbelongTo();
         new GlobalVarLocalize(m).run(m);
         m.setName();
         Analyze.calcuPrecSuccBB(m);
         System.out.println(m);
         m.updateUses();
+        m.updateBbelongTo();
         new Mem2Reg().run(m);
         m.setName();
         System.out.println(m);
-- 
GitLab