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