2011-02-20 12:57:14 +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"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-08-15 19:34:23 +00:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
#define DEBUG_TYPE "regalloc"
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
// Compare VirtRegMap::getRegAllocPref().
|
|
|
|
AllocationOrder::AllocationOrder(unsigned VirtReg,
|
|
|
|
const VirtRegMap &VRM,
|
2011-06-12 15:42:51 +00:00
|
|
|
const RegisterClassInfo &RegClassInfo)
|
2013-04-08 18:41:23 +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);
|
|
|
|
rewind();
|
|
|
|
|
|
|
|
DEBUG({
|
|
|
|
if (!Hints.empty()) {
|
|
|
|
dbgs() << "hints:";
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
|
|
|
dbgs() << ' ' << PrintReg(Hints[I], TRI);
|
|
|
|
dbgs() << '\n';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#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
|
2011-02-20 12:57:14 +00:00
|
|
|
}
|