LLVM API Documentation

MCRegisterInfo.cpp
Go to the documentation of this file.
00001 //=== MC/MCRegisterInfo.cpp - Target Register Description -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements MCRegisterInfo functions.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/MC/MCRegisterInfo.h"
00015 
00016 using namespace llvm;
00017 
00018 unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
00019                                              const MCRegisterClass *RC) const {
00020   for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers)
00021     if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx))
00022       return *Supers;
00023   return 0;
00024 }
00025 
00026 unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const {
00027   assert(Idx && Idx < getNumSubRegIndices() &&
00028          "This is not a subregister index");
00029   // Get a pointer to the corresponding SubRegIndices list. This list has the
00030   // name of each sub-register in the same order as MCSubRegIterator.
00031   const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
00032   for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
00033     if (*SRI == Idx)
00034       return *Subs;
00035   return 0;
00036 }
00037 
00038 unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
00039   assert(SubReg && SubReg < getNumRegs() && "This is not a register");
00040   // Get a pointer to the corresponding SubRegIndices list. This list has the
00041   // name of each sub-register in the same order as MCSubRegIterator.
00042   const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
00043   for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
00044     if (*Subs == SubReg)
00045       return *SRI;
00046   return 0;
00047 }
00048 
00049 unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
00050   assert(Idx && Idx < getNumSubRegIndices() &&
00051          "This is not a subregister index");
00052   return SubRegIdxRanges[Idx].Size;
00053 }
00054 
00055 unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
00056   assert(Idx && Idx < getNumSubRegIndices() &&
00057          "This is not a subregister index");
00058   return SubRegIdxRanges[Idx].Offset;
00059 }
00060 
00061 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
00062   const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
00063   unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
00064 
00065   DwarfLLVMRegPair Key = { RegNum, 0 };
00066   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
00067   if (I == M+Size || I->FromReg != RegNum)
00068     return -1;
00069   return I->ToReg;
00070 }
00071 
00072 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
00073   const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
00074   unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
00075 
00076   DwarfLLVMRegPair Key = { RegNum, 0 };
00077   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
00078   assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
00079   return I->ToReg;
00080 }
00081 
00082 int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
00083   const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
00084   if (I == L2SEHRegs.end()) return (int)RegNum;
00085   return I->second;
00086 }