2004-02-23 01:25:05 +00:00
|
|
|
//===-- llvm/CodeGen/PhysRegTracker.h - Physical Register Tracker -*- C++ -*-=//
|
2004-02-23 00:53:31 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-02-23 00:53:31 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a physical register tracker. The tracker
|
2004-02-23 01:25:05 +00: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 00:53:31 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_PHYSREGTRACKER_H
|
|
|
|
#define LLVM_CODEGEN_PHYSREGTRACKER_H
|
|
|
|
|
2008-02-10 18:45:23 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2004-02-23 00:53:31 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class PhysRegTracker {
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo* tri_;
|
2004-02-23 00:53:31 +00:00
|
|
|
std::vector<unsigned> regUse_;
|
|
|
|
|
|
|
|
public:
|
2008-02-10 18:45:23 +00:00
|
|
|
explicit PhysRegTracker(const TargetRegisterInfo& tri)
|
|
|
|
: tri_(&tri),
|
|
|
|
regUse_(tri_->getNumRegs(), 0) {
|
2004-02-23 00:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PhysRegTracker(const PhysRegTracker& rhs)
|
2008-02-10 18:45:23 +00:00
|
|
|
: tri_(rhs.tri_),
|
2004-02-23 00:53:31 +00:00
|
|
|
regUse_(rhs.regUse_) {
|
|
|
|
}
|
|
|
|
|
|
|
|
const PhysRegTracker& operator=(const PhysRegTracker& rhs) {
|
2008-02-10 18:45:23 +00:00
|
|
|
tri_ = rhs.tri_;
|
2004-02-23 00:53:31 +00:00
|
|
|
regUse_ = rhs.regUse_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addRegUse(unsigned physReg) {
|
2008-02-10 18:45:23 +00:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
|
2004-02-23 00:53:31 +00:00
|
|
|
"should be physical register!");
|
|
|
|
++regUse_[physReg];
|
2008-02-10 18:45:23 +00:00
|
|
|
for (const unsigned* as = tri_->getAliasSet(physReg); *as; ++as)
|
2004-02-23 01:57:39 +00:00
|
|
|
++regUse_[*as];
|
2004-02-23 00:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void delRegUse(unsigned physReg) {
|
2008-02-10 18:45:23 +00:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
|
2004-02-23 00:53:31 +00:00
|
|
|
"should be physical register!");
|
|
|
|
assert(regUse_[physReg] != 0);
|
|
|
|
--regUse_[physReg];
|
2008-02-10 18:45:23 +00:00
|
|
|
for (const unsigned* as = tri_->getAliasSet(physReg); *as; ++as) {
|
2004-02-23 01:57:39 +00:00
|
|
|
assert(regUse_[*as] != 0);
|
|
|
|
--regUse_[*as];
|
2004-02-23 00:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-23 01:25:05 +00:00
|
|
|
bool isRegAvail(unsigned physReg) const {
|
2008-02-10 18:45:23 +00:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(physReg) &&
|
2004-02-23 00:53:31 +00:00
|
|
|
"should be physical register!");
|
|
|
|
return regUse_[physReg] == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|