2010-12-11 02:36:02 +08: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"
|
2012-12-04 06:51:04 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2010-12-11 02:36:02 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-06-07 04:29:31 +08:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2012-11-29 03:13:06 +08:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
2012-12-04 06:51:04 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-12-11 02:36:02 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "regalloc"
|
|
|
|
|
2010-12-11 02:36:02 +08:00
|
|
|
// Compare VirtRegMap::getRegAllocPref().
|
|
|
|
AllocationOrder::AllocationOrder(unsigned VirtReg,
|
|
|
|
const VirtRegMap &VRM,
|
2015-07-16 06:16:00 +08:00
|
|
|
const RegisterClassInfo &RegClassInfo,
|
|
|
|
const LiveRegMatrix *Matrix)
|
2017-11-10 16:46:26 +08:00
|
|
|
: Pos(0), HardHints(false) {
|
2012-12-04 06:51:04 +08:00
|
|
|
const MachineFunction &MF = VRM.getMachineFunction();
|
|
|
|
const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
|
|
|
|
Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
|
2017-11-10 16:46:26 +08:00
|
|
|
if (TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix))
|
|
|
|
HardHints = true;
|
2012-12-05 06:25:16 +08:00
|
|
|
rewind();
|
2010-12-11 02:36:02 +08:00
|
|
|
|
2012-12-04 06:51:04 +08:00
|
|
|
DEBUG({
|
|
|
|
if (!Hints.empty()) {
|
|
|
|
dbgs() << "hints:";
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
2017-11-28 20:42:37 +08:00
|
|
|
dbgs() << ' ' << printReg(Hints[I], TRI);
|
2012-12-04 06:51:04 +08:00
|
|
|
dbgs() << '\n';
|
|
|
|
}
|
|
|
|
});
|
2013-02-20 02:41:01 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
2016-08-12 06:21:41 +08:00
|
|
|
assert(is_contained(Order, Hints[I]) &&
|
2013-02-20 02:41:01 +08:00
|
|
|
"Target hint is outside allocation order.");
|
|
|
|
#endif
|
2012-12-04 06:51:04 +08:00
|
|
|
}
|