]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCRegisterInfo.cpp
MFV r316083,316094:
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MC / MCRegisterInfo.cpp
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
14 #include "llvm/MC/MCRegisterInfo.h"
15 #include "llvm/Support/Format.h"
16 #include "llvm/Support/raw_ostream.h"
17
18 using namespace llvm;
19
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))
24       return *Supers;
25   return 0;
26 }
27
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)
35     if (*SRI == Idx)
36       return *Subs;
37   return 0;
38 }
39
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)
46     if (*Subs == SubReg)
47       return *SRI;
48   return 0;
49 }
50
51 unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
52   assert(Idx && Idx < getNumSubRegIndices() &&
53          "This is not a subregister index");
54   return SubRegIdxRanges[Idx].Size;
55 }
56
57 unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
58   assert(Idx && Idx < getNumSubRegIndices() &&
59          "This is not a subregister index");
60   return SubRegIdxRanges[Idx].Offset;
61 }
62
63 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
64   const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
65   unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
66
67   if (!M)
68     return -1;
69   DwarfLLVMRegPair Key = { RegNum, 0 };
70   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
71   if (I == M+Size || I->FromReg != RegNum)
72     return -1;
73   return I->ToReg;
74 }
75
76 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
77   const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
78   unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
79
80   if (!M)
81     return -1;
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");
85   return I->ToReg;
86 }
87
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;
91   return I->second;
92 }
93
94 int MCRegisterInfo::getCodeViewRegNum(unsigned RegNum) const {
95   if (L2CVRegs.empty())
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");
100   return I->second;
101 }