LLVM API Documentation
00001 //===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements a physical register tracker. The tracker 00011 // tracks physical register usage through addRegUse and 00012 // delRegUse. isRegAvail checks if a physical register is available or 00013 // not taking into consideration register aliases. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef LLVM_CODEGEN_PHYSREGTRACKER_H 00018 #define LLVM_CODEGEN_PHYSREGTRACKER_H 00019 00020 #include "llvm/Target/MRegisterInfo.h" 00021 00022 namespace llvm { 00023 00024 class PhysRegTracker { 00025 const MRegisterInfo* mri_; 00026 std::vector<unsigned> regUse_; 00027 00028 public: 00029 PhysRegTracker(const MRegisterInfo& mri) 00030 : mri_(&mri), 00031 regUse_(mri_->getNumRegs(), 0) { 00032 } 00033 00034 PhysRegTracker(const PhysRegTracker& rhs) 00035 : mri_(rhs.mri_), 00036 regUse_(rhs.regUse_) { 00037 } 00038 00039 const PhysRegTracker& operator=(const PhysRegTracker& rhs) { 00040 mri_ = rhs.mri_; 00041 regUse_ = rhs.regUse_; 00042 return *this; 00043 } 00044 00045 void addRegUse(unsigned physReg) { 00046 assert(MRegisterInfo::isPhysicalRegister(physReg) && 00047 "should be physical register!"); 00048 ++regUse_[physReg]; 00049 for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) 00050 ++regUse_[*as]; 00051 } 00052 00053 void delRegUse(unsigned physReg) { 00054 assert(MRegisterInfo::isPhysicalRegister(physReg) && 00055 "should be physical register!"); 00056 assert(regUse_[physReg] != 0); 00057 --regUse_[physReg]; 00058 for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) { 00059 assert(regUse_[*as] != 0); 00060 --regUse_[*as]; 00061 } 00062 } 00063 00064 bool isRegAvail(unsigned physReg) const { 00065 assert(MRegisterInfo::isPhysicalRegister(physReg) && 00066 "should be physical register!"); 00067 return regUse_[physReg] == 0; 00068 } 00069 }; 00070 00071 } // End llvm namespace 00072 00073 #endif