/src/keystone/llvm/lib/MC/MCRegisterInfo.cpp
Line | Count | Source |
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_ks; |
17 | | |
18 | | unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx, |
19 | 186 | const MCRegisterClass *RC) const { |
20 | 189 | for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers) |
21 | 185 | if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx)) |
22 | 182 | return *Supers; |
23 | 4 | return 0; |
24 | 186 | } |
25 | | |
26 | 317 | unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const { |
27 | 317 | assert(Idx && Idx < getNumSubRegIndices() && |
28 | 317 | "This is not a subregister index"); |
29 | | // Get a pointer to the corresponding SubRegIndices list. This list has the |
30 | | // name of each sub-register in the same order as MCSubRegIterator. |
31 | 317 | const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices; |
32 | 452 | for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI) |
33 | 452 | if (*SRI == Idx) |
34 | 317 | return *Subs; |
35 | 0 | return 0; |
36 | 317 | } |
37 | | |
38 | 0 | unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const { |
39 | 0 | assert(SubReg && SubReg < getNumRegs() && "This is not a register"); |
40 | | // Get a pointer to the corresponding SubRegIndices list. This list has the |
41 | | // name of each sub-register in the same order as MCSubRegIterator. |
42 | 0 | const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices; |
43 | 0 | for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI) |
44 | 0 | if (*Subs == SubReg) |
45 | 0 | return *SRI; |
46 | 0 | return 0; |
47 | 0 | } |
48 | | |
49 | 0 | unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const { |
50 | 0 | assert(Idx && Idx < getNumSubRegIndices() && |
51 | 0 | "This is not a subregister index"); |
52 | 0 | return SubRegIdxRanges[Idx].Size; |
53 | 0 | } |
54 | | |
55 | 0 | unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const { |
56 | 0 | assert(Idx && Idx < getNumSubRegIndices() && |
57 | 0 | "This is not a subregister index"); |
58 | 0 | return SubRegIdxRanges[Idx].Offset; |
59 | 0 | } |
60 | | |
61 | 106k | int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const { |
62 | 106k | const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs; |
63 | 106k | unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize; |
64 | | |
65 | 106k | DwarfLLVMRegPair Key = { RegNum, 0 }; |
66 | 106k | const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key); |
67 | 106k | if (I == M+Size || I->FromReg != RegNum) |
68 | 0 | return -1; |
69 | 106k | return I->ToReg; |
70 | 106k | } |
71 | | |
72 | 0 | int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const { |
73 | 0 | const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs; |
74 | 0 | unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize; |
75 | |
|
76 | 0 | DwarfLLVMRegPair Key = { RegNum, 0 }; |
77 | 0 | const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key); |
78 | 0 | assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum"); |
79 | 0 | return I->ToReg; |
80 | 0 | } |
81 | | |
82 | 0 | int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const { |
83 | 0 | const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum); |
84 | 0 | if (I == L2SEHRegs.end()) return (int)RegNum; |
85 | 0 | return I->second; |
86 | 0 | } |