Alkis Evlogimenos | 534f545 | 2004-02-23 01:25:05 +0000 | [diff] [blame^] | 1 | //===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=// |
Alkis Evlogimenos | 888b1a6 | 2004-02-23 00:53:31 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements a physical register tracker. The tracker |
Alkis Evlogimenos | 534f545 | 2004-02-23 01:25:05 +0000 | [diff] [blame^] | 11 | // tracks physical register usage through addRegUse and |
| 12 | // delRegUse. isRegAvail checks if a physical register is available or |
| 13 | // not taking into consideration register aliases. |
Alkis Evlogimenos | 888b1a6 | 2004-02-23 00:53:31 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #ifndef LLVM_CODEGEN_PHYSREGTRACKER_H |
| 18 | #define LLVM_CODEGEN_PHYSREGTRACKER_H |
| 19 | |
| 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | class PhysRegTracker { |
| 26 | private: |
| 27 | const MRegisterInfo* mri_; |
| 28 | std::vector<unsigned> regUse_; |
| 29 | |
| 30 | public: |
| 31 | PhysRegTracker(MachineFunction* mf) |
| 32 | : mri_(mf ? mf->getTarget().getRegisterInfo() : NULL) { |
| 33 | if (mri_) { |
| 34 | regUse_.assign(mri_->getNumRegs(), 0); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | PhysRegTracker(const PhysRegTracker& rhs) |
| 39 | : mri_(rhs.mri_), |
| 40 | regUse_(rhs.regUse_) { |
| 41 | } |
| 42 | |
| 43 | const PhysRegTracker& operator=(const PhysRegTracker& rhs) { |
| 44 | mri_ = rhs.mri_; |
| 45 | regUse_ = rhs.regUse_; |
| 46 | return *this; |
| 47 | } |
| 48 | |
| 49 | void addRegUse(unsigned physReg) { |
| 50 | assert(MRegisterInfo::isPhysicalRegister(physReg) && |
| 51 | "should be physical register!"); |
| 52 | ++regUse_[physReg]; |
| 53 | for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) { |
| 54 | physReg = *as; |
| 55 | ++regUse_[physReg]; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void delRegUse(unsigned physReg) { |
| 60 | assert(MRegisterInfo::isPhysicalRegister(physReg) && |
| 61 | "should be physical register!"); |
| 62 | assert(regUse_[physReg] != 0); |
| 63 | --regUse_[physReg]; |
| 64 | for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) { |
| 65 | physReg = *as; |
| 66 | assert(regUse_[physReg] != 0); |
| 67 | --regUse_[physReg]; |
| 68 | } |
| 69 | } |
| 70 | |
Alkis Evlogimenos | 534f545 | 2004-02-23 01:25:05 +0000 | [diff] [blame^] | 71 | bool isRegAvail(unsigned physReg) const { |
Alkis Evlogimenos | 888b1a6 | 2004-02-23 00:53:31 +0000 | [diff] [blame] | 72 | assert(MRegisterInfo::isPhysicalRegister(physReg) && |
| 73 | "should be physical register!"); |
| 74 | return regUse_[physReg] == 0; |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | } // End llvm namespace |
| 79 | |
| 80 | #endif |