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 int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
00050   const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
00051   unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
00052 
00053   DwarfLLVMRegPair Key = { RegNum, 0 };
00054   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
00055   if (I == M+Size || I->FromReg != RegNum)
00056     return -1;
00057   return I->ToReg;
00058 }
00059 
00060 int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
00061   const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
00062   unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
00063 
00064   DwarfLLVMRegPair Key = { RegNum, 0 };
00065   const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
00066   assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
00067   return I->ToReg;
00068 }
00069 
00070 int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
00071   const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
00072   if (I == L2SEHRegs.end()) return (int)RegNum;
00073   return I->second;
00074 }