aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/VirtRegMap.h
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-02-23 23:08:11 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-02-23 23:08:11 +0000
commit34d9bc9f168d17c52eb57e024580bd9499695f91 (patch)
tree8d6247020b4c01250c058f1b83feb41537799216 /lib/CodeGen/VirtRegMap.h
parentc38aa6dd7952cbc0d890387a8e728412711d9044 (diff)
downloadexternal_llvm-34d9bc9f168d17c52eb57e024580bd9499695f91.zip
external_llvm-34d9bc9f168d17c52eb57e024580bd9499695f91.tar.gz
external_llvm-34d9bc9f168d17c52eb57e024580bd9499695f91.tar.bz2
Refactor VirtRegMap out of RegAllocLinearScan as the first part of bug
251 (providing a generic machine code rewriter/spiller). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11780 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/VirtRegMap.h')
-rw-r--r--lib/CodeGen/VirtRegMap.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/lib/CodeGen/VirtRegMap.h b/lib/CodeGen/VirtRegMap.h
new file mode 100644
index 0000000..1c593d3
--- /dev/null
+++ b/lib/CodeGen/VirtRegMap.h
@@ -0,0 +1,95 @@
+//===-- llvm/CodeGen/VirtRegMap.h - Virtual Register Map -*- C++ -*--------===//
+//
+// 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 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 <climits>
+
+namespace llvm {
+
+ class VirtRegMap {
+ public:
+ typedef std::vector<unsigned> Virt2PhysMap;
+ typedef std::vector<int> Virt2StackSlotMap;
+
+ enum {
+ NO_PHYS_REG = 0,
+ NO_STACK_SLOT = INT_MAX
+ };
+
+ private:
+ MachineFunction* mf_;
+ Virt2PhysMap v2pMap_;
+ Virt2StackSlotMap v2ssMap_;
+
+ // do not implement
+ VirtRegMap(const VirtRegMap& rhs);
+ const VirtRegMap& operator=(const VirtRegMap& rhs);
+
+ static unsigned toIndex(unsigned virtReg) {
+ return virtReg - MRegisterInfo::FirstVirtualRegister;
+ }
+ static unsigned fromIndex(unsigned index) {
+ return index + MRegisterInfo::FirstVirtualRegister;
+ }
+
+ public:
+ VirtRegMap(MachineFunction& mf)
+ : mf_(&mf),
+ v2pMap_(mf.getSSARegMap()->getNumVirtualRegs(), NO_PHYS_REG),
+ v2ssMap_(mf.getSSARegMap()->getNumVirtualRegs(), NO_STACK_SLOT) {
+ }
+
+ unsigned getPhys4Virt(unsigned virtReg) const {
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ return v2pMap_[toIndex(virtReg)];
+ }
+
+ void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
+ assert(MRegisterInfo::isVirtualRegister(virtReg) &&
+ MRegisterInfo::isPhysicalRegister(physReg));
+ assert(v2pMap_[toIndex(virtReg)] == NO_PHYS_REG &&
+ "attempt to assign physical register to already mapped "
+ "virtual register");
+ v2pMap_[toIndex(virtReg)] = physReg;
+ }
+
+ void clearVirtReg(unsigned virtReg) {
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ assert(v2pMap_[toIndex(virtReg)] != NO_PHYS_REG &&
+ "attempt to clear a not assigned virtual register");
+ v2pMap_[toIndex(virtReg)] = NO_PHYS_REG;
+ }
+
+ int getStackSlot4Virt(unsigned virtReg) const {
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ return v2ssMap_[toIndex(virtReg)];
+ }
+
+ int assignVirt2StackSlot(unsigned virtReg);
+
+ friend std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
+ };
+
+ std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
+
+} // End llvm namespace
+
+#endif