1 //===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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/CodeGen/MachineFunction.h"
24 class PhysRegTracker {
25 const MRegisterInfo* mri_;
26 std::vector<unsigned> regUse_;
29 PhysRegTracker(MachineFunction* mf)
30 : mri_(mf ? mf->getTarget().getRegisterInfo() : NULL) {
32 regUse_.assign(mri_->getNumRegs(), 0);
36 PhysRegTracker(const PhysRegTracker& rhs)
38 regUse_(rhs.regUse_) {
41 const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
43 regUse_ = rhs.regUse_;
47 void addRegUse(unsigned physReg) {
48 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
49 "should be physical register!");
51 for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as)
55 void delRegUse(unsigned physReg) {
56 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
57 "should be physical register!");
58 assert(regUse_[physReg] != 0);
60 for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) {
61 assert(regUse_[*as] != 0);
66 bool isRegAvail(unsigned physReg) const {
67 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
68 "should be physical register!");
69 return regUse_[physReg] == 0;
73 } // End llvm namespace