Index: include/llvm/MC/MCRegisterInfo.h =================================================================== --- include/llvm/MC/MCRegisterInfo.h +++ include/llvm/MC/MCRegisterInfo.h @@ -381,7 +381,17 @@ int getDwarfRegNum(unsigned RegNum, bool isEH) const; /// \brief Map a dwarf register back to a target register. - int getLLVMRegNum(unsigned RegNum, bool isEH) const; + /// This method might assert if no mapping exists. + unsigned getLLVMRegNum(unsigned RegNum, bool isEH) const { + int LLVMRegNum = tryGetLLVMRegNum(RegNum, isEH); + assert(LLVMRegNum != -1 && "Invalid RegNum"); + return LLVMRegNum; + } + + /// \brief Map a Dwarf register back to a target register. + /// \returns the corresponding LLVM register number or -1 if the + /// passed Dwarf register is invalid. + int tryGetLLVMRegNum(unsigned RegNum, bool isEH) const; /// \brief Map a target register to an equivalent SEH register /// number. Returns LLVM register number if there is no equivalent value. Index: lib/MC/MCRegisterInfo.cpp =================================================================== --- lib/MC/MCRegisterInfo.cpp +++ lib/MC/MCRegisterInfo.cpp @@ -69,13 +69,14 @@ return I->ToReg; } -int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const { +int MCRegisterInfo::tryGetLLVMRegNum(unsigned RegNum, bool isEH) const { const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs; unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize; DwarfLLVMRegPair Key = { RegNum, 0 }; const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key); - assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum"); + if (I == M+Size || I->FromReg != RegNum) + return -1; return I->ToReg; }