blob: 2717e337687a81bbd9eb4ede75b60bbddcc44219 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- 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.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_PHYSREGTRACKER_H
18#define LLVM_CODEGEN_PHYSREGTRACKER_H
19
20#include "llvm/Target/MRegisterInfo.h"
21
22namespace llvm {
23
24 class PhysRegTracker {
25 const MRegisterInfo* mri_;
26 std::vector<unsigned> regUse_;
27
28 public:
Dan Gohman9ba5d4d2007-08-27 14:50:10 +000029 explicit PhysRegTracker(const MRegisterInfo& mri)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030 : mri_(&mri),
31 regUse_(mri_->getNumRegs(), 0) {
32 }
33
34 PhysRegTracker(const PhysRegTracker& rhs)
35 : mri_(rhs.mri_),
36 regUse_(rhs.regUse_) {
37 }
38
39 const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
40 mri_ = rhs.mri_;
41 regUse_ = rhs.regUse_;
42 return *this;
43 }
44
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];
51 }
52
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];
61 }
62 }
63
64 bool isRegAvail(unsigned physReg) const {
65 assert(MRegisterInfo::isPhysicalRegister(physReg) &&
66 "should be physical register!");
67 return regUse_[physReg] == 0;
68 }
69 };
70
71} // End llvm namespace
72
73#endif