1 //===- MC/MCRegisterInfo.cpp - Target Register Description ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements MCRegisterInfo functions.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/MCRegisterInfo.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/Support/ErrorHandling.h"
23 unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
24 const MCRegisterClass *RC) const {
25 for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers)
26 if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx))
31 unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const {
32 assert(Idx && Idx < getNumSubRegIndices() &&
33 "This is not a subregister index");
34 // Get a pointer to the corresponding SubRegIndices list. This list has the
35 // name of each sub-register in the same order as MCSubRegIterator.
36 const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
37 for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
43 unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
44 assert(SubReg && SubReg < getNumRegs() && "This is not a register");
45 // Get a pointer to the corresponding SubRegIndices list. This list has the
46 // name of each sub-register in the same order as MCSubRegIterator.
47 const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
48 for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
54 unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
55 assert(Idx && Idx < getNumSubRegIndices() &&
56 "This is not a subregister index");
57 return SubRegIdxRanges[Idx].Size;
60 unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
61 assert(Idx && Idx < getNumSubRegIndices() &&
62 "This is not a subregister index");
63 return SubRegIdxRanges[Idx].Offset;
66 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
67 const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
68 unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
72 DwarfLLVMRegPair Key = { RegNum, 0 };
73 const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
74 if (I == M+Size || I->FromReg != RegNum)
79 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
80 const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
81 unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
85 DwarfLLVMRegPair Key = { RegNum, 0 };
86 const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
87 assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
91 int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
92 const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
93 if (I == L2SEHRegs.end()) return (int)RegNum;
97 int MCRegisterInfo::getCodeViewRegNum(unsigned RegNum) const {
99 report_fatal_error("target does not implement codeview register mapping");
100 const DenseMap<unsigned, int>::const_iterator I = L2CVRegs.find(RegNum);
101 if (I == L2CVRegs.end())
102 report_fatal_error("unknown codeview register");