LLVM  4.0.0
MCRegisterInfo.cpp
Go to the documentation of this file.
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"
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 }
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
unsigned getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const
For a given register pair, return the sub-register index if the second register is a sub-register of ...
MCSuperRegIterator enumerates all super-registers of Reg.
unsigned SubReg
Reg
All possible values of the reg field in the ModR/M byte.
int getSEHRegNum(unsigned RegNum) const
Map a target register to an equivalent SEH register number.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
int getCodeViewRegNum(unsigned RegNum) const
Map a target register to an equivalent CodeView register number.
MCRegisterClass - Base class of TargetRegisterClass.
unsigned getSubReg(unsigned Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
int getLLVMRegNum(unsigned RegNum, bool isEH) const
Map a dwarf register back to a target register.
MCSubRegIterator enumerates all sub-registers of Reg.
unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg...
DwarfLLVMRegPair - Emitted by tablegen so Dwarf<->LLVM reg mappings can be performed with a binary se...
bool contains(unsigned Reg) const
contains - Return true if the specified register is included in this register class.
#define I(x, y, z)
Definition: MD5.cpp:54
iterator end()
Definition: DenseMap.h:69
iterator find(const KeyT &Val)
Definition: DenseMap.h:127
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index.
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:80
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getSubRegIdxSize(unsigned Idx) const
Get the size of the bit range covered by a sub-register index.