blob: 1f10c4bdaf9ccc48bff2e527e9e9408db837b49e [file] [log] [blame]
Alkis Evlogimenos534f5452004-02-23 01:25:05 +00001//===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements a physical register tracker. The tracker
Alkis Evlogimenos534f5452004-02-23 01:25:05 +000011// 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.
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000014//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_PHYSREGTRACKER_H
18#define LLVM_CODEGEN_PHYSREGTRACKER_H
19
Dan Gohman6f0d0242008-02-10 18:45:23 +000020#include "llvm/Target/TargetRegisterInfo.h"
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000021
22namespace llvm {
23
24 class PhysRegTracker {
Dan Gohman6f0d0242008-02-10 18:45:23 +000025 const TargetRegisterInfo* tri_;
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000026 std::vector<unsigned> regUse_;
27
28 public:
Dan Gohman6f0d0242008-02-10 18:45:23 +000029 explicit PhysRegTracker(const TargetRegisterInfo& tri)
30 : tri_(&tri),
31 regUse_(tri_->getNumRegs(), 0) {
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000032 }
33
34 PhysRegTracker(const PhysRegTracker& rhs)
Dan Gohman6f0d0242008-02-10 18:45:23 +000035 : tri_(rhs.tri_),
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000036 regUse_(rhs.regUse_) {
37 }
38
39 const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
Dan Gohman6f0d0242008-02-10 18:45:23 +000040 tri_ = rhs.tri_;
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000041 regUse_ = rhs.regUse_;
42 return *this;
43 }
44
45 void addRegUse(unsigned physReg) {
Dan Gohman6f0d0242008-02-10 18:45:23 +000046 assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000047 "should be physical register!");
48 ++regUse_[physReg];
Dan Gohman6f0d0242008-02-10 18:45:23 +000049 for (const unsigned* as = tri_->getAliasSet(physReg); *as; ++as)
Alkis Evlogimenos25d9d582004-02-23 01:57:39 +000050 ++regUse_[*as];
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000051 }
52
53 void delRegUse(unsigned physReg) {
Dan Gohman6f0d0242008-02-10 18:45:23 +000054 assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000055 "should be physical register!");
56 assert(regUse_[physReg] != 0);
57 --regUse_[physReg];
Dan Gohman6f0d0242008-02-10 18:45:23 +000058 for (const unsigned* as = tri_->getAliasSet(physReg); *as; ++as) {
Alkis Evlogimenos25d9d582004-02-23 01:57:39 +000059 assert(regUse_[*as] != 0);
60 --regUse_[*as];
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000061 }
62 }
63
Alkis Evlogimenos534f5452004-02-23 01:25:05 +000064 bool isRegAvail(unsigned physReg) const {
Dan Gohman6f0d0242008-02-10 18:45:23 +000065 assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
Alkis Evlogimenos888b1a62004-02-23 00:53:31 +000066 "should be physical register!");
67 return regUse_[physReg] == 0;
68 }
69 };
70
71} // End llvm namespace
72
73#endif