2010-12-10 19:36:02 +01:00
|
|
|
//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-12-10 19:36:02 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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-03 23:51:04 +01:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2010-12-10 19:36:02 +01:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-06-06 22:29:31 +02:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2012-11-28 20:13:06 +01:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
2012-12-03 23:51:04 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-12-10 19:36:02 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 04:02:50 +02:00
|
|
|
#define DEBUG_TYPE "regalloc"
|
|
|
|
|
2010-12-10 19:36:02 +01:00
|
|
|
// Compare VirtRegMap::getRegAllocPref().
|
2020-09-29 01:41:28 +02:00
|
|
|
AllocationOrder AllocationOrder::create(unsigned VirtReg, const VirtRegMap &VRM,
|
|
|
|
const RegisterClassInfo &RegClassInfo,
|
|
|
|
const LiveRegMatrix *Matrix) {
|
2012-12-03 23:51:04 +01:00
|
|
|
const MachineFunction &MF = VRM.getMachineFunction();
|
|
|
|
const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
|
2020-09-29 01:41:28 +02:00
|
|
|
auto Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
|
|
|
|
SmallVector<MCPhysReg, 16> Hints;
|
|
|
|
bool HardHints =
|
|
|
|
TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix);
|
2010-12-10 19:36:02 +01:00
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG({
|
2012-12-03 23:51:04 +01:00
|
|
|
if (!Hints.empty()) {
|
|
|
|
dbgs() << "hints:";
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
2017-11-28 13:42:37 +01:00
|
|
|
dbgs() << ' ' << printReg(Hints[I], TRI);
|
2012-12-03 23:51:04 +01:00
|
|
|
dbgs() << '\n';
|
|
|
|
}
|
|
|
|
});
|
2013-02-19 19:41:01 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
|
2016-08-12 00:21:41 +02:00
|
|
|
assert(is_contained(Order, Hints[I]) &&
|
2013-02-19 19:41:01 +01:00
|
|
|
"Target hint is outside allocation order.");
|
|
|
|
#endif
|
2020-09-29 01:41:28 +02:00
|
|
|
return AllocationOrder(std::move(Hints), Order, HardHints);
|
2012-12-03 23:51:04 +01:00
|
|
|
}
|