2004-02-23 23:08:11 +00:00
|
|
|
//===-- 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"
|
2004-02-25 21:55:45 +00:00
|
|
|
#include "Support/DenseMap.h"
|
2004-02-23 23:08:11 +00:00
|
|
|
#include <climits>
|
2004-03-01 20:05:10 +00:00
|
|
|
#include <map>
|
2004-02-23 23:08:11 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2004-03-01 20:05:10 +00:00
|
|
|
class MachineInstr;
|
|
|
|
|
2004-02-23 23:08:11 +00:00
|
|
|
class VirtRegMap {
|
|
|
|
public:
|
2004-02-25 21:55:45 +00:00
|
|
|
typedef DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
|
|
|
|
typedef DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
|
2004-03-01 20:05:10 +00:00
|
|
|
typedef std::multimap<MachineInstr*, unsigned> MI2VirtMap;
|
2004-02-23 23:47:10 +00:00
|
|
|
|
2004-02-23 23:08:11 +00:00
|
|
|
private:
|
|
|
|
MachineFunction* mf_;
|
|
|
|
Virt2PhysMap v2pMap_;
|
|
|
|
Virt2StackSlotMap v2ssMap_;
|
2004-03-01 20:05:10 +00:00
|
|
|
MI2VirtMap mi2vMap_;
|
2004-02-23 23:08:11 +00:00
|
|
|
|
|
|
|
// do not implement
|
|
|
|
VirtRegMap(const VirtRegMap& rhs);
|
|
|
|
const VirtRegMap& operator=(const VirtRegMap& rhs);
|
|
|
|
|
2004-02-23 23:49:40 +00:00
|
|
|
enum {
|
|
|
|
NO_PHYS_REG = 0,
|
|
|
|
NO_STACK_SLOT = INT_MAX
|
|
|
|
};
|
|
|
|
|
2004-02-23 23:08:11 +00:00
|
|
|
public:
|
|
|
|
VirtRegMap(MachineFunction& mf)
|
|
|
|
: mf_(&mf),
|
2004-02-25 21:55:45 +00:00
|
|
|
v2pMap_(NO_PHYS_REG),
|
|
|
|
v2ssMap_(NO_STACK_SLOT) {
|
2004-05-29 19:03:29 +00:00
|
|
|
grow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void grow() {
|
|
|
|
v2pMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
|
|
|
|
v2ssMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
|
2004-02-23 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-24 06:30:36 +00:00
|
|
|
bool hasPhys(unsigned virtReg) const {
|
|
|
|
return getPhys(virtReg) != NO_PHYS_REG;
|
|
|
|
}
|
|
|
|
|
2004-02-23 23:47:10 +00:00
|
|
|
unsigned getPhys(unsigned virtReg) const {
|
2004-02-23 23:08:11 +00:00
|
|
|
assert(MRegisterInfo::isVirtualRegister(virtReg));
|
2004-02-25 21:55:45 +00:00
|
|
|
return v2pMap_[virtReg];
|
2004-02-23 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
|
|
|
|
assert(MRegisterInfo::isVirtualRegister(virtReg) &&
|
|
|
|
MRegisterInfo::isPhysicalRegister(physReg));
|
2004-02-25 21:55:45 +00:00
|
|
|
assert(v2pMap_[virtReg] == NO_PHYS_REG &&
|
2004-02-23 23:08:11 +00:00
|
|
|
"attempt to assign physical register to already mapped "
|
|
|
|
"virtual register");
|
2004-02-25 21:55:45 +00:00
|
|
|
v2pMap_[virtReg] = physReg;
|
2004-02-23 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-27 06:11:15 +00:00
|
|
|
void clearVirt(unsigned virtReg) {
|
2004-02-23 23:08:11 +00:00
|
|
|
assert(MRegisterInfo::isVirtualRegister(virtReg));
|
2004-02-25 21:55:45 +00:00
|
|
|
assert(v2pMap_[virtReg] != NO_PHYS_REG &&
|
2004-02-23 23:08:11 +00:00
|
|
|
"attempt to clear a not assigned virtual register");
|
2004-02-25 21:55:45 +00:00
|
|
|
v2pMap_[virtReg] = NO_PHYS_REG;
|
2004-02-23 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-24 06:30:36 +00:00
|
|
|
bool hasStackSlot(unsigned virtReg) const {
|
|
|
|
return getStackSlot(virtReg) != NO_STACK_SLOT;
|
|
|
|
}
|
|
|
|
|
2004-02-23 23:47:10 +00:00
|
|
|
int getStackSlot(unsigned virtReg) const {
|
2004-02-23 23:08:11 +00:00
|
|
|
assert(MRegisterInfo::isVirtualRegister(virtReg));
|
2004-02-25 21:55:45 +00:00
|
|
|
return v2ssMap_[virtReg];
|
2004-02-23 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int assignVirt2StackSlot(unsigned virtReg);
|
2004-05-29 20:38:05 +00:00
|
|
|
void assignVirt2StackSlot(unsigned virtReg, int frameIndex);
|
2004-02-23 23:08:11 +00:00
|
|
|
|
2004-03-01 20:05:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-02-23 23:08:11 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const VirtRegMap& li);
|
|
|
|
|
2004-03-01 23:18:15 +00:00
|
|
|
struct Spiller {
|
|
|
|
virtual ~Spiller();
|
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction& mf, const VirtRegMap& vrm) = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Spiller* createSpiller();
|
2004-02-24 08:58:30 +00:00
|
|
|
|
2004-02-23 23:08:11 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|