2008-02-10 19:45:23 +01:00
|
|
|
//===- TargetRegisterInfo.cpp - Target Register Information Implementation ===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-17 05:03:08 +01:00
|
|
|
//
|
2008-02-10 19:45:23 +01:00
|
|
|
// This file implements the TargetRegisterInfo interface.
|
2002-12-17 05:03:08 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-08-03 19:27:09 +02:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-02-10 19:45:23 +01:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2006-08-03 19:27:09 +02:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2006-03-28 15:48:33 +02:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2007-02-15 06:59:24 +01:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2006-03-28 15:48:33 +02:00
|
|
|
|
2006-02-01 19:10:56 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2008-02-10 19:45:23 +01:00
|
|
|
TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
|
2002-12-28 21:34:18 +01:00
|
|
|
regclass_iterator RCB, regclass_iterator RCE,
|
2008-07-01 19:34:38 +02:00
|
|
|
int CFSO, int CFDO,
|
|
|
|
const unsigned* subregs, const unsigned subregsize)
|
2008-07-01 23:00:31 +02:00
|
|
|
: SubregHash(subregs), SubregHashSize(subregsize), Desc(D), NumRegs(NR),
|
|
|
|
RegClassBegin(RCB), RegClassEnd(RCE) {
|
2002-12-17 05:03:08 +01:00
|
|
|
assert(NumRegs < FirstVirtualRegister &&
|
|
|
|
"Target has too many physical registers!");
|
|
|
|
|
2002-12-28 21:34:18 +01:00
|
|
|
CallFrameSetupOpcode = CFSO;
|
|
|
|
CallFrameDestroyOpcode = CFDO;
|
2002-12-17 05:03:08 +01:00
|
|
|
}
|
|
|
|
|
2008-02-10 19:45:23 +01:00
|
|
|
TargetRegisterInfo::~TargetRegisterInfo() {}
|
2004-10-27 08:00:53 +02:00
|
|
|
|
2008-03-11 08:54:14 +01:00
|
|
|
namespace {
|
|
|
|
// Sort according to super- / sub- class relations.
|
|
|
|
// i.e. super- register class < sub- register class.
|
|
|
|
struct RCCompare {
|
|
|
|
bool operator()(const TargetRegisterClass* const &LHS,
|
|
|
|
const TargetRegisterClass* const &RHS) {
|
|
|
|
return RHS->hasSuperClass(LHS);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2007-09-26 23:36:17 +02:00
|
|
|
/// getPhysicalRegisterRegClass - Returns the Register Class of a physical
|
2008-03-11 08:19:34 +01:00
|
|
|
/// register of the given type. If type is MVT::Other, then just return any
|
|
|
|
/// register class the register belongs to.
|
2007-09-26 23:36:17 +02:00
|
|
|
const TargetRegisterClass *
|
2008-06-06 14:08:01 +02:00
|
|
|
TargetRegisterInfo::getPhysicalRegisterRegClass(unsigned reg, MVT VT) const {
|
2007-09-26 23:36:17 +02:00
|
|
|
assert(isPhysicalRegister(reg) && "reg must be a physical register");
|
2008-03-11 08:54:14 +01:00
|
|
|
|
2007-09-26 23:36:17 +02:00
|
|
|
// Pick the register class of the right type that contains this physreg.
|
2008-03-11 08:54:14 +01:00
|
|
|
SmallVector<const TargetRegisterClass*, 4> RCs;
|
2008-04-25 19:21:40 +02:00
|
|
|
for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I){
|
2008-03-11 08:54:14 +01:00
|
|
|
if ((VT == MVT::Other || (*I)->hasType(VT)) && (*I)->contains(reg))
|
|
|
|
RCs.push_back(*I);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RCs.size() == 1)
|
|
|
|
return RCs[0];
|
|
|
|
|
|
|
|
if (RCs.size()) {
|
|
|
|
// Multiple compatible register classes. Get the super- class.
|
|
|
|
std::stable_sort(RCs.begin(), RCs.end(), RCCompare());
|
|
|
|
return RCs[0];
|
|
|
|
}
|
|
|
|
|
2007-09-26 23:36:17 +02:00
|
|
|
assert(false && "Couldn't find the register class");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-18 01:33:39 +02:00
|
|
|
/// getAllocatableSetForRC - Toggle the bits that represent allocatable
|
|
|
|
/// registers for the specific register class.
|
|
|
|
static void getAllocatableSetForRC(MachineFunction &MF,
|
|
|
|
const TargetRegisterClass *RC, BitVector &R){
|
|
|
|
for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
|
|
|
|
E = RC->allocation_order_end(MF); I != E; ++I)
|
|
|
|
R.set(*I);
|
|
|
|
}
|
|
|
|
|
2008-02-10 19:45:23 +01:00
|
|
|
BitVector TargetRegisterInfo::getAllocatableSet(MachineFunction &MF,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2007-02-15 06:59:24 +01:00
|
|
|
BitVector Allocatable(NumRegs);
|
2007-04-18 01:33:39 +02:00
|
|
|
if (RC) {
|
|
|
|
getAllocatableSetForRC(MF, RC, Allocatable);
|
|
|
|
return Allocatable;
|
2004-08-27 00:21:04 +02:00
|
|
|
}
|
2007-04-18 01:33:39 +02:00
|
|
|
|
2008-02-10 19:45:23 +01:00
|
|
|
for (TargetRegisterInfo::regclass_iterator I = regclass_begin(),
|
2007-04-18 01:33:39 +02:00
|
|
|
E = regclass_end(); I != E; ++I)
|
|
|
|
getAllocatableSetForRC(MF, *I, Allocatable);
|
2004-08-27 00:21:04 +02:00
|
|
|
return Allocatable;
|
2005-04-22 00:55:34 +02:00
|
|
|
}
|
2006-03-28 15:48:33 +02:00
|
|
|
|
2008-01-31 04:37:28 +01:00
|
|
|
/// getFrameIndexOffset - Returns the displacement from the frame register to
|
|
|
|
/// the stack frame of the specified index. This is the default implementation
|
|
|
|
/// which is likely incorrect for the target.
|
2008-02-10 19:45:23 +01:00
|
|
|
int TargetRegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
|
2006-08-03 19:27:09 +02:00
|
|
|
const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
|
2006-03-28 15:48:33 +02:00
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2008-01-31 04:37:28 +01:00
|
|
|
return MFI->getObjectOffset(FI) + MFI->getStackSize() -
|
|
|
|
TFI.getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
|
2006-03-28 15:48:33 +02:00
|
|
|
}
|
2006-04-07 18:34:46 +02:00
|
|
|
|
|
|
|
/// getInitialFrameState - Returns a list of machine moves that are assumed
|
|
|
|
/// on entry to a function.
|
|
|
|
void
|
2008-02-10 19:45:23 +01:00
|
|
|
TargetRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
|
2006-04-07 18:34:46 +02:00
|
|
|
// Default is to do nothing.
|
|
|
|
}
|
|
|
|
|