1 //===-- llvm/CodeGen/VirtRegMap.h - Virtual Register Map -*- C++ -*--------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements a virtual register map. This maps virtual
11 // registers to physical registers and virtual registers to stack
12 // slots. It is created and updated by a register allocator and then
13 // used by a machine code rewriter that adds spill code and rewrites
14 // virtual into physical register references.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CODEGEN_VIRTREGMAP_H
19 #define LLVM_CODEGEN_VIRTREGMAP_H
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/SSARegMap.h"
23 #include "Support/DenseMap.h"
33 typedef DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
34 typedef DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
35 typedef std::multimap<MachineInstr*, unsigned> MI2VirtMap;
40 Virt2StackSlotMap v2ssMap_;
44 VirtRegMap(const VirtRegMap& rhs);
45 const VirtRegMap& operator=(const VirtRegMap& rhs);
49 NO_STACK_SLOT = INT_MAX
53 VirtRegMap(MachineFunction& mf)
56 v2ssMap_(NO_STACK_SLOT) {
57 v2pMap_.grow(mf.getSSARegMap()->getLastVirtReg());
58 v2ssMap_.grow(mf.getSSARegMap()->getLastVirtReg());
61 bool hasPhys(unsigned virtReg) const {
62 return getPhys(virtReg) != NO_PHYS_REG;
65 unsigned getPhys(unsigned virtReg) const {
66 assert(MRegisterInfo::isVirtualRegister(virtReg));
67 return v2pMap_[virtReg];
70 void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
71 assert(MRegisterInfo::isVirtualRegister(virtReg) &&
72 MRegisterInfo::isPhysicalRegister(physReg));
73 assert(v2pMap_[virtReg] == NO_PHYS_REG &&
74 "attempt to assign physical register to already mapped "
76 v2pMap_[virtReg] = physReg;
79 void clearVirt(unsigned virtReg) {
80 assert(MRegisterInfo::isVirtualRegister(virtReg));
81 assert(v2pMap_[virtReg] != NO_PHYS_REG &&
82 "attempt to clear a not assigned virtual register");
83 v2pMap_[virtReg] = NO_PHYS_REG;
86 bool hasStackSlot(unsigned virtReg) const {
87 return getStackSlot(virtReg) != NO_STACK_SLOT;
90 int getStackSlot(unsigned virtReg) const {
91 assert(MRegisterInfo::isVirtualRegister(virtReg));
92 return v2ssMap_[virtReg];
95 int assignVirt2StackSlot(unsigned virtReg);
97 void virtFolded(unsigned virtReg,
101 std::pair<MI2VirtMap::const_iterator, MI2VirtMap::const_iterator>
102 getFoldedVirts(MachineInstr* MI) const {
103 return mi2vMap_.equal_range(MI);
106 friend std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
109 std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
114 virtual bool runOnMachineFunction(MachineFunction& mf, const VirtRegMap& vrm) = 0;
118 Spiller* createSpiller();
120 } // End llvm namespace