diff options
author | Evan Cheng <evan.cheng@apple.com> | 2007-10-18 07:49:59 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2007-10-18 07:49:59 +0000 |
commit | 4ae31a5d3297af4c6e9752ec91d76b6daa0fc05c (patch) | |
tree | 6527351c0aed04902c6cb7250531c61023a16432 /lib/CodeGen/SimpleRegisterCoalescing.cpp | |
parent | cf1d7256d0bb1e9e3101bf201e4d60529b30b6ff (diff) | |
download | external_llvm-4ae31a5d3297af4c6e9752ec91d76b6daa0fc05c.zip external_llvm-4ae31a5d3297af4c6e9752ec91d76b6daa0fc05c.tar.gz external_llvm-4ae31a5d3297af4c6e9752ec91d76b6daa0fc05c.tar.bz2 |
Really fix PR1734. Carefully track which register uses are sub-register uses by
traversing inverse register coalescing map.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43118 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SimpleRegisterCoalescing.cpp')
-rw-r--r-- | lib/CodeGen/SimpleRegisterCoalescing.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/CodeGen/SimpleRegisterCoalescing.cpp b/lib/CodeGen/SimpleRegisterCoalescing.cpp index ee2cbbb..b2c29fc 100644 --- a/lib/CodeGen/SimpleRegisterCoalescing.cpp +++ b/lib/CodeGen/SimpleRegisterCoalescing.cpp @@ -57,7 +57,6 @@ namespace { const PassInfo *llvm::SimpleRegisterCoalescingID = X.getPassInfo(); void SimpleRegisterCoalescing::getAnalysisUsage(AnalysisUsage &AU) const { - //AU.addPreserved<LiveVariables>(); AU.addPreserved<LiveIntervals>(); AU.addPreservedID(PHIEliminationID); AU.addPreservedID(TwoAddressInstructionPassID); @@ -185,6 +184,17 @@ bool SimpleRegisterCoalescing::AdjustCopiesBackFrom(LiveInterval &IntA, LiveInte return true; } +/// AddSubRegIdxPairs - Recursively mark all the registers represented by the +/// specified register as sub-registers. The recursion level is expected to be +/// shallow. +void SimpleRegisterCoalescing::AddSubRegIdxPairs(unsigned Reg, unsigned SubIdx) { + std::vector<unsigned> &JoinedRegs = r2rRevMap_[Reg]; + for (unsigned i = 0, e = JoinedRegs.size(); i != e; ++i) { + SubRegIdxes.push_back(std::make_pair(JoinedRegs[i], SubIdx)); + AddSubRegIdxPairs(JoinedRegs[i], SubIdx); + } +} + /// JoinCopy - Attempt to join intervals corresponding to SrcReg/DstReg, /// which are the src/dst of the copy instruction CopyMI. This returns true /// if the copy was successfully coalesced away, or if it is never possible @@ -459,8 +469,9 @@ bool SimpleRegisterCoalescing::JoinCopy(MachineInstr *CopyMI, std::swap(repSrcReg, repDstReg); std::swap(ResSrcInt, ResDstInt); } - SubRegIdxes.push_back(std::make_pair(DstReg, - CopyMI->getOperand(2).getImm())); + unsigned SubIdx = CopyMI->getOperand(2).getImm(); + SubRegIdxes.push_back(std::make_pair(repSrcReg, SubIdx)); + AddSubRegIdxPairs(repSrcReg, SubIdx); } DOUT << "\n\t\tJoined. Result = "; ResDstInt->print(DOUT, mri_); @@ -470,6 +481,7 @@ bool SimpleRegisterCoalescing::JoinCopy(MachineInstr *CopyMI, // being merged. li_->removeInterval(repSrcReg); r2rMap_[repSrcReg] = repDstReg; + r2rRevMap_[repDstReg].push_back(repSrcReg); // Finally, delete the copy instruction. li_->RemoveMachineInstrFromMaps(CopyMI); @@ -1039,7 +1051,7 @@ void SimpleRegisterCoalescing::joinIntervals() { } DOUT << "*** Register mapping ***\n"; - for (int i = 0, e = r2rMap_.size(); i != e; ++i) + for (unsigned i = 0, e = r2rMap_.size(); i != e; ++i) if (r2rMap_[i]) { DOUT << " reg " << i << " -> "; DEBUG(printRegName(r2rMap_[i])); @@ -1172,9 +1184,12 @@ void SimpleRegisterCoalescing::printRegName(unsigned reg) const { } void SimpleRegisterCoalescing::releaseMemory() { - r2rMap_.clear(); - JoinedLIs.clear(); - SubRegIdxes.clear(); + for (unsigned i = 0, e = r2rMap_.size(); i != e; ++i) + r2rRevMap_[i].clear(); + r2rRevMap_.clear(); + r2rMap_.clear(); + JoinedLIs.clear(); + SubRegIdxes.clear(); } static bool isZeroLengthInterval(LiveInterval *li) { @@ -1204,6 +1219,7 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) { SSARegMap *RegMap = mf_->getSSARegMap(); r2rMap_.grow(RegMap->getLastVirtReg()); + r2rRevMap_.grow(RegMap->getLastVirtReg()); // Join (coalesce) intervals if requested. if (EnableJoining) { @@ -1214,7 +1230,8 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) { DOUT << "\n"; } - // Track coalesced sub-registers. + // Transfer sub-registers info to SSARegMap now that coalescing information + // is complete. while (!SubRegIdxes.empty()) { std::pair<unsigned, unsigned> RI = SubRegIdxes.back(); SubRegIdxes.pop_back(); |