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