2010-12-10 18:36:02 +00:00
|
|
|
//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements an allocation order for virtual registers.
|
|
|
|
//
|
|
|
|
// The preferred allocation order for a virtual register depends on allocation
|
|
|
|
// hints and target hooks. The AllocationOrder class encapsulates all of that.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AllocationOrder.h"
|
|
|
|
#include "VirtRegMap.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-06-06 20:29:31 +00:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2010-12-10 18:36:02 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Compare VirtRegMap::getRegAllocPref().
|
|
|
|
AllocationOrder::AllocationOrder(unsigned VirtReg,
|
|
|
|
const VirtRegMap &VRM,
|
2011-06-03 20:34:53 +00:00
|
|
|
const RegisterClassInfo &RegClassInfo)
|
2011-06-06 21:02:04 +00:00
|
|
|
: Begin(0), End(0), Pos(0), RCI(RegClassInfo), OwnedBegin(false) {
|
2010-12-10 18:36:02 +00:00
|
|
|
const TargetRegisterClass *RC = VRM.getRegInfo().getRegClass(VirtReg);
|
|
|
|
std::pair<unsigned, unsigned> HintPair =
|
|
|
|
VRM.getRegInfo().getRegAllocationHint(VirtReg);
|
|
|
|
|
|
|
|
// HintPair.second is a register, phys or virt.
|
|
|
|
Hint = HintPair.second;
|
|
|
|
|
|
|
|
// Translate to physreg, or 0 if not assigned yet.
|
2011-01-10 02:58:51 +00:00
|
|
|
if (TargetRegisterInfo::isVirtualRegister(Hint))
|
2010-12-10 18:36:02 +00:00
|
|
|
Hint = VRM.getPhys(Hint);
|
|
|
|
|
2011-06-06 21:02:04 +00:00
|
|
|
// The first hint pair component indicates a target-specific hint.
|
|
|
|
if (HintPair.first) {
|
|
|
|
const TargetRegisterInfo &TRI = VRM.getTargetRegInfo();
|
|
|
|
// The remaining allocation order may depend on the hint.
|
2012-03-04 10:16:38 +00:00
|
|
|
ArrayRef<uint16_t> Order =
|
2011-06-16 23:31:16 +00:00
|
|
|
TRI.getRawAllocationOrder(RC, HintPair.first, Hint,
|
|
|
|
VRM.getMachineFunction());
|
|
|
|
if (Order.empty())
|
2011-06-06 21:02:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Copy the allocation order with reserved registers removed.
|
|
|
|
OwnedBegin = true;
|
2011-06-16 23:31:16 +00:00
|
|
|
unsigned *P = new unsigned[Order.size()];
|
2011-06-06 21:02:04 +00:00
|
|
|
Begin = P;
|
2011-06-16 23:31:16 +00:00
|
|
|
for (unsigned i = 0; i != Order.size(); ++i)
|
|
|
|
if (!RCI.isReserved(Order[i]))
|
|
|
|
*P++ = Order[i];
|
2011-06-06 21:02:04 +00:00
|
|
|
End = P;
|
|
|
|
|
|
|
|
// Target-dependent hints require resolution.
|
|
|
|
Hint = TRI.ResolveRegAllocHint(HintPair.first, Hint,
|
|
|
|
VRM.getMachineFunction());
|
|
|
|
} else {
|
|
|
|
// If there is no hint or just a normal hint, use the cached allocation
|
|
|
|
// order from RegisterClassInfo.
|
|
|
|
ArrayRef<unsigned> O = RCI.getOrder(RC);
|
|
|
|
Begin = O.begin();
|
|
|
|
End = O.end();
|
|
|
|
}
|
2010-12-10 18:36:02 +00:00
|
|
|
|
|
|
|
// The hint must be a valid physreg for allocation.
|
|
|
|
if (Hint && (!TargetRegisterInfo::isPhysicalRegister(Hint) ||
|
2011-06-03 20:34:53 +00:00
|
|
|
!RC->contains(Hint) || RCI.isReserved(Hint)))
|
2010-12-10 18:36:02 +00:00
|
|
|
Hint = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-06 21:02:04 +00:00
|
|
|
AllocationOrder::~AllocationOrder() {
|
|
|
|
if (OwnedBegin)
|
|
|
|
delete [] Begin;
|
2010-12-10 18:36:02 +00:00
|
|
|
}
|