MCRegisterInfo.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //=== MC/MCRegisterInfo.cpp - Target Register Description -------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements MCRegisterInfo functions.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/MC/MCRegisterInfo.h"
  14. using namespace llvm;
  15. unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
  16. const MCRegisterClass *RC) const {
  17. for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers)
  18. if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx))
  19. return *Supers;
  20. return 0;
  21. }
  22. unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const {
  23. assert(Idx && Idx < getNumSubRegIndices() &&
  24. "This is not a subregister index");
  25. // Get a pointer to the corresponding SubRegIndices list. This list has the
  26. // name of each sub-register in the same order as MCSubRegIterator.
  27. const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
  28. for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
  29. if (*SRI == Idx)
  30. return *Subs;
  31. return 0;
  32. }
  33. unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
  34. assert(SubReg && SubReg < getNumRegs() && "This is not a register");
  35. // Get a pointer to the corresponding SubRegIndices list. This list has the
  36. // name of each sub-register in the same order as MCSubRegIterator.
  37. const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
  38. for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
  39. if (*Subs == SubReg)
  40. return *SRI;
  41. return 0;
  42. }
  43. unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
  44. assert(Idx && Idx < getNumSubRegIndices() &&
  45. "This is not a subregister index");
  46. return SubRegIdxRanges[Idx].Size;
  47. }
  48. unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
  49. assert(Idx && Idx < getNumSubRegIndices() &&
  50. "This is not a subregister index");
  51. return SubRegIdxRanges[Idx].Offset;
  52. }
  53. int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
  54. const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
  55. unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
  56. DwarfLLVMRegPair Key = { RegNum, 0 };
  57. const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
  58. if (I == M+Size || I->FromReg != RegNum)
  59. return -1;
  60. return I->ToReg;
  61. }
  62. int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
  63. const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
  64. unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
  65. DwarfLLVMRegPair Key = { RegNum, 0 };
  66. const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
  67. assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
  68. return I->ToReg;
  69. }
  70. int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
  71. const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
  72. if (I == L2SEHRegs.end()) return (int)RegNum;
  73. return I->second;
  74. }