2017-06-26 20:32:52 +00:00
|
|
|
//==- TargetRegisterInfo.cpp - Target Register Information Implementation --==//
|
2009-06-02 17:52:33 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the TargetRegisterInfo interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-12-18 20:10:56 +00:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-12-18 20:10:56 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2015-12-30 11:46:15 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include "llvm/CodeGen/MachineValueType.h"
|
2017-12-18 20:10:56 +00:00
|
|
|
#include "llvm/CodeGen/TargetFrameLowering.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
2015-12-30 11:46:15 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2015-01-18 16:17:27 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/Printable.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-06-26 20:32:52 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <utility>
|
2015-12-30 11:46:15 +00:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "target-reg-info"
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-17 15:36:56 +00:00
|
|
|
TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
|
2009-06-02 17:52:33 +00:00
|
|
|
regclass_iterator RCB, regclass_iterator RCE,
|
2012-12-02 13:10:19 +00:00
|
|
|
const char *const *SRINames,
|
2017-01-02 19:17:04 +00:00
|
|
|
const LaneBitmask *SRILaneMasks,
|
2017-12-18 20:10:56 +00:00
|
|
|
LaneBitmask SRICoveringLanes,
|
|
|
|
const RegClassInfo *const RCIs,
|
|
|
|
unsigned Mode)
|
2012-12-02 13:10:19 +00:00
|
|
|
: InfoDesc(ID), SubRegIndexNames(SRINames),
|
|
|
|
SubRegIndexLaneMasks(SRILaneMasks),
|
2013-12-22 00:04:03 +00:00
|
|
|
RegClassBegin(RCB), RegClassEnd(RCE),
|
2017-12-18 20:10:56 +00:00
|
|
|
CoveringLanes(SRICoveringLanes),
|
|
|
|
RCInfos(RCIs), HwMode(Mode) {
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 20:32:52 +00:00
|
|
|
TargetRegisterInfo::~TargetRegisterInfo() = default;
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
void TargetRegisterInfo::markSuperRegs(BitVector &RegisterSet, unsigned Reg)
|
|
|
|
const {
|
|
|
|
for (MCSuperRegIterator AI(Reg, this, true); AI.isValid(); ++AI)
|
|
|
|
RegisterSet.set(*AI);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetRegisterInfo::checkAllSuperRegsMarked(const BitVector &RegisterSet,
|
|
|
|
ArrayRef<MCPhysReg> Exceptions) const {
|
|
|
|
// Check that all super registers of reserved regs are reserved as well.
|
|
|
|
BitVector Checked(getNumRegs());
|
2017-05-17 20:22:39 +00:00
|
|
|
for (unsigned Reg : RegisterSet.set_bits()) {
|
2017-01-02 19:17:04 +00:00
|
|
|
if (Checked[Reg])
|
|
|
|
continue;
|
|
|
|
for (MCSuperRegIterator SR(Reg, this); SR.isValid(); ++SR) {
|
|
|
|
if (!RegisterSet[*SR] && !is_contained(Exceptions, Reg)) {
|
2017-12-18 20:10:56 +00:00
|
|
|
dbgs() << "Error: Super register " << printReg(*SR, this)
|
|
|
|
<< " of reserved register " << printReg(Reg, this)
|
2017-01-02 19:17:04 +00:00
|
|
|
<< " is not reserved.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We transitively check superregs. So we can remember this for later
|
|
|
|
// to avoid compiletime explosion in deep register hierarchies.
|
|
|
|
Checked.set(*SR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2017-12-18 20:10:56 +00:00
|
|
|
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI,
|
2015-12-30 11:46:15 +00:00
|
|
|
unsigned SubIdx) {
|
|
|
|
return Printable([Reg, TRI, SubIdx](raw_ostream &OS) {
|
|
|
|
if (!Reg)
|
|
|
|
OS << "%noreg";
|
|
|
|
else if (TargetRegisterInfo::isStackSlot(Reg))
|
|
|
|
OS << "SS#" << TargetRegisterInfo::stackSlot2Index(Reg);
|
|
|
|
else if (TargetRegisterInfo::isVirtualRegister(Reg))
|
2017-12-18 20:10:56 +00:00
|
|
|
OS << '%' << TargetRegisterInfo::virtReg2Index(Reg);
|
|
|
|
else if (!TRI)
|
|
|
|
OS << '%' << "physreg" << Reg;
|
|
|
|
else if (Reg < TRI->getNumRegs()) {
|
|
|
|
OS << '%';
|
|
|
|
printLowerCase(TRI->getName(Reg), OS);
|
|
|
|
} else
|
|
|
|
llvm_unreachable("Register kind is unsupported.");
|
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
if (SubIdx) {
|
|
|
|
if (TRI)
|
|
|
|
OS << ':' << TRI->getSubRegIndexName(SubIdx);
|
|
|
|
else
|
|
|
|
OS << ":sub(" << SubIdx << ')';
|
|
|
|
}
|
|
|
|
});
|
2011-02-20 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 20:10:56 +00:00
|
|
|
Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI) {
|
2015-12-30 11:46:15 +00:00
|
|
|
return Printable([Unit, TRI](raw_ostream &OS) {
|
|
|
|
// Generic printout when TRI is missing.
|
|
|
|
if (!TRI) {
|
|
|
|
OS << "Unit~" << Unit;
|
|
|
|
return;
|
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
// Check for invalid register units.
|
|
|
|
if (Unit >= TRI->getNumRegUnits()) {
|
|
|
|
OS << "BadUnit~" << Unit;
|
|
|
|
return;
|
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
// Normal units have at least one root.
|
|
|
|
MCRegUnitRootIterator Roots(Unit, TRI);
|
|
|
|
assert(Roots.isValid() && "Unit has no roots.");
|
|
|
|
OS << TRI->getName(*Roots);
|
|
|
|
for (++Roots; Roots.isValid(); ++Roots)
|
|
|
|
OS << '~' << TRI->getName(*Roots);
|
|
|
|
});
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 20:10:56 +00:00
|
|
|
Printable printVRegOrUnit(unsigned Unit, const TargetRegisterInfo *TRI) {
|
2015-12-30 11:46:15 +00:00
|
|
|
return Printable([Unit, TRI](raw_ostream &OS) {
|
|
|
|
if (TRI && TRI->isVirtualRegister(Unit)) {
|
2017-12-18 20:10:56 +00:00
|
|
|
OS << '%' << TargetRegisterInfo::virtReg2Index(Unit);
|
2015-12-30 11:46:15 +00:00
|
|
|
} else {
|
2017-12-18 20:10:56 +00:00
|
|
|
OS << printRegUnit(Unit, TRI);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Printable printRegClassOrBank(unsigned Reg, const MachineRegisterInfo &RegInfo,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
return Printable([Reg, &RegInfo, TRI](raw_ostream &OS) {
|
|
|
|
if (RegInfo.getRegClassOrNull(Reg))
|
|
|
|
OS << StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
|
|
|
|
else if (RegInfo.getRegBankOrNull(Reg))
|
|
|
|
OS << StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
|
|
|
|
else {
|
|
|
|
OS << "_";
|
|
|
|
assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
|
|
|
|
"Generic registers must have a valid type");
|
2015-12-30 11:46:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-26 20:32:52 +00:00
|
|
|
} // end namespace llvm
|
2015-12-30 11:46:15 +00:00
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
/// getAllocatableClass - Return the maximal subclass of the given register
|
|
|
|
/// class that is alloctable, or NULL.
|
|
|
|
const TargetRegisterClass *
|
|
|
|
TargetRegisterInfo::getAllocatableClass(const TargetRegisterClass *RC) const {
|
|
|
|
if (!RC || RC->isAllocatable())
|
|
|
|
return RC;
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
for (BitMaskClassIterator It(RC->getSubClassMask(), *this); It.isValid();
|
|
|
|
++It) {
|
|
|
|
const TargetRegisterClass *SubRC = getRegClass(It.getID());
|
|
|
|
if (SubRC->isAllocatable())
|
|
|
|
return SubRC;
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
2014-11-24 09:08:18 +00:00
|
|
|
return nullptr;
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:19:57 +00:00
|
|
|
/// getMinimalPhysRegClass - Returns the Register Class of a physical
|
|
|
|
/// register of the given type, picking the most sub register class of
|
|
|
|
/// the right type that contains this physreg.
|
2009-06-02 17:52:33 +00:00
|
|
|
const TargetRegisterClass *
|
2015-01-18 16:17:27 +00:00
|
|
|
TargetRegisterInfo::getMinimalPhysRegClass(unsigned reg, MVT VT) const {
|
2009-06-02 17:52:33 +00:00
|
|
|
assert(isPhysicalRegister(reg) && "reg must be a physical register");
|
|
|
|
|
2010-07-13 17:19:57 +00:00
|
|
|
// Pick the most sub register class of the right type that contains
|
2009-06-02 17:52:33 +00:00
|
|
|
// this physreg.
|
2014-11-24 09:08:18 +00:00
|
|
|
const TargetRegisterClass* BestRC = nullptr;
|
2017-04-16 16:01:22 +00:00
|
|
|
for (const TargetRegisterClass* RC : regclasses()) {
|
2017-04-26 19:45:00 +00:00
|
|
|
if ((VT == MVT::Other || isTypeLegalForClass(*RC, VT)) &&
|
|
|
|
RC->contains(reg) && (!BestRC || BestRC->hasSubClass(RC)))
|
2009-06-02 17:52:33 +00:00
|
|
|
BestRC = RC;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(BestRC && "Couldn't find the register class");
|
|
|
|
return BestRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getAllocatableSetForRC - Toggle the bits that represent allocatable
|
|
|
|
/// registers for the specific register class.
|
2009-10-14 17:57:32 +00:00
|
|
|
static void getAllocatableSetForRC(const MachineFunction &MF,
|
2010-09-17 15:48:55 +00:00
|
|
|
const TargetRegisterClass *RC, BitVector &R){
|
2012-08-15 19:34:23 +00:00
|
|
|
assert(RC->isAllocatable() && "invalid for nonallocatable sets");
|
2014-11-24 09:08:18 +00:00
|
|
|
ArrayRef<MCPhysReg> Order = RC->getRawAllocationOrder(MF);
|
2011-07-17 15:36:56 +00:00
|
|
|
for (unsigned i = 0; i != Order.size(); ++i)
|
|
|
|
R.set(Order[i]);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
BitVector TargetRegisterInfo::getAllocatableSet(const MachineFunction &MF,
|
2009-06-02 17:52:33 +00:00
|
|
|
const TargetRegisterClass *RC) const {
|
2011-07-17 15:36:56 +00:00
|
|
|
BitVector Allocatable(getNumRegs());
|
2009-06-02 17:52:33 +00:00
|
|
|
if (RC) {
|
2012-08-15 19:34:23 +00:00
|
|
|
// A register class with no allocatable subclass returns an empty set.
|
|
|
|
const TargetRegisterClass *SubClass = getAllocatableClass(RC);
|
|
|
|
if (SubClass)
|
|
|
|
getAllocatableSetForRC(MF, SubClass, Allocatable);
|
2010-09-17 15:48:55 +00:00
|
|
|
} else {
|
2017-04-16 16:01:22 +00:00
|
|
|
for (const TargetRegisterClass *C : regclasses())
|
|
|
|
if (C->isAllocatable())
|
|
|
|
getAllocatableSetForRC(MF, C, Allocatable);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 15:48:55 +00:00
|
|
|
// Mask out the reserved registers
|
|
|
|
BitVector Reserved = getReservedRegs(MF);
|
2011-02-20 12:57:14 +00:00
|
|
|
Allocatable &= Reserved.flip();
|
2010-09-17 15:48:55 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
return Allocatable;
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
static inline
|
|
|
|
const TargetRegisterClass *firstCommonClass(const uint32_t *A,
|
|
|
|
const uint32_t *B,
|
2015-12-30 11:46:15 +00:00
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
const MVT::SimpleValueType SVT =
|
|
|
|
MVT::SimpleValueType::Any) {
|
|
|
|
const MVT VT(SVT);
|
2012-08-15 19:34:23 +00:00
|
|
|
for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; I += 32)
|
2015-12-30 11:46:15 +00:00
|
|
|
if (unsigned Common = *A++ & *B++) {
|
|
|
|
const TargetRegisterClass *RC =
|
|
|
|
TRI->getRegClass(I + countTrailingZeros(Common));
|
2017-04-26 19:45:00 +00:00
|
|
|
if (SVT == MVT::SimpleValueType::Any || TRI->isTypeLegalForClass(*RC, VT))
|
2015-12-30 11:46:15 +00:00
|
|
|
return RC;
|
|
|
|
}
|
2014-11-24 09:08:18 +00:00
|
|
|
return nullptr;
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
const TargetRegisterClass *
|
2011-10-20 21:10:27 +00:00
|
|
|
TargetRegisterInfo::getCommonSubClass(const TargetRegisterClass *A,
|
2015-12-30 11:46:15 +00:00
|
|
|
const TargetRegisterClass *B,
|
|
|
|
const MVT::SimpleValueType SVT) const {
|
2011-10-20 21:10:27 +00:00
|
|
|
// First take care of the trivial cases.
|
2009-06-02 17:52:33 +00:00
|
|
|
if (A == B)
|
|
|
|
return A;
|
|
|
|
if (!A || !B)
|
2014-11-24 09:08:18 +00:00
|
|
|
return nullptr;
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2011-10-20 21:10:27 +00:00
|
|
|
// Register classes are ordered topologically, so the largest common
|
|
|
|
// sub-class it the common sub-class with the smallest ID.
|
2015-12-30 11:46:15 +00:00
|
|
|
return firstCommonClass(A->getSubClassMask(), B->getSubClassMask(), this, SVT);
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
const TargetRegisterClass *
|
|
|
|
TargetRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
|
|
|
|
const TargetRegisterClass *B,
|
|
|
|
unsigned Idx) const {
|
|
|
|
assert(A && B && "Missing register class");
|
|
|
|
assert(Idx && "Bad sub-register index");
|
|
|
|
|
|
|
|
// Find Idx in the list of super-register indices.
|
|
|
|
for (SuperRegClassIterator RCI(B, this); RCI.isValid(); ++RCI)
|
|
|
|
if (RCI.getSubReg() == Idx)
|
|
|
|
// The bit mask contains all register classes that are projected into B
|
|
|
|
// by Idx. Find a class that is also a sub-class of A.
|
|
|
|
return firstCommonClass(RCI.getMask(), A->getSubClassMask(), this);
|
2014-11-24 09:08:18 +00:00
|
|
|
return nullptr;
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
2011-10-20 21:10:27 +00:00
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
const TargetRegisterClass *TargetRegisterInfo::
|
|
|
|
getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
|
|
|
|
const TargetRegisterClass *RCB, unsigned SubB,
|
|
|
|
unsigned &PreA, unsigned &PreB) const {
|
|
|
|
assert(RCA && SubA && RCB && SubB && "Invalid arguments");
|
|
|
|
|
|
|
|
// Search all pairs of sub-register indices that project into RCA and RCB
|
|
|
|
// respectively. This is quadratic, but usually the sets are very small. On
|
|
|
|
// most targets like X86, there will only be a single sub-register index
|
|
|
|
// (e.g., sub_16bit projecting into GR16).
|
|
|
|
//
|
|
|
|
// The worst case is a register class like DPR on ARM.
|
|
|
|
// We have indices dsub_0..dsub_7 projecting into that class.
|
|
|
|
//
|
|
|
|
// It is very common that one register class is a sub-register of the other.
|
|
|
|
// Arrange for RCA to be the larger register so the answer will be found in
|
|
|
|
// the first iteration. This makes the search linear for the most common
|
|
|
|
// case.
|
2014-11-24 09:08:18 +00:00
|
|
|
const TargetRegisterClass *BestRC = nullptr;
|
2012-08-15 19:34:23 +00:00
|
|
|
unsigned *BestPreA = &PreA;
|
|
|
|
unsigned *BestPreB = &PreB;
|
2017-04-26 19:45:00 +00:00
|
|
|
if (getRegSizeInBits(*RCA) < getRegSizeInBits(*RCB)) {
|
2012-08-15 19:34:23 +00:00
|
|
|
std::swap(RCA, RCB);
|
|
|
|
std::swap(SubA, SubB);
|
|
|
|
std::swap(BestPreA, BestPreB);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also terminate the search one we have found a register class as small as
|
|
|
|
// RCA.
|
2017-04-26 19:45:00 +00:00
|
|
|
unsigned MinSize = getRegSizeInBits(*RCA);
|
2012-08-15 19:34:23 +00:00
|
|
|
|
|
|
|
for (SuperRegClassIterator IA(RCA, this, true); IA.isValid(); ++IA) {
|
|
|
|
unsigned FinalA = composeSubRegIndices(IA.getSubReg(), SubA);
|
|
|
|
for (SuperRegClassIterator IB(RCB, this, true); IB.isValid(); ++IB) {
|
|
|
|
// Check if a common super-register class exists for this index pair.
|
|
|
|
const TargetRegisterClass *RC =
|
|
|
|
firstCommonClass(IA.getMask(), IB.getMask(), this);
|
2017-04-26 19:45:00 +00:00
|
|
|
if (!RC || getRegSizeInBits(*RC) < MinSize)
|
2012-08-15 19:34:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// The indexes must compose identically: PreA+SubA == PreB+SubB.
|
|
|
|
unsigned FinalB = composeSubRegIndices(IB.getSubReg(), SubB);
|
|
|
|
if (FinalA != FinalB)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Is RC a better candidate than BestRC?
|
2017-04-26 19:45:00 +00:00
|
|
|
if (BestRC && getRegSizeInBits(*RC) >= getRegSizeInBits(*BestRC))
|
2012-08-15 19:34:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Yes, RC is the smallest super-register seen so far.
|
|
|
|
BestRC = RC;
|
|
|
|
*BestPreA = IA.getSubReg();
|
|
|
|
*BestPreB = IB.getSubReg();
|
|
|
|
|
|
|
|
// Bail early if we reached MinSize. We won't find a better candidate.
|
2017-04-26 19:45:00 +00:00
|
|
|
if (getRegSizeInBits(*BestRC) == MinSize)
|
2012-08-15 19:34:23 +00:00
|
|
|
return BestRC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BestRC;
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2013-04-08 18:41:23 +00:00
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
/// \brief Check if the registers defined by the pair (RegisterClass, SubReg)
|
|
|
|
/// share the same register file.
|
|
|
|
static bool shareSameRegisterFile(const TargetRegisterInfo &TRI,
|
|
|
|
const TargetRegisterClass *DefRC,
|
|
|
|
unsigned DefSubReg,
|
|
|
|
const TargetRegisterClass *SrcRC,
|
|
|
|
unsigned SrcSubReg) {
|
|
|
|
// Same register class.
|
|
|
|
if (DefRC == SrcRC)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Both operands are sub registers. Check if they share a register class.
|
|
|
|
unsigned SrcIdx, DefIdx;
|
|
|
|
if (SrcSubReg && DefSubReg) {
|
|
|
|
return TRI.getCommonSuperRegClass(SrcRC, SrcSubReg, DefRC, DefSubReg,
|
|
|
|
SrcIdx, DefIdx) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At most one of the register is a sub register, make it Src to avoid
|
|
|
|
// duplicating the test.
|
|
|
|
if (!SrcSubReg) {
|
|
|
|
std::swap(DefSubReg, SrcSubReg);
|
|
|
|
std::swap(DefRC, SrcRC);
|
|
|
|
}
|
|
|
|
|
|
|
|
// One of the register is a sub register, check if we can get a superclass.
|
|
|
|
if (SrcSubReg)
|
|
|
|
return TRI.getMatchingSuperRegClass(SrcRC, DefRC, SrcSubReg) != nullptr;
|
|
|
|
|
|
|
|
// Plain copy.
|
|
|
|
return TRI.getCommonSubClass(DefRC, SrcRC) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetRegisterInfo::shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
|
|
|
|
unsigned DefSubReg,
|
|
|
|
const TargetRegisterClass *SrcRC,
|
|
|
|
unsigned SrcSubReg) const {
|
|
|
|
// If this source does not incur a cross register bank copy, use it.
|
|
|
|
return shareSameRegisterFile(*this, DefRC, DefSubReg, SrcRC, SrcSubReg);
|
|
|
|
}
|
|
|
|
|
2013-04-08 18:41:23 +00:00
|
|
|
// Compute target-independent register allocator hints to help eliminate copies.
|
2017-12-18 20:10:56 +00:00
|
|
|
bool
|
2013-04-08 18:41:23 +00:00
|
|
|
TargetRegisterInfo::getRegAllocationHints(unsigned VirtReg,
|
|
|
|
ArrayRef<MCPhysReg> Order,
|
|
|
|
SmallVectorImpl<MCPhysReg> &Hints,
|
|
|
|
const MachineFunction &MF,
|
2015-12-30 11:46:15 +00:00
|
|
|
const VirtRegMap *VRM,
|
|
|
|
const LiveRegMatrix *Matrix) const {
|
2013-04-08 18:41:23 +00:00
|
|
|
const MachineRegisterInfo &MRI = MF.getRegInfo();
|
2017-12-18 20:10:56 +00:00
|
|
|
const std::pair<unsigned, SmallVector<unsigned, 4>> &Hints_MRI =
|
|
|
|
MRI.getRegAllocationHints(VirtReg);
|
|
|
|
|
|
|
|
// First hint may be a target hint.
|
|
|
|
bool Skip = (Hints_MRI.first != 0);
|
|
|
|
for (auto Reg : Hints_MRI.second) {
|
|
|
|
if (Skip) {
|
|
|
|
Skip = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Target-independent hints are either a physical or a virtual register.
|
|
|
|
unsigned Phys = Reg;
|
|
|
|
if (VRM && isVirtualRegister(Phys))
|
|
|
|
Phys = VRM->getPhys(Phys);
|
|
|
|
|
|
|
|
// Check that Phys is a valid hint in VirtReg's register class.
|
|
|
|
if (!isPhysicalRegister(Phys))
|
|
|
|
continue;
|
|
|
|
if (MRI.isReserved(Phys))
|
|
|
|
continue;
|
|
|
|
// Check that Phys is in the allocation order. We shouldn't heed hints
|
|
|
|
// from VirtReg's register class if they aren't in the allocation order. The
|
|
|
|
// target probably has a reason for removing the register.
|
|
|
|
if (!is_contained(Order, Phys))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// All clear, tell the register allocator to prefer this register.
|
|
|
|
Hints.push_back(Phys);
|
|
|
|
}
|
|
|
|
return false;
|
2013-04-08 18:41:23 +00:00
|
|
|
}
|
2015-01-18 16:17:27 +00:00
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
bool TargetRegisterInfo::canRealignStack(const MachineFunction &MF) const {
|
2017-12-18 20:10:56 +00:00
|
|
|
return !MF.getFunction().hasFnAttribute("no-realign-stack");
|
2015-12-30 11:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetRegisterInfo::needsStackRealignment(
|
|
|
|
const MachineFunction &MF) const {
|
2017-01-02 19:17:04 +00:00
|
|
|
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
2015-12-30 11:46:15 +00:00
|
|
|
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
|
2017-12-18 20:10:56 +00:00
|
|
|
const Function &F = MF.getFunction();
|
2015-12-30 11:46:15 +00:00
|
|
|
unsigned StackAlign = TFI->getStackAlignment();
|
2017-01-02 19:17:04 +00:00
|
|
|
bool requiresRealignment = ((MFI.getMaxAlignment() > StackAlign) ||
|
2017-12-18 20:10:56 +00:00
|
|
|
F.hasFnAttribute(Attribute::StackAlignment));
|
|
|
|
if (F.hasFnAttribute("stackrealign") || requiresRealignment) {
|
2015-12-30 11:46:15 +00:00
|
|
|
if (canRealignStack(MF))
|
|
|
|
return true;
|
2017-12-18 20:10:56 +00:00
|
|
|
DEBUG(dbgs() << "Can't realign function's stack: " << F.getName() << "\n");
|
2015-12-30 11:46:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
bool TargetRegisterInfo::regmaskSubsetEqual(const uint32_t *mask0,
|
|
|
|
const uint32_t *mask1) const {
|
|
|
|
unsigned N = (getNumRegs()+31) / 32;
|
|
|
|
for (unsigned I = 0; I < N; ++I)
|
|
|
|
if ((mask0[I] & mask1[I]) != mask0[I])
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-18 16:17:27 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2017-04-16 16:01:22 +00:00
|
|
|
LLVM_DUMP_METHOD
|
|
|
|
void TargetRegisterInfo::dumpReg(unsigned Reg, unsigned SubRegIndex,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
2017-12-18 20:10:56 +00:00
|
|
|
dbgs() << printReg(Reg, TRI, SubRegIndex) << "\n";
|
2015-01-18 16:17:27 +00:00
|
|
|
}
|
|
|
|
#endif
|