Give MCRegisterInfo an implementation file.
[oota-llvm.git] / 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
16 using namespace llvm;
17
18 unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
19                                              const MCRegisterClass *RC) const {
20   for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers)
21     if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx))
22       return *Supers;
23   return 0;
24 }
25
26 unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const {
27   // Get a pointer to the corresponding SubRegIndices list. This list has the
28   // name of each sub-register in the same order as MCSubRegIterator.
29   const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
30   for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
31     if (*SRI == Idx)
32       return *Subs;
33   return 0;
34 }
35
36 unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
37   // Get a pointer to the corresponding SubRegIndices list. This list has the
38   // name of each sub-register in the same order as MCSubRegIterator.
39   const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
40   for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
41     if (*Subs == SubReg)
42       return *SRI;
43   return 0;
44 }
45
46 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
47   const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
48   unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
49
50   DwarfLLVMRegPair Key = { RegNum, 0 };
51   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
52   if (I == M+Size || I->FromReg != RegNum)
53     return -1;
54   return I->ToReg;
55 }
56
57 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
58   const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
59   unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
60
61   DwarfLLVMRegPair Key = { RegNum, 0 };
62   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
63   assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
64   return I->ToReg;
65 }
66
67 int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
68   const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
69   if (I == L2SEHRegs.end()) return (int)RegNum;
70   return I->second;
71 }