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/Target/MRegisterInfo.h"
24 class PhysRegTracker
{
25 const MRegisterInfo
* mri_
;
26 std::vector
<unsigned> regUse_
;
29 PhysRegTracker(const MRegisterInfo
& mri
)
31 regUse_(mri_
->getNumRegs(), 0) {
34 PhysRegTracker(const PhysRegTracker
& rhs
)
36 regUse_(rhs
.regUse_
) {
39 const PhysRegTracker
& operator=(const PhysRegTracker
& rhs
) {
41 regUse_
= rhs
.regUse_
;
45 void addRegUse(unsigned physReg
) {
46 assert(MRegisterInfo::isPhysicalRegister(physReg
) &&
47 "should be physical register!");
49 for (const unsigned* as
= mri_
->getAliasSet(physReg
); *as
; ++as
)
53 void delRegUse(unsigned physReg
) {
54 assert(MRegisterInfo::isPhysicalRegister(physReg
) &&
55 "should be physical register!");
56 assert(regUse_
[physReg
] != 0);
58 for (const unsigned* as
= mri_
->getAliasSet(physReg
); *as
; ++as
) {
59 assert(regUse_
[*as
] != 0);
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