1 //===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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/TargetRegisterInfo.h"
24 class PhysRegTracker
{
25 const TargetRegisterInfo
* tri_
;
26 std::vector
<unsigned> regUse_
;
29 explicit PhysRegTracker(const TargetRegisterInfo
& tri
)
31 regUse_(tri_
->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(TargetRegisterInfo::isPhysicalRegister(physReg
) &&
47 "should be physical register!");
49 for (const unsigned* as
= tri_
->getAliasSet(physReg
); *as
; ++as
)
53 void delRegUse(unsigned physReg
) {
54 assert(TargetRegisterInfo::isPhysicalRegister(physReg
) &&
55 "should be physical register!");
56 assert(regUse_
[physReg
] != 0);
58 for (const unsigned* as
= tri_
->getAliasSet(physReg
); *as
; ++as
) {
59 assert(regUse_
[*as
] != 0);
64 bool isRegAvail(unsigned physReg
) const {
65 assert(TargetRegisterInfo::isPhysicalRegister(physReg
) &&
66 "should be physical register!");
67 return regUse_
[physReg
] == 0;
71 } // End llvm namespace