We don't need to recompute the entire liveness information for all cases. This is a preparation patch for further phi copy optimization.
v2: also need to update varKill set. Signed-off-by: Zhigang Gong <zhigang.g...@intel.com> --- backend/src/ir/liveness.cpp | 37 +++++++++++++++++++++++++++++++++++++ backend/src/ir/liveness.hpp | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/backend/src/ir/liveness.cpp b/backend/src/ir/liveness.cpp index e2240c0..1839029 100644 --- a/backend/src/ir/liveness.cpp +++ b/backend/src/ir/liveness.cpp @@ -59,6 +59,43 @@ 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); + } + if (info.varKill.contains(from)) { + info.varKill.erase(from); + info.varKill.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 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet