[Beignet] [PATCH 3/8] GBE: add two helper routines for liveness partially update.

Zhigang Gong zhigang.gong at intel.com
Tue Sep 22 21:44:49 PDT 2015


We don't need to recompute the entire liveness information for
all cases. This is a preparation patch for further phi copy
optimization.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/ir/liveness.cpp | 33 +++++++++++++++++++++++++++++++++
 backend/src/ir/liveness.hpp |  7 +++++++
 2 files changed, 40 insertions(+)

diff --git a/backend/src/ir/liveness.cpp b/backend/src/ir/liveness.cpp
index e2240c0..c5a6374 100644
--- a/backend/src/ir/liveness.cpp
+++ b/backend/src/ir/liveness.cpp
@@ -59,6 +59,39 @@ namespace ir {
     }
   }
 
+  void Liveness::removeRegs(const set<Register> &removes) {
+    for (auto &pair : liveness) {
+      BlockInfo &info = *(pair.second);
+      for (auto reg : removes) {
+        if (info.liveOut.contains(reg))
+          info.liveOut.erase(reg);
+        if (info.upwardUsed.contains(reg))
+          info.upwardUsed.erase(reg);
+      }
+    }
+  }
+
+  void Liveness::replaceRegs(const map<Register, Register> &replaceMap) {
+
+    for (auto &pair : liveness) {
+      BlockInfo &info = *pair.second;
+      BasicBlock *bb = const_cast<BasicBlock *>(&info.bb);
+      for (auto &pair : replaceMap) {
+        Register from = pair.first;
+        Register to = pair.second;
+        if (info.liveOut.contains(from)) {
+          info.liveOut.erase(from);
+          info.liveOut.insert(to);
+          bb->definedPhiRegs.insert(to);
+        }
+        if (info.upwardUsed.contains(from)) {
+          info.upwardUsed.erase(from);
+          info.upwardUsed.insert(to);
+        }
+      }
+    }
+  }
+
   Liveness::~Liveness(void) {
     for (auto &pair : liveness) GBE_SAFE_DELETE(pair.second);
   }
diff --git a/backend/src/ir/liveness.hpp b/backend/src/ir/liveness.hpp
index d9fa2ed..df889e6 100644
--- a/backend/src/ir/liveness.hpp
+++ b/backend/src/ir/liveness.hpp
@@ -116,6 +116,13 @@ namespace ir {
         }
       }
     }
+
+    // remove some registers from the liveness information.
+    void removeRegs(const set<Register> &removes);
+
+    // replace some registers according to (from, to) register map.
+    void replaceRegs(const map<Register, Register> &replaceMap);
+
   private:
     /*! Store the liveness of all blocks */
     Info liveness;
-- 
1.9.1



More information about the Beignet mailing list