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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 22:51:04 +00:00
|
|
|
#define DEBUG_TYPE "regalloc"
|
2010-12-10 18:36:02 +00:00
|
|
|
#include "AllocationOrder.h"
|
2012-12-03 22:51:04 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2010-12-10 18:36:02 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-06-06 20:29:31 +00:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2012-11-28 19:13:06 +00:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
2012-12-03 22:51:04 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.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)
|
2012-12-03 22:51:04 +00:00
|
|
|
: Pos(0) {
|
|
|
|
const MachineFunction &MF = VRM.getMachineFunction();
|
|
|
|
const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
|
|
|
|
Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
|
|
|
|
TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM);
|
2012-12-04 22:25:16 +00:00
|
|
|
rewind();
|
2010-12-10 18:36:02 +00:00
|
|
|
|
2012-12-03 22:51:04 +00:00
|
|
|
DEBUG({
|
|
|
|
if (!Hints.empty()) {
|
|
|
|
dbgs() << "hints:";
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
|
|
|
dbgs() << ' ' << PrintReg(Hints[I], TRI);
|
|
|
|
dbgs() << '\n';
|
|
|
|
}
|
|
|
|
});
|
2013-02-19 18:41:01 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
|
|
|
assert(std::find(Order.begin(), Order.end(), Hints[I]) != Order.end() &&
|
|
|
|
"Target hint is outside allocation order.");
|
|
|
|
#endif
|
2012-12-03 22:51:04 +00:00
|
|
|
}
|