2008-02-10 18:45:23 +00:00
|
|
|
//===- TargetRegisterInfo.cpp - Target Register Information Implementation ===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-17 04:03:08 +00:00
|
|
|
//
|
2008-02-10 18:45:23 +00:00
|
|
|
// This file implements the TargetRegisterInfo interface.
|
2002-12-17 04:03:08 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-08-03 17:27:09 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-02-10 18:45:23 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2006-08-03 17:27:09 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2006-03-28 13:48:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2007-02-15 05:59:24 +00:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2006-03-28 13:48:33 +00:00
|
|
|
|
2006-02-01 18:10:56 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2008-02-10 18:45:23 +00:00
|
|
|
TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
|
2002-12-28 20:34:18 +00:00
|
|
|
regclass_iterator RCB, regclass_iterator RCE,
|
2008-07-01 17:34:38 +00:00
|
|
|
int CFSO, int CFDO,
|
2009-04-09 03:50:16 +00:00
|
|
|
const unsigned* subregs, const unsigned subregsize,
|
|
|
|
const unsigned* superregs, const unsigned superregsize)
|
|
|
|
: SubregHash(subregs), SubregHashSize(subregsize),
|
|
|
|
SuperregHash(superregs), SuperregHashSize(superregsize),
|
|
|
|
Desc(D), NumRegs(NR), RegClassBegin(RCB), RegClassEnd(RCE) {
|
2002-12-17 04:03:08 +00:00
|
|
|
assert(NumRegs < FirstVirtualRegister &&
|
|
|
|
"Target has too many physical registers!");
|
|
|
|
|
2002-12-28 20:34:18 +00:00
|
|
|
CallFrameSetupOpcode = CFSO;
|
|
|
|
CallFrameDestroyOpcode = CFDO;
|
2002-12-17 04:03:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-10 18:45:23 +00:00
|
|
|
TargetRegisterInfo::~TargetRegisterInfo() {}
|
2004-10-27 06:00:53 +00:00
|
|
|
|
2007-09-26 21:36:17 +00:00
|
|
|
/// getPhysicalRegisterRegClass - Returns the Register Class of a physical
|
2008-03-11 07:19:34 +00:00
|
|
|
/// register of the given type. If type is MVT::Other, then just return any
|
|
|
|
/// register class the register belongs to.
|
2007-09-26 21:36:17 +00:00
|
|
|
const TargetRegisterClass *
|
2008-06-06 12:08:01 +00:00
|
|
|
TargetRegisterInfo::getPhysicalRegisterRegClass(unsigned reg, MVT VT) const {
|
2007-09-26 21:36:17 +00:00
|
|
|
assert(isPhysicalRegister(reg) && "reg must be a physical register");
|
2008-03-11 07:54:14 +00:00
|
|
|
|
2008-09-21 21:01:49 +00:00
|
|
|
// Pick the most super register class of the right type that contains
|
|
|
|
// this physreg.
|
|
|
|
const TargetRegisterClass* BestRC = 0;
|
2008-04-25 17:21:40 +00:00
|
|
|
for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I){
|
2008-09-21 21:01:49 +00:00
|
|
|
const TargetRegisterClass* RC = *I;
|
|
|
|
if ((VT == MVT::Other || RC->hasType(VT)) && RC->contains(reg) &&
|
|
|
|
(!BestRC || BestRC->hasSuperClass(RC)))
|
|
|
|
BestRC = RC;
|
2008-03-11 07:54:14 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 21:01:49 +00:00
|
|
|
assert(BestRC && "Couldn't find the register class");
|
|
|
|
return BestRC;
|
2007-09-26 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 23:33:39 +00: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 18:45:23 +00:00
|
|
|
BitVector TargetRegisterInfo::getAllocatableSet(MachineFunction &MF,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2007-02-15 05:59:24 +00:00
|
|
|
BitVector Allocatable(NumRegs);
|
2007-04-17 23:33:39 +00:00
|
|
|
if (RC) {
|
|
|
|
getAllocatableSetForRC(MF, RC, Allocatable);
|
|
|
|
return Allocatable;
|
2004-08-26 22:21:04 +00:00
|
|
|
}
|
2007-04-17 23:33:39 +00:00
|
|
|
|
2008-02-10 18:45:23 +00:00
|
|
|
for (TargetRegisterInfo::regclass_iterator I = regclass_begin(),
|
2007-04-17 23:33:39 +00:00
|
|
|
E = regclass_end(); I != E; ++I)
|
|
|
|
getAllocatableSetForRC(MF, *I, Allocatable);
|
2004-08-26 22:21:04 +00:00
|
|
|
return Allocatable;
|
2005-04-21 22:55:34 +00:00
|
|
|
}
|
2006-03-28 13:48:33 +00:00
|
|
|
|
2008-01-31 03:37:28 +00: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 18:45:23 +00:00
|
|
|
int TargetRegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
|
2006-08-03 17:27:09 +00:00
|
|
|
const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
|
2006-03-28 13:48:33 +00:00
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2008-01-31 03:37:28 +00:00
|
|
|
return MFI->getObjectOffset(FI) + MFI->getStackSize() -
|
|
|
|
TFI.getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
|
2006-03-28 13:48:33 +00:00
|
|
|
}
|
2006-04-07 16:34:46 +00:00
|
|
|
|
|
|
|
/// getInitialFrameState - Returns a list of machine moves that are assumed
|
|
|
|
/// on entry to a function.
|
|
|
|
void
|
2008-02-10 18:45:23 +00:00
|
|
|
TargetRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
|
2006-04-07 16:34:46 +00:00
|
|
|
// Default is to do nothing.
|
|
|
|
}
|
|
|
|
|