diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h | 8 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp | 23 |
2 files changed, 25 insertions, 6 deletions
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h index c837e13cb43..19d17036585 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h @@ -216,6 +216,14 @@ public: iterator_range<SmallVectorImpl<unsigned>::iterator> getVRegsMem(unsigned OpIdx); + /// Get the end iterator for a range starting at \p StartIdx and + /// spannig \p NumVal in NewVRegs. + /// \pre StartIdx + NumVal <= NewVRegs.size() + SmallVectorImpl<unsigned>::const_iterator + getNewVRegsEnd(unsigned StartIdx, unsigned NumVal) const; + SmallVectorImpl<unsigned>::iterator getNewVRegsEnd(unsigned StartIdx, + unsigned NumVal); + public: /// Create an OperandsMapper that will hold the information to apply \p /// InstrMapping to \p MI. diff --git a/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp b/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp index f945a087e60..6173369f9cc 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp @@ -538,13 +538,26 @@ RegisterBankInfo::OperandsMapper::getVRegsMem(unsigned OpIdx) { NewVRegs.push_back(0); } SmallVectorImpl<unsigned>::iterator End = - NewVRegs.size() <= StartIdx + NumPartialVal + 1 - ? NewVRegs.end() - : &NewVRegs[StartIdx + NumPartialVal + 1]; + getNewVRegsEnd(StartIdx, NumPartialVal); return make_range(&NewVRegs[StartIdx], End); } +SmallVectorImpl<unsigned>::const_iterator +RegisterBankInfo::OperandsMapper::getNewVRegsEnd(unsigned StartIdx, + unsigned NumVal) const { + return const_cast<OperandsMapper *>(this)->getNewVRegsEnd(StartIdx, NumVal); +} +SmallVectorImpl<unsigned>::iterator +RegisterBankInfo::OperandsMapper::getNewVRegsEnd(unsigned StartIdx, + unsigned NumVal) { + assert((NewVRegs.size() == StartIdx + NumVal || + NewVRegs.size() > StartIdx + NumVal) && + "NewVRegs too small to contain all the partial mapping"); + return NewVRegs.size() <= StartIdx + NumVal ? NewVRegs.end() + : &NewVRegs[StartIdx + NumVal]; +} + void RegisterBankInfo::OperandsMapper::createVRegs(unsigned OpIdx) { assert(OpIdx < getMI().getNumOperands() && "Out-of-bound access"); iterator_range<SmallVectorImpl<unsigned>::iterator> NewVRegsForOpIdx = @@ -588,9 +601,7 @@ RegisterBankInfo::OperandsMapper::getVRegs(unsigned OpIdx, unsigned PartMapSize = getInstrMapping().getOperandMapping(OpIdx).BreakDown.size(); SmallVectorImpl<unsigned>::const_iterator End = - NewVRegs.size() <= StartIdx + PartMapSize + 1 - ? NewVRegs.end() - : &NewVRegs[StartIdx + PartMapSize + 1]; + getNewVRegsEnd(StartIdx, PartMapSize); iterator_range<SmallVectorImpl<unsigned>::const_iterator> Res = make_range(&NewVRegs[StartIdx], End); #ifndef NDEBUG |

