LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
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  assert(Idx && Idx < getNumSubRegIndices() &&
28  "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  const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
32  for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
33  if (*SRI == Idx)
34  return *Subs;
35  return 0;
36 }
37 
38 unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
39  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  const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
43  for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
44  if (*Subs == SubReg)
45  return *SRI;
46  return 0;
47 }
48 
49 unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
50  assert(Idx && Idx < getNumSubRegIndices() &&
51  "This is not a subregister index");
52  return SubRegIdxRanges[Idx].Size;
53 }
54 
55 unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
56  assert(Idx && Idx < getNumSubRegIndices() &&
57  "This is not a subregister index");
58  return SubRegIdxRanges[Idx].Offset;
59 }
60 
61 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
62  const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
63  unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
64 
65  DwarfLLVMRegPair Key = { RegNum, 0 };
66  const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
67  if (I == M+Size || I->FromReg != RegNum)
68  return -1;
69  return I->ToReg;
70 }
71 
72 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
73  const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
74  unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
75 
76  DwarfLLVMRegPair Key = { RegNum, 0 };
77  const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
78  assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
79  return I->ToReg;
80 }
81 
82 int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
83  const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
84  if (I == L2SEHRegs.end()) return (int)RegNum;
85  return I->second;
86 }
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number. Returns -1 if there is no equivalent va...
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 ...
int getSEHRegNum(unsigned RegNum) const
Map a target register to an equivalent SEH register number. Returns LLVM register number if there is ...
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. Index 0 is reserved for the no-op...
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...
iterator end()
Definition: DenseMap.h:57
int getLLVMRegNum(unsigned RegNum, bool isEH) const
Map a dwarf register back to a target register.
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...
bool contains(unsigned Reg) const
#define I(x, y, z)
Definition: MD5.cpp:54
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index. If an Offset doesn't make sense (the...
unsigned getSubRegIdxSize(unsigned Idx) const
Get the size of the bit range covered by a sub-register index. If the index isn't continuous...
iterator find(const KeyT &Val)
Definition: DenseMap.h:108