[Beignet] [PATCH] defer dead insn removal since lowerIndirectRead still needs them

Guo, Yejun yejun.guo at intel.com
Wed Apr 26 08:43:21 UTC 2017


---
 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



More information about the Beignet mailing list