Reverting back to original 1.8 version so I can manually merge in patch.
[llvm-complete.git] / lib / CodeGen / PhysRegTracker.h
blobf5a240231cf2bb910f5c3818f8efdb1848bb5f37
1 //===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
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
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CODEGEN_PHYSREGTRACKER_H
18 #define LLVM_CODEGEN_PHYSREGTRACKER_H
20 #include "llvm/Target/MRegisterInfo.h"
22 namespace llvm {
24 class PhysRegTracker {
25 const MRegisterInfo* mri_;
26 std::vector<unsigned> regUse_;
28 public:
29 PhysRegTracker(const MRegisterInfo& mri)
30 : mri_(&mri),
31 regUse_(mri_->getNumRegs(), 0) {
34 PhysRegTracker(const PhysRegTracker& rhs)
35 : mri_(rhs.mri_),
36 regUse_(rhs.regUse_) {
39 const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
40 mri_ = rhs.mri_;
41 regUse_ = rhs.regUse_;
42 return *this;
45 void addRegUse(unsigned physReg) {
46 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
47 "should be physical register!");
48 ++regUse_[physReg];
49 for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as)
50 ++regUse_[*as];
53 void delRegUse(unsigned physReg) {
54 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
55 "should be physical register!");
56 assert(regUse_[physReg] != 0);
57 --regUse_[physReg];
58 for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) {
59 assert(regUse_[*as] != 0);
60 --regUse_[*as];
64 bool isRegAvail(unsigned physReg) const {
65 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
66 "should be physical register!");
67 return regUse_[physReg] == 0;
71 } // End llvm namespace
73 #endif