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,
|
2009-05-30 03:09:53 +02:00
|
|
|
const unsigned* subregs, const unsigned subregsize,
|
2009-04-10 00:19:30 +02:00
|
|
|
const unsigned* superregs, const unsigned superregsize,
|
2009-05-30 03:09:53 +02:00
|
|
|
const unsigned* aliases, const unsigned aliasessize)
|
2009-04-09 05:50:16 +02:00
|
|
|
: SubregHash(subregs), SubregHashSize(subregsize),
|
|
|
|
SuperregHash(superregs), SuperregHashSize(superregsize),
|
2009-04-10 00:19:30 +02:00
|
|
|
AliasesHash(aliases), AliasesHashSize(aliasessize),
|
2009-04-09 05:50:16 +02:00
|
|
|
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
|
|
|
|
2007-09-26 23:36:17 +02:00
|
|
|
/// getPhysicalRegisterRegClass - Returns the Register Class of a physical
|
2009-08-11 00:56:29 +02:00
|
|
|
/// register of the given type. If type is EVT::Other, then just return any
|
2008-03-11 08:19:34 +01:00
|
|
|
/// register class the register belongs to.
|
2007-09-26 23:36:17 +02:00
|
|
|
const TargetRegisterClass *
|
2009-08-11 00:56:29 +02:00
|
|
|
TargetRegisterInfo::getPhysicalRegisterRegClass(unsigned reg, EVT 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
|
|
|
|
2008-09-21 23:01:49 +02:00
|
|
|
// Pick the most super register class of the right type that contains
|
|
|
|
// this physreg.
|
|
|
|
const TargetRegisterClass* BestRC = 0;
|
2008-04-25 19:21:40 +02:00
|
|
|
for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I){
|
2008-09-21 23:01:49 +02:00
|
|
|
const TargetRegisterClass* RC = *I;
|
2009-08-11 22:47:22 +02:00
|
|
|
if ((VT == MVT::Other || RC->hasType(VT)) && RC->contains(reg) &&
|
2008-09-21 23:01:49 +02:00
|
|
|
(!BestRC || BestRC->hasSuperClass(RC)))
|
|
|
|
BestRC = RC;
|
2008-03-11 08:54:14 +01:00
|
|
|
}
|
|
|
|
|
2008-09-21 23:01:49 +02:00
|
|
|
assert(BestRC && "Couldn't find the register class");
|
|
|
|
return BestRC;
|
2007-09-26 23:36:17 +02:00
|
|
|
}
|
|
|
|
|
2007-04-18 01:33:39 +02:00
|
|
|
/// getAllocatableSetForRC - Toggle the bits that represent allocatable
|
|
|
|
/// registers for the specific register class.
|
2009-10-10 00:09:05 +02:00
|
|
|
static void getAllocatableSetForRC(const MachineFunction &MF,
|
2007-04-18 01:33:39 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-10-10 00:09:05 +02:00
|
|
|
BitVector TargetRegisterInfo::getAllocatableSet(const MachineFunction &MF,
|
2008-02-10 19:45:23 +01:00
|
|
|
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
|
2009-09-23 22:57:02 +02:00
|
|
|
/// which is overridden for some targets.
|
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.
|
|
|
|
}
|
|
|
|
|
2009-04-30 23:23:32 +02:00
|
|
|
const TargetRegisterClass *
|
|
|
|
llvm::getCommonSubClass(const TargetRegisterClass *A,
|
|
|
|
const TargetRegisterClass *B) {
|
|
|
|
// First take care of the trivial cases
|
|
|
|
if (A == B)
|
|
|
|
return A;
|
|
|
|
if (!A || !B)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If B is a subclass of A, it will be handled in the loop below
|
|
|
|
if (B->hasSubClass(A))
|
|
|
|
return A;
|
|
|
|
|
|
|
|
const TargetRegisterClass *Best = 0;
|
|
|
|
for (TargetRegisterClass::sc_iterator I = A->subclasses_begin();
|
|
|
|
const TargetRegisterClass *X = *I; ++I) {
|
|
|
|
if (X == B)
|
|
|
|
return B; // B is a subclass of A
|
|
|
|
|
|
|
|
// X must be a common subclass of A and B
|
|
|
|
if (!B->hasSubClass(X))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// A superclass is definitely better.
|
|
|
|
if (!Best || Best->hasSuperClass(X)) {
|
|
|
|
Best = X;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A subclass is definitely worse
|
|
|
|
if (Best->hasSubClass(X))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Best and *I have no super/sub class relation - pick the larger class, or
|
|
|
|
// the smaller spill size.
|
|
|
|
int nb = std::distance(Best->begin(), Best->end());
|
|
|
|
int ni = std::distance(X->begin(), X->end());
|
|
|
|
if (ni>nb || (ni==nb && X->getSize() < Best->getSize()))
|
|
|
|
Best = X;
|
|
|
|
}
|
|
|
|
return Best;
|
|
|
|
}
|