summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/VirtRegMap.cpp
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
commitc794a9060f0aea1caf7b292fa703a06a050ce73d (patch)
treee6a5fc04f65cad44cd075a73c88edbb141e42728 /llvm/lib/CodeGen/VirtRegMap.cpp
parentd140e3d4ff6b96194edf955818fd87d9e3aa3cad (diff)
downloadbcm5719-llvm-c794a9060f0aea1caf7b292fa703a06a050ce73d.tar.gz
bcm5719-llvm-c794a9060f0aea1caf7b292fa703a06a050ce73d.zip
Refactor VirtRegMap out of RegAllocLinearScan as the first part of bug
251 (providing a generic machine code rewriter/spiller). llvm-svn: 11780
Diffstat (limited to 'llvm/lib/CodeGen/VirtRegMap.cpp')
-rw-r--r--llvm/lib/CodeGen/VirtRegMap.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/VirtRegMap.cpp b/llvm/lib/CodeGen/VirtRegMap.cpp
new file mode 100644
index 00000000000..bfbe0ef9c5a
--- /dev/null
+++ b/llvm/lib/CodeGen/VirtRegMap.cpp
@@ -0,0 +1,55 @@
+//===-- llvm/CodeGen/VirtRegMap.cpp - Virtual Register Map ----------------===//
+//
+// 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 the virtual register map.
+//
+//===----------------------------------------------------------------------===//
+
+#include "VirtRegMap.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/Target/TargetMachine.h"
+#include "Support/Statistic.h"
+#include <iostream>
+
+using namespace llvm;
+
+namespace {
+ Statistic<> numSpills("ra-linearscan", "Number of register spills");
+}
+
+int VirtRegMap::assignVirt2StackSlot(unsigned virtReg)
+{
+ assert(MRegisterInfo::isVirtualRegister(virtReg));
+ assert(v2ssMap_[toIndex(virtReg)] == NO_STACK_SLOT &&
+ "attempt to assign stack slot to already spilled register");
+ const TargetRegisterClass* rc =
+ mf_->getSSARegMap()->getRegClass(virtReg);
+ int frameIndex = mf_->getFrameInfo()->CreateStackObject(rc);
+ v2ssMap_[toIndex(virtReg)] = frameIndex;
+ ++numSpills;
+ return frameIndex;
+}
+
+std::ostream& llvm::operator<<(std::ostream& os, const VirtRegMap& vrm)
+{
+ const MRegisterInfo* mri = vrm.mf_->getTarget().getRegisterInfo();
+
+ std::cerr << "********** REGISTER MAP **********\n";
+ for (unsigned i = 0, e = vrm.v2pMap_.size(); i != e; ++i) {
+ if (vrm.v2pMap_[i] != VirtRegMap::NO_PHYS_REG)
+ std::cerr << "[reg" << VirtRegMap::fromIndex(i) << " -> "
+ << mri->getName(vrm.v2pMap_[i]) << "]\n";
+ }
+ for (unsigned i = 0, e = vrm.v2ssMap_.size(); i != e; ++i) {
+ if (vrm.v2ssMap_[i] != VirtRegMap::NO_STACK_SLOT)
+ std::cerr << "[reg" << VirtRegMap::fromIndex(i) << " -> fi#"
+ << vrm.v2ssMap_[i] << "]\n";
+ }
+ return std::cerr << '\n';
+}
OpenPOWER on IntegriCloud