LLVM API Documentation

TargetRegisterInfo.cpp

Go to the documentation of this file.
00001 //===- TargetRegisterInfo.cpp - Target Register Information Implementation ===//
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 the TargetRegisterInfo interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Target/TargetMachine.h"
00015 #include "llvm/Target/TargetRegisterInfo.h"
00016 #include "llvm/Target/TargetFrameInfo.h"
00017 #include "llvm/CodeGen/MachineFunction.h"
00018 #include "llvm/CodeGen/MachineFrameInfo.h"
00019 #include "llvm/ADT/BitVector.h"
00020 
00021 using namespace llvm;
00022 
00023 TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
00024                              regclass_iterator RCB, regclass_iterator RCE,
00025                              int CFSO, int CFDO,
00026                              const unsigned* subregs, const unsigned subregsize)
00027   : SubregHash(subregs), SubregHashSize(subregsize), Desc(D), NumRegs(NR),
00028     RegClassBegin(RCB), RegClassEnd(RCE) {
00029   assert(NumRegs < FirstVirtualRegister &&
00030          "Target has too many physical registers!");
00031 
00032   CallFrameSetupOpcode   = CFSO;
00033   CallFrameDestroyOpcode = CFDO;
00034 }
00035 
00036 TargetRegisterInfo::~TargetRegisterInfo() {}
00037 
00038 /// getPhysicalRegisterRegClass - Returns the Register Class of a physical
00039 /// register of the given type. If type is MVT::Other, then just return any
00040 /// register class the register belongs to.
00041 const TargetRegisterClass *
00042 TargetRegisterInfo::getPhysicalRegisterRegClass(unsigned reg, MVT VT) const {
00043   assert(isPhysicalRegister(reg) && "reg must be a physical register");
00044 
00045   // Pick the most super register class of the right type that contains
00046   // this physreg.
00047   const TargetRegisterClass* BestRC = 0;
00048   for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I){
00049     const TargetRegisterClass* RC = *I;
00050     if ((VT == MVT::Other || RC->hasType(VT)) && RC->contains(reg) &&
00051         (!BestRC || BestRC->hasSuperClass(RC)))
00052       BestRC = RC;
00053   }
00054 
00055   assert(BestRC && "Couldn't find the register class");
00056   return BestRC;
00057 }
00058 
00059 /// getAllocatableSetForRC - Toggle the bits that represent allocatable
00060 /// registers for the specific register class.
00061 static void getAllocatableSetForRC(MachineFunction &MF,
00062                                    const TargetRegisterClass *RC, BitVector &R){  
00063   for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
00064          E = RC->allocation_order_end(MF); I != E; ++I)
00065     R.set(*I);
00066 }
00067 
00068 BitVector TargetRegisterInfo::getAllocatableSet(MachineFunction &MF,
00069                                           const TargetRegisterClass *RC) const {
00070   BitVector Allocatable(NumRegs);
00071   if (RC) {
00072     getAllocatableSetForRC(MF, RC, Allocatable);
00073     return Allocatable;
00074   }
00075 
00076   for (TargetRegisterInfo::regclass_iterator I = regclass_begin(),
00077          E = regclass_end(); I != E; ++I)
00078     getAllocatableSetForRC(MF, *I, Allocatable);
00079   return Allocatable;
00080 }
00081 
00082 /// getFrameIndexOffset - Returns the displacement from the frame register to
00083 /// the stack frame of the specified index. This is the default implementation
00084 /// which is likely incorrect for the target.
00085 int TargetRegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
00086   const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
00087   MachineFrameInfo *MFI = MF.getFrameInfo();
00088   return MFI->getObjectOffset(FI) + MFI->getStackSize() -
00089     TFI.getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
00090 }
00091 
00092 /// getInitialFrameState - Returns a list of machine moves that are assumed
00093 /// on entry to a function.
00094 void
00095 TargetRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
00096   // Default is to do nothing.
00097 }
00098 



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.