2010-12-11 02:36:02 +08:00
|
|
|
//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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-11 02:36:02 +08: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-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().
|
2020-09-29 07:41:28 +08:00
|
|
|
AllocationOrder AllocationOrder::create(unsigned VirtReg, const VirtRegMap &VRM,
|
|
|
|
const RegisterClassInfo &RegClassInfo,
|
|
|
|
const LiveRegMatrix *Matrix) {
|
2012-12-04 06:51:04 +08:00
|
|
|
const MachineFunction &MF = VRM.getMachineFunction();
|
|
|
|
const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
|
2020-09-29 07:41:28 +08: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-11 02:36:02 +08:00
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG({
|
2012-12-04 06:51:04 +08:00
|
|
|
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
|
2020-09-29 07:41:28 +08:00
|
|
|
return AllocationOrder(std::move(Hints), Order, HardHints);
|
2012-12-04 06:51:04 +08:00
|
|
|
}
|