Please ignore this patch, there is still something not correct. Thanks.

-----Original Message-----
From: Guo, Yejun 
Sent: Wednesday, April 26, 2017 4:43 PM
To: beignet@lists.freedesktop.org
Cc: Guo, Yejun
Subject: [PATCH] defer dead insn removal since lowerIndirectRead still needs 
them

---
 backend/src/ir/lowering.cpp | 54 ++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/backend/src/ir/lowering.cpp b/backend/src/ir/lowering.cpp
index 93bd96a..53aafa4 100644
--- a/backend/src/ir/lowering.cpp
+++ b/backend/src/ir/lowering.cpp
@@ -117,7 +117,7 @@ namespace ir {
     /*! Lower the given function argument accesses */
     ArgUse lower(uint32_t argID);
     /*! Build the constant push for the function */
-    void buildConstantPush(void);
+    void buildConstantPush(set<const Instruction*>& dead);
     /* Lower indirect Read to indirct Mov */
     void lowerIndirectRead(uint32_t argID);
     /* Convert indirectLoad to indirect Mov */
@@ -192,6 +192,25 @@ namespace ir {
     GBE_SAFE_DELETE(liveness);
   }
 
+// Remove all the given instructions from the stream (if dead)
+#define REMOVE_INSN(WHICH) \
+  for (const auto &loadAddImm : seq) { \
+    Instruction *WHICH = loadAddImm.WHICH; \
+    if (WHICH == NULL) continue; \
+    const UseSet &useSet = dag->getUse(WHICH, 0); \
+    bool isDead = true; \
+    for (auto use : useSet) { \
+      if (dead.contains(use->getInstruction()) == false) { \
+        isDead = false; \
+        break; \
+      } \
+    } \
+    if (isDead && !dead.contains(WHICH)) { \
+      dead.insert(WHICH); \
+      WHICH->remove(); \
+    } \
+  }
+
   void FunctionArgumentLowerer::lower(const std::string &functionName) {
     if ((this->fn = unit.getFunction(functionName)) == NULL)
       return;
@@ -213,40 +232,22 @@ namespace ir {
 
     // Build the constant push description and remove the instruction that
     // therefore become useless
-    this->buildConstantPush();
+    set<const Instruction*> dead;
+    this->buildConstantPush(dead);
     for (uint32_t i = 0; i < indirctReadArgs.size(); ++i){
       lowerIndirectRead(indirctReadArgs[i]);
     }
-    ReplaceIndirectLoad();
-  }
+    REMOVE_INSN(add)
+    REMOVE_INSN(loadImm)
 
-// Remove all the given instructions from the stream (if dead)
-#define REMOVE_INSN(WHICH) \
-  for (const auto &loadAddImm : seq) { \
-    Instruction *WHICH = loadAddImm.WHICH; \
-    if (WHICH == NULL) continue; \
-    const UseSet &useSet = dag->getUse(WHICH, 0); \
-    bool isDead = true; \
-    for (auto use : useSet) { \
-      if (dead.contains(use->getInstruction()) == false) { \
-        isDead = false; \
-        break; \
-      } \
-    } \
-    if (isDead && !dead.contains(WHICH)) { \
-      dead.insert(WHICH); \
-      WHICH->remove(); \
-    } \
+    ReplaceIndirectLoad();
   }
 
-  void FunctionArgumentLowerer::buildConstantPush(void)
+  void FunctionArgumentLowerer::buildConstantPush(set<const Instruction*>& 
dead)
   {
     if (seq.size() == 0)
       return;
 
-    // Track instructions we remove to recursively kill them properly
-    set<const Instruction*> dead;
-
     // The argument location we already pushed (since the same argument 
location
     // can be used several times)
     set<PushLocation> inserted;
@@ -291,9 +292,6 @@ namespace ir {
         load->remove();
       }
     }
-
-    REMOVE_INSN(add)
-    REMOVE_INSN(loadImm)
   }
 
 #undef REMOVE_INSN
-- 
2.7.4

_______________________________________________
Beignet mailing list
Beignet@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to