2004-02-23 09:25:05 +08:00
|
|
|
//===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
|
2004-02-23 08:53:31 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a physical register tracker. The tracker
|
2004-02-23 09:25:05 +08:00
|
|
|
// tracks physical register usage through addRegUse and
|
|
|
|
// delRegUse. isRegAvail checks if a physical register is available or
|
|
|
|
// not taking into consideration register aliases.
|
2004-02-23 08:53:31 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_PHYSREGTRACKER_H
|
|
|
|
#define LLVM_CODEGEN_PHYSREGTRACKER_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class PhysRegTracker {
|
|
|
|
const MRegisterInfo* mri_;
|
|
|
|
std::vector<unsigned> regUse_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PhysRegTracker(MachineFunction* mf)
|
|
|
|
: mri_(mf ? mf->getTarget().getRegisterInfo() : NULL) {
|
|
|
|
if (mri_) {
|
|
|
|
regUse_.assign(mri_->getNumRegs(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysRegTracker(const PhysRegTracker& rhs)
|
|
|
|
: mri_(rhs.mri_),
|
|
|
|
regUse_(rhs.regUse_) {
|
|
|
|
}
|
|
|
|
|
|
|
|
const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
|
|
|
|
mri_ = rhs.mri_;
|
|
|
|
regUse_ = rhs.regUse_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addRegUse(unsigned physReg) {
|
|
|
|
assert(MRegisterInfo::isPhysicalRegister(physReg) &&
|
|
|
|
"should be physical register!");
|
|
|
|
++regUse_[physReg];
|
2004-02-23 09:57:39 +08:00
|
|
|
for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as)
|
|
|
|
++regUse_[*as];
|
2004-02-23 08:53:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void delRegUse(unsigned physReg) {
|
|
|
|
assert(MRegisterInfo::isPhysicalRegister(physReg) &&
|
|
|
|
"should be physical register!");
|
|
|
|
assert(regUse_[physReg] != 0);
|
|
|
|
--regUse_[physReg];
|
|
|
|
for (const unsigned* as = mri_->getAliasSet(physReg); *as; ++as) {
|
2004-02-23 09:57:39 +08:00
|
|
|
assert(regUse_[*as] != 0);
|
|
|
|
--regUse_[*as];
|
2004-02-23 08:53:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-23 09:25:05 +08:00
|
|
|
bool isRegAvail(unsigned physReg) const {
|
2004-02-23 08:53:31 +08:00
|
|
|
assert(MRegisterInfo::isPhysicalRegister(physReg) &&
|
|
|
|
"should be physical register!");
|
|
|
|
return regUse_[physReg] == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|