[Beignet] [PATCH] refresh DAG when an arg has both direct and indirect read

Guo, Yejun yejun.guo at intel.com
Wed May 17 06:52:18 UTC 2017


when the return value is ARG_INDIRECT_READ, there is still possible
that some IRs read it directly, and will be handled in buildConstantPush()
so we need to refresh the dag afer function buildConstantPush

another method is to update DAG accordingly, but i don't think it
is easy compared with the refresh method, so i do not choose it.
---
 backend/src/ir/lowering.cpp | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/backend/src/ir/lowering.cpp b/backend/src/ir/lowering.cpp
index 93bd96a..bcf5940 100644
--- a/backend/src/ir/lowering.cpp
+++ b/backend/src/ir/lowering.cpp
@@ -199,6 +199,7 @@ namespace ir {
     GBE_SAFE_DELETE(liveness);
     this->liveness = GBE_NEW(ir::Liveness, *fn);
     this->dag = GBE_NEW(ir::FunctionDAG, *this->liveness);
+    bool needRefreshDag = false;
 
     // Process all structure arguments and find all the direct loads we can
     // replace
@@ -207,13 +208,27 @@ namespace ir {
     for (uint32_t argID = 0; argID < argNum; ++argID) {
       FunctionArgument &arg = fn->getArg(argID);
       if (arg.type != FunctionArgument::STRUCTURE) continue;
-      if(this->lower(argID) == ARG_INDIRECT_READ)
+      if(this->lower(argID) == ARG_INDIRECT_READ) {
         indirctReadArgs.push_back(argID);
+        //when the return value is ARG_INDIRECT_READ, there is still possible
+        //that some IRs read it directly, and will be handled in buildConstantPush()
+        //so we need to refresh the dag afer function buildConstantPush
+        for (const auto &loadAddImm : seq) {
+          if (loadAddImm.argID == argID)
+            needRefreshDag = true;
+        }
+      }
     }
 
     // Build the constant push description and remove the instruction that
     // therefore become useless
     this->buildConstantPush();
+    if (needRefreshDag) {
+      GBE_SAFE_DELETE(dag);
+      GBE_SAFE_DELETE(liveness);
+      this->liveness = GBE_NEW(ir::Liveness, *fn);
+      this->dag = GBE_NEW(ir::FunctionDAG, *this->liveness);
+    }
     for (uint32_t i = 0; i < indirctReadArgs.size(); ++i){
       lowerIndirectRead(indirctReadArgs[i]);
     }
-- 
2.7.4



More information about the Beignet mailing list