From 150e6f3a4a4b1c1f8e6d4d7baac344187b4c8325 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Tue, 13 May 2014 17:51:26 +0800 Subject: [PATCH] GBE: don't allocate/modify flag if it is not used in current BB. If a flag is not used in current BB, we don't need to set the modFlag bit on that instruction. Thus the register allocation stage will not allocate a flag register for it. No performance impact, as the previous implementation will expire that flag register immediately. Signed-off-by: Zhigang Gong Reviewed-by: "Song, Ruiling" --- backend/src/backend/gen_insn_selection.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp index 0c3144b..f6f2ece 100644 --- a/backend/src/backend/gen_insn_selection.cpp +++ b/backend/src/backend/gen_insn_selection.cpp @@ -228,6 +228,7 @@ namespace gbe for (uint32_t childID = 0; childID < childNum; ++childID) this->child[childID] = NULL; computeBool = false; + isUsed = false; } /*! Mergeable are non-root instructions with valid sources */ INLINE void setAsMergeable(uint32_t which) { mergeable|=(1<computeBool = true; } + child->isUsed = true; } else dag->child[srcID] = NULL; } @@ -1841,8 +1845,10 @@ namespace gbe sel.MOV_DF(dst, src, sel.selReg(r)); } else { sel.push(); - if (sel.getRegisterFamily(insn.getDst(0)) == ir::FAMILY_BOOL) { - sel.curr.physicalFlag = 0; + auto dag = sel.regDAG[insn.getDst(0)]; + if (sel.getRegisterFamily(insn.getDst(0)) == ir::FAMILY_BOOL && + dag->isUsed) { + sel.curr.physicalFlag = 0; sel.curr.flagIndex = (uint16_t)(insn.getDst(0)); sel.curr.modFlag = 1; } @@ -2044,7 +2050,8 @@ namespace gbe bool inverse = false; sel.getSrcGenRegImm(dag, src0, src1, type, inverse); // Output the binary instruction - if (sel.getRegisterFamily(insn.getDst(0)) == ir::FAMILY_BOOL) { + if (sel.getRegisterFamily(insn.getDst(0)) == ir::FAMILY_BOOL && + dag.isUsed) { GBE_ASSERT(insn.getOpcode() == OP_AND || insn.getOpcode() == OP_OR || insn.getOpcode() == OP_XOR); @@ -2576,7 +2583,7 @@ namespace gbe switch (type) { case TYPE_BOOL: - if (!sel.isScalarReg(insn.getDst(0))) { + if (!sel.isScalarReg(insn.getDst(0)) && sel.regDAG[insn.getDst(0)]->isUsed) { sel.curr.modFlag = 1; sel.curr.physicalFlag = 0; sel.curr.flagIndex = (uint16_t) insn.getDst(0); -- 2.7.4