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-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"
|
2010-12-14 18:53:39 +00:00
|
|
|
#include "llvm/Support/raw_ostream.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
|
|
|
|
2011-06-24 01:44:41 +00:00
|
|
|
TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
|
2002-12-28 20:34:18 +00:00
|
|
|
regclass_iterator RCB, regclass_iterator RCE,
|
2011-06-28 21:14:33 +00:00
|
|
|
const char *const *subregindexnames)
|
2011-06-24 01:44:41 +00:00
|
|
|
: InfoDesc(ID), SubRegIndexNames(subregindexnames),
|
2010-05-25 19:49:38 +00:00
|
|
|
RegClassBegin(RCB), RegClassEnd(RCE) {
|
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
|
|
|
|
2011-01-09 03:05:53 +00:00
|
|
|
void PrintReg::print(raw_ostream &OS) const {
|
|
|
|
if (!Reg)
|
|
|
|
OS << "%noreg";
|
2011-01-09 21:17:37 +00:00
|
|
|
else if (TargetRegisterInfo::isStackSlot(Reg))
|
|
|
|
OS << "SS#" << TargetRegisterInfo::stackSlot2Index(Reg);
|
2011-01-09 03:05:53 +00:00
|
|
|
else if (TargetRegisterInfo::isVirtualRegister(Reg))
|
|
|
|
OS << "%vreg" << TargetRegisterInfo::virtReg2Index(Reg);
|
2011-01-09 21:17:37 +00:00
|
|
|
else if (TRI && Reg < TRI->getNumRegs())
|
2011-01-09 03:05:53 +00:00
|
|
|
OS << '%' << TRI->getName(Reg);
|
2010-12-14 18:53:39 +00:00
|
|
|
else
|
2011-01-09 03:05:53 +00:00
|
|
|
OS << "%physreg" << Reg;
|
|
|
|
if (SubIdx) {
|
|
|
|
if (TRI)
|
|
|
|
OS << ':' << TRI->getSubRegIndexName(SubIdx);
|
|
|
|
else
|
|
|
|
OS << ":sub(" << SubIdx << ')';
|
|
|
|
}
|
2010-12-14 18:53:39 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 12:39:06 +00:00
|
|
|
/// getMinimalPhysRegClass - Returns the Register Class of a physical
|
2010-07-06 15:31:55 +00:00
|
|
|
/// register of the given type, picking the most sub register class of
|
|
|
|
/// the right type that contains this physreg.
|
2010-06-02 12:39:06 +00:00
|
|
|
const TargetRegisterClass *
|
2010-06-29 14:02:34 +00:00
|
|
|
TargetRegisterInfo::getMinimalPhysRegClass(unsigned reg, EVT VT) const {
|
2010-06-02 12:39:06 +00:00
|
|
|
assert(isPhysicalRegister(reg) && "reg must be a physical register");
|
|
|
|
|
|
|
|
// Pick the most sub register class of the right type that contains
|
|
|
|
// this physreg.
|
|
|
|
const TargetRegisterClass* BestRC = 0;
|
|
|
|
for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I){
|
|
|
|
const TargetRegisterClass* RC = *I;
|
2010-06-29 14:02:34 +00:00
|
|
|
if ((VT == MVT::Other || RC->hasType(VT)) && RC->contains(reg) &&
|
|
|
|
(!BestRC || BestRC->hasSubClass(RC)))
|
2010-06-02 12:39:06 +00:00
|
|
|
BestRC = RC;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(BestRC && "Couldn't find the register class");
|
|
|
|
return BestRC;
|
|
|
|
}
|
|
|
|
|
2007-04-17 23:33:39 +00:00
|
|
|
/// getAllocatableSetForRC - Toggle the bits that represent allocatable
|
|
|
|
/// registers for the specific register class.
|
2009-10-09 22:09:05 +00:00
|
|
|
static void getAllocatableSetForRC(const MachineFunction &MF,
|
2010-09-02 18:44:51 +00:00
|
|
|
const TargetRegisterClass *RC, BitVector &R){
|
2011-06-17 23:17:13 +00:00
|
|
|
ArrayRef<unsigned> Order = RC->getRawAllocationOrder(MF);
|
|
|
|
for (unsigned i = 0; i != Order.size(); ++i)
|
|
|
|
R.set(Order[i]);
|
2007-04-17 23:33:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 22:09:05 +00:00
|
|
|
BitVector TargetRegisterInfo::getAllocatableSet(const MachineFunction &MF,
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterClass *RC) const {
|
2011-06-24 01:44:41 +00:00
|
|
|
BitVector Allocatable(getNumRegs());
|
2007-04-17 23:33:39 +00:00
|
|
|
if (RC) {
|
|
|
|
getAllocatableSetForRC(MF, RC, Allocatable);
|
2010-09-02 18:18:52 +00:00
|
|
|
} else {
|
|
|
|
for (TargetRegisterInfo::regclass_iterator I = regclass_begin(),
|
2007-04-17 23:33:39 +00:00
|
|
|
E = regclass_end(); I != E; ++I)
|
2011-06-02 23:07:20 +00:00
|
|
|
if ((*I)->isAllocatable())
|
|
|
|
getAllocatableSetForRC(MF, *I, Allocatable);
|
2010-09-02 18:18:52 +00:00
|
|
|
}
|
2010-09-02 16:31:21 +00:00
|
|
|
|
|
|
|
// Mask out the reserved registers
|
|
|
|
BitVector Reserved = getReservedRegs(MF);
|
2010-10-28 18:41:23 +00:00
|
|
|
Allocatable &= Reserved.flip();
|
2010-09-02 16:31:21 +00:00
|
|
|
|
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
|
|
|
|
2009-04-30 21:23:32 +00:00
|
|
|
const TargetRegisterClass *
|
2011-09-30 22:18:51 +00:00
|
|
|
TargetRegisterInfo::getCommonSubClass(const TargetRegisterClass *A,
|
|
|
|
const TargetRegisterClass *B) const {
|
2011-09-30 22:19:07 +00:00
|
|
|
// First take care of the trivial cases.
|
2009-04-30 21:23:32 +00:00
|
|
|
if (A == B)
|
|
|
|
return A;
|
|
|
|
if (!A || !B)
|
|
|
|
return 0;
|
|
|
|
|
2011-09-30 22:19:07 +00:00
|
|
|
// Register classes are ordered topologically, so the largest common
|
|
|
|
// sub-class it the common sub-class with the smallest ID.
|
|
|
|
const unsigned *SubA = A->getSubClassMask();
|
|
|
|
const unsigned *SubB = B->getSubClassMask();
|
2009-04-30 21:23:32 +00:00
|
|
|
|
2011-09-30 22:19:07 +00:00
|
|
|
// We could start the search from max(A.ID, B.ID), but we are only going to
|
|
|
|
// execute 2-3 iterations anyway.
|
|
|
|
for (unsigned Base = 0, BaseE = getNumRegClasses(); Base < BaseE; Base += 32)
|
|
|
|
if (unsigned Common = *SubA++ & *SubB++)
|
|
|
|
return getRegClass(Base + CountTrailingZeros_32(Common));
|
|
|
|
|
|
|
|
// No common sub-class exists.
|
|
|
|
return NULL;
|
2009-04-30 21:23:32 +00:00
|
|
|
}
|