LLVM 22.0.0git
AllocationOrder.cpp
Go to the documentation of this file.
1//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements an allocation order for virtual registers.
10//
11// The preferred allocation order for a virtual register depends on allocation
12// hints and target hooks. The AllocationOrder class encapsulates all of that.
13//
14//===----------------------------------------------------------------------===//
15
16#include "AllocationOrder.h"
21#include "llvm/Support/Debug.h"
23
24using namespace llvm;
25
26#define DEBUG_TYPE "regalloc"
27
28// Compare VirtRegMap::getRegAllocPref().
30 const RegisterClassInfo &RegClassInfo,
31 const LiveRegMatrix *Matrix) {
32 const MachineFunction &MF = VRM.getMachineFunction();
34 auto Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
36 bool HardHints =
37 TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix);
38
40 if (!Hints.empty()) {
41 dbgs() << "hints:";
42 for (MCPhysReg Hint : Hints)
43 dbgs() << ' ' << printReg(Hint, TRI);
44 dbgs() << '\n';
45 }
46 });
47 assert(all_of(Hints,
48 [&](MCPhysReg Hint) { return is_contained(Order, Hint); }) &&
49 "Target hint is outside allocation order.");
50 return AllocationOrder(std::move(Hints), Order, HardHints);
51}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Live Register Matrix
Register const TargetRegisterInfo * TRI
#define LLVM_DEBUG(...)
Definition Debug.h:114
static AllocationOrder create(Register VirtReg, const VirtRegMap &VRM, const RegisterClassInfo &RegClassInfo, const LiveRegMatrix *Matrix)
Create a new AllocationOrder for VirtReg.
AllocationOrder(SmallVector< MCPhysReg, 16 > &&Hints, ArrayRef< MCPhysReg > Order, bool HardHints)
Create an AllocationOrder given the Hints, Order, and HardHints values.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
ArrayRef< MCPhysReg > getOrder(const TargetRegisterClass *RC) const
getOrder - Returns the preferred allocation order for RC.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineFunction & getMachineFunction() const
Definition VirtRegMap.h:75
const TargetRegisterInfo & getTargetRegInfo() const
Definition VirtRegMap.h:81
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1707
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1879
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.