spillPhysRegAroundRegDefsUses() may have invalidated iterators stored in fixed_ Inter...
[llvm/msp430.git] / lib / CodeGen / PhysRegTracker.h
blob1f10c4bdaf9ccc48bff2e527e9e9408db837b49e
1 //===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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/TargetRegisterInfo.h"
22 namespace llvm {
24 class PhysRegTracker {
25 const TargetRegisterInfo* tri_;
26 std::vector<unsigned> regUse_;
28 public:
29 explicit PhysRegTracker(const TargetRegisterInfo& tri)
30 : tri_(&tri),
31 regUse_(tri_->getNumRegs(), 0) {
34 PhysRegTracker(const PhysRegTracker& rhs)
35 : tri_(rhs.tri_),
36 regUse_(rhs.regUse_) {
39 const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
40 tri_ = rhs.tri_;
41 regUse_ = rhs.regUse_;
42 return *this;
45 void addRegUse(unsigned physReg) {
46 assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
47 "should be physical register!");
48 ++regUse_[physReg];
49 for (const unsigned* as = tri_->getAliasSet(physReg); *as; ++as)
50 ++regUse_[*as];
53 void delRegUse(unsigned physReg) {
54 assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
55 "should be physical register!");
56 assert(regUse_[physReg] != 0);
57 --regUse_[physReg];
58 for (const unsigned* as = tri_->getAliasSet(physReg); *as; ++as) {
59 assert(regUse_[*as] != 0);
60 --regUse_[*as];
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
73 #endif