aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/VirtRegMap.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-09-30 01:54:45 +0000
committerChris Lattner <sabre@nondot.org>2004-09-30 01:54:45 +0000
commit8c4d88d3697835371ecf6823f4142af13603ad2d (patch)
tree2b8a1f4f46192ee5aa6bb0209162fcbc1c0f001e /lib/CodeGen/VirtRegMap.h
parent23367a779cc59e87d38628d8195f6214f4aa8af8 (diff)
downloadexternal_llvm-8c4d88d3697835371ecf6823f4142af13603ad2d.zip
external_llvm-8c4d88d3697835371ecf6823f4142af13603ad2d.tar.gz
external_llvm-8c4d88d3697835371ecf6823f4142af13603ad2d.tar.bz2
Reindent code, improve comments, move huge nested methods out of classes,
prune #includes, add print/dump methods, etc. No functionality changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16604 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/VirtRegMap.h')
-rw-r--r--lib/CodeGen/VirtRegMap.h210
1 files changed, 103 insertions, 107 deletions
diff --git a/lib/CodeGen/VirtRegMap.h b/lib/CodeGen/VirtRegMap.h
index fb694d5..664ca62 100644
--- a/lib/CodeGen/VirtRegMap.h
+++ b/lib/CodeGen/VirtRegMap.h
@@ -7,125 +7,121 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements a virtual register map. This maps virtual
-// registers to physical registers and virtual registers to stack
-// slots. It is created and updated by a register allocator and then
-// used by a machine code rewriter that adds spill code and rewrites
-// virtual into physical register references.
+// This file implements a virtual register map. This maps virtual registers to
+// physical registers and virtual registers to stack slots. It is created and
+// updated by a register allocator and then used by a machine code rewriter that
+// adds spill code and rewrites virtual into physical register references.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_VIRTREGMAP_H
#define LLVM_CODEGEN_VIRTREGMAP_H
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/SSARegMap.h"
+#include "llvm/Target/MRegisterInfo.h"
#include "llvm/ADT/DenseMap.h"
-#include <climits>
#include <map>
namespace llvm {
-
- class MachineInstr;
-
- class VirtRegMap {
- public:
- typedef DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
- typedef DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
- typedef std::multimap<MachineInstr*, unsigned> MI2VirtMap;
-
- private:
- MachineFunction* mf_;
- Virt2PhysMap v2pMap_;
- Virt2StackSlotMap v2ssMap_;
- MI2VirtMap mi2vMap_;
-
- // do not implement
- VirtRegMap(const VirtRegMap& rhs);
- const VirtRegMap& operator=(const VirtRegMap& rhs);
-
- enum {
- NO_PHYS_REG = 0,
- NO_STACK_SLOT = INT_MAX
- };
-
- public:
- VirtRegMap(MachineFunction& mf)
- : mf_(&mf),
- v2pMap_(NO_PHYS_REG),
- v2ssMap_(NO_STACK_SLOT) {
- grow();
- }
-
- void grow() {
- v2pMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
- v2ssMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
- }
-
- bool hasPhys(unsigned virtReg) const {
- return getPhys(virtReg) != NO_PHYS_REG;
- }
-
- unsigned getPhys(unsigned virtReg) const {
- assert(MRegisterInfo::isVirtualRegister(virtReg));
- return v2pMap_[virtReg];
- }
-
- void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
- assert(MRegisterInfo::isVirtualRegister(virtReg) &&
- MRegisterInfo::isPhysicalRegister(physReg));
- assert(v2pMap_[virtReg] == NO_PHYS_REG &&
- "attempt to assign physical register to already mapped "
- "virtual register");
- v2pMap_[virtReg] = physReg;
- }
-
- void clearVirt(unsigned virtReg) {
- assert(MRegisterInfo::isVirtualRegister(virtReg));
- assert(v2pMap_[virtReg] != NO_PHYS_REG &&
- "attempt to clear a not assigned virtual register");
- v2pMap_[virtReg] = NO_PHYS_REG;
- }
-
- void clearAllVirt() {
- v2pMap_.clear();
- grow();
- }
-
- bool hasStackSlot(unsigned virtReg) const {
- return getStackSlot(virtReg) != NO_STACK_SLOT;
- }
-
- int getStackSlot(unsigned virtReg) const {
- assert(MRegisterInfo::isVirtualRegister(virtReg));
- return v2ssMap_[virtReg];
- }
-
- int assignVirt2StackSlot(unsigned virtReg);
- void assignVirt2StackSlot(unsigned virtReg, int frameIndex);
-
- void virtFolded(unsigned virtReg,
- MachineInstr* oldMI,
- MachineInstr* newMI);
-
- std::pair<MI2VirtMap::const_iterator, MI2VirtMap::const_iterator>
- getFoldedVirts(MachineInstr* MI) const {
- return mi2vMap_.equal_range(MI);
- }
-
- friend std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
- };
-
- std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
-
- struct Spiller {
- virtual ~Spiller();
-
- virtual bool runOnMachineFunction(MachineFunction& mf, const VirtRegMap& vrm) = 0;
-
+ class MachineInstr;
+
+ class VirtRegMap {
+ public:
+ typedef DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
+ typedef DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
+ typedef std::multimap<MachineInstr*, unsigned> MI2VirtMap;
+
+ private:
+ MachineFunction* mf_;
+ Virt2PhysMap v2pMap_;
+ Virt2StackSlotMap v2ssMap_;
+ MI2VirtMap mi2vMap_;
+
+ VirtRegMap(const VirtRegMap&); // DO NOT IMPLEMENT
+ void operator=(const VirtRegMap&); // DO NOT IMPLEMENT
+
+ enum {
+ NO_PHYS_REG = 0,
+ NO_STACK_SLOT = ~0 >> 1
};
- Spiller* createSpiller();
+ public:
+ VirtRegMap(MachineFunction& mf)
+ : mf_(&mf), v2pMap_(NO_PHYS_REG), v2ssMap_(NO_STACK_SLOT) {
+ grow();
+ }
+
+ void grow();
+
+ bool hasPhys(unsigned virtReg) const {
+ return getPhys(virtReg) != NO_PHYS_REG;
+ }
+
+ unsigned getPhys(unsigned virtReg) const {
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ return v2pMap_[virtReg];
+ }
+
+ void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
+ assert(MRegisterInfo::isVirtualRegister(virtReg) &&
+ MRegisterInfo::isPhysicalRegister(physReg));
+ assert(v2pMap_[virtReg] == NO_PHYS_REG &&
+ "attempt to assign physical register to already mapped "
+ "virtual register");
+ v2pMap_[virtReg] = physReg;
+ }
+
+ void clearVirt(unsigned virtReg) {
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ assert(v2pMap_[virtReg] != NO_PHYS_REG &&
+ "attempt to clear a not assigned virtual register");
+ v2pMap_[virtReg] = NO_PHYS_REG;
+ }
+
+ void clearAllVirt() {
+ v2pMap_.clear();
+ grow();
+ }
+
+ bool hasStackSlot(unsigned virtReg) const {
+ return getStackSlot(virtReg) != NO_STACK_SLOT;
+ }
+
+ int getStackSlot(unsigned virtReg) const {
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ return v2ssMap_[virtReg];
+ }
+
+ int assignVirt2StackSlot(unsigned virtReg);
+ void assignVirt2StackSlot(unsigned virtReg, int frameIndex);
+
+ void virtFolded(unsigned virtReg, MachineInstr* oldMI,
+ MachineInstr* newMI);
+
+ std::pair<MI2VirtMap::const_iterator, MI2VirtMap::const_iterator>
+ getFoldedVirts(MachineInstr* MI) const {
+ return mi2vMap_.equal_range(MI);
+ }
+
+ void print(std::ostream &OS) const;
+ void dump() const;
+ };
+
+ inline std::ostream &operator<<(std::ostream &OS, const VirtRegMap &VRM) {
+ VRM.print(OS);
+ return OS;
+ }
+
+ /// Spiller interface: Implementations of this interface assign spilled
+ /// virtual registers to stack slots, rewriting the code.
+ struct Spiller {
+ virtual ~Spiller();
+ virtual bool runOnMachineFunction(MachineFunction &MF,
+ const VirtRegMap &VRM) = 0;
+ };
+
+ /// createSpiller - Create an return a spiller object, as specified on the
+ /// command line.
+ Spiller* createSpiller();
} // End llvm namespace