From: Krzysztof Parzyszek Date: Fri, 10 Mar 2017 22:44:24 +0000 (+0000) Subject: [RDF] Remove the map of reaching defs from copy propagation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f2421b3c0a0ca2f8c68ed795f17afea9268ce32;p=llvm [RDF] Remove the map of reaching defs from copy propagation Use Liveness::getNearestAliasedRef to find the reaching def instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297526 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/Hexagon/RDFCopy.cpp b/lib/Target/Hexagon/RDFCopy.cpp index 392ab7af6c2..57ce9fabc5e 100644 --- a/lib/Target/Hexagon/RDFCopy.cpp +++ b/lib/Target/Hexagon/RDFCopy.cpp @@ -11,6 +11,7 @@ #include "RDFCopy.h" #include "RDFGraph.h" +#include "RDFLiveness.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineInstr.h" @@ -53,47 +54,12 @@ bool CopyPropagation::interpretAsCopy(const MachineInstr *MI, EqualityMap &EM) { void CopyPropagation::recordCopy(NodeAddr SA, EqualityMap &EM) { CopyMap.insert(std::make_pair(SA.Id, EM)); Copies.push_back(SA.Id); - - for (auto I : EM) { - auto FS = DefM.find(I.second.Reg); - if (FS == DefM.end() || FS->second.empty()) - continue; // Undefined source - RDefMap[I.second][SA.Id] = FS->second.top()->Id; - // Insert DstR into the map. - RDefMap[I.first]; - } -} - - -void CopyPropagation::updateMap(NodeAddr IA) { - RegisterSet RRs; - for (NodeAddr RA : IA.Addr->members(DFG)) - RRs.insert(RA.Addr->getRegRef(DFG)); - bool Common = false; - for (auto &R : RDefMap) { - if (!RRs.count(R.first)) - continue; - Common = true; - break; - } - if (!Common) - return; - - for (auto &R : RDefMap) { - if (!RRs.count(R.first)) - continue; - auto F = DefM.find(R.first.Reg); - if (F == DefM.end() || F->second.empty()) - continue; - R.second[IA.Id] = F->second.top()->Id; - } } bool CopyPropagation::scanBlock(MachineBasicBlock *B) { bool Changed = false; auto BA = DFG.getFunc().Addr->findBlock(B, DFG); - DFG.markBlock(BA.Id, DefM); for (NodeAddr IA : BA.Addr->members(DFG)) { if (DFG.IsCode(IA)) { @@ -102,20 +68,30 @@ bool CopyPropagation::scanBlock(MachineBasicBlock *B) { if (interpretAsCopy(SA.Addr->getCode(), EM)) recordCopy(SA, EM); } - - updateMap(IA); - DFG.pushAllDefs(IA, DefM); } MachineDomTreeNode *N = MDT.getNode(B); for (auto I : *N) Changed |= scanBlock(I->getBlock()); - DFG.releaseBlock(BA.Id, DefM); return Changed; } +NodeId CopyPropagation::getLocalReachingDef(RegisterRef RefRR, + NodeAddr IA) { + NodeAddr RA = L.getNearestAliasedRef(RefRR, IA); + if (RA.Id != 0) { + if (RA.Addr->getKind() == NodeAttrs::Def) + return RA.Id; + assert(RA.Addr->getKind() == NodeAttrs::Use); + if (NodeId RD = RA.Addr->getReachingDef()) + return RD; + } + return 0; +} + + bool CopyPropagation::run() { scanBlock(&DFG.getMF().front()); @@ -129,14 +105,6 @@ bool CopyPropagation::run() { << Print(J.second, DFG); dbgs() << " }\n"; } - dbgs() << "\nRDef map:\n"; - for (auto R : RDefMap) { - dbgs() << Print(R.first, DFG) << " -> {"; - for (auto &M : R.second) - dbgs() << ' ' << Print(M.first, DFG) << ':' - << Print(M.second, DFG); - dbgs() << " }\n"; - } } bool Changed = false; @@ -176,8 +144,7 @@ bool CopyPropagation::run() { if (DR == SR) continue; - auto &RDefSR = RDefMap[SR]; - NodeId RDefSR_SA = RDefSR[SA.Id]; + NodeId AtCopy = getLocalReachingDef(SR, SA); for (NodeId N = DA.Addr->getReachedUse(), NextN; N; N = NextN) { auto UA = DFG.addr(N); @@ -190,7 +157,8 @@ bool CopyPropagation::run() { NodeAddr IA = UA.Addr->getOwner(DFG); assert(DFG.IsCode(IA)); - if (RDefSR[IA.Id] != RDefSR_SA) + NodeId AtUse = getLocalReachingDef(SR, IA); + if (AtCopy != AtUse) continue; MachineOperand &Op = UA.Addr->getOp(); @@ -206,8 +174,8 @@ bool CopyPropagation::run() { Op.setReg(NewReg); Op.setSubReg(0); DFG.unlinkUse(UA, false); - if (RDefSR_SA != 0) { - UA.Addr->linkToDef(UA.Id, DFG.addr(RDefSR_SA)); + if (AtCopy != 0) { + UA.Addr->linkToDef(UA.Id, DFG.addr(AtCopy)); } else { UA.Addr->setReachingDef(0); UA.Addr->setSibling(0); diff --git a/lib/Target/Hexagon/RDFCopy.h b/lib/Target/Hexagon/RDFCopy.h index 5ece11bd5ce..bbd625c5f5f 100644 --- a/lib/Target/Hexagon/RDFCopy.h +++ b/lib/Target/Hexagon/RDFCopy.h @@ -11,6 +11,9 @@ #define LLVM_LIB_TARGET_HEXAGON_RDFCOPY_H #include "RDFGraph.h" +#include "RDFLiveness.h" +#include "llvm/CodeGen/MachineFunction.h" + #include #include @@ -24,7 +27,7 @@ namespace rdf { struct CopyPropagation { CopyPropagation(DataFlowGraph &dfg) : MDT(dfg.getDT()), DFG(dfg), - Trace(false) {} + L(dfg.getMF().getRegInfo(), dfg), Trace(false) {} virtual ~CopyPropagation() = default; @@ -39,18 +42,16 @@ namespace rdf { private: const MachineDominatorTree &MDT; DataFlowGraph &DFG; - DataFlowGraph::DefStackMap DefM; + Liveness L; bool Trace; - // map: register -> (map: stmt -> reaching def) - std::map> RDefMap; // map: statement -> (map: dst reg -> src reg) std::map CopyMap; std::vector Copies; void recordCopy(NodeAddr SA, EqualityMap &EM); - void updateMap(NodeAddr IA); bool scanBlock(MachineBasicBlock *B); + NodeId getLocalReachingDef(RegisterRef RefRR, NodeAddr IA); }; } // end namespace rdf diff --git a/test/CodeGen/Hexagon/pred-absolute-store.ll b/test/CodeGen/Hexagon/pred-absolute-store.ll index 3e5e98270d5..2f19e9aeb7b 100644 --- a/test/CodeGen/Hexagon/pred-absolute-store.ll +++ b/test/CodeGen/Hexagon/pred-absolute-store.ll @@ -1,7 +1,7 @@ ; RUN: llc -march=hexagon < %s | FileCheck %s -; Check that we are able to predicate instructions with abosolute +; Check that we are able to predicate instructions with absolute ; addressing mode. -; CHECK: if ({{!*}}p{{[0-2]}}.new) memw(##gvar) = r{{[0-9]+}} +; CHECK: if ({{!?}}p{{[0-3]}}) memw(##gvar) = r{{[0-9]+}} @gvar = external global i32 define i32 @test2(i32 %a, i32 %b) nounwind {