1 //=== MC/MCRegisterInfo.cpp - Target Register Description -------*- C++ -*-===//
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/Support/Format.h"
16 #include "llvm/Support/raw_ostream.h"
20 unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
21 const MCRegisterClass *RC) const {
22 for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers)
23 if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx))
28 unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const {
29 assert(Idx && Idx < getNumSubRegIndices() &&
30 "This is not a subregister index");
31 // Get a pointer to the corresponding SubRegIndices list. This list has the
32 // name of each sub-register in the same order as MCSubRegIterator.
33 const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
34 for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
40 unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
41 assert(SubReg && SubReg < getNumRegs() && "This is not a register");
42 // Get a pointer to the corresponding SubRegIndices list. This list has the
43 // name of each sub-register in the same order as MCSubRegIterator.
44 const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
45 for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
51 unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
52 assert(Idx && Idx < getNumSubRegIndices() &&
53 "This is not a subregister index");
54 return SubRegIdxRanges[Idx].Size;
57 unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
58 assert(Idx && Idx < getNumSubRegIndices() &&
59 "This is not a subregister index");
60 return SubRegIdxRanges[Idx].Offset;
63 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
64 const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
65 unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
69 DwarfLLVMRegPair Key = { RegNum, 0 };
70 const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
71 if (I == M+Size || I->FromReg != RegNum)
76 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
77 const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
78 unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
82 DwarfLLVMRegPair Key = { RegNum, 0 };
83 const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
84 assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
88 int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
89 const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
90 if (I == L2SEHRegs.end()) return (int)RegNum;
94 int MCRegisterInfo::getCodeViewRegNum(unsigned RegNum) const {
96 report_fatal_error("target does not implement codeview register mapping");
97 const DenseMap<unsigned, int>::const_iterator I = L2CVRegs.find(RegNum);
98 if (I == L2CVRegs.end())
99 report_fatal_error("unknown codeview register");