[Alignment][NFC] Remove dependency on GlobalObject::setAlignment(unsigned)
[llvm-core.git] / lib / CodeGen / AllocationOrder.cpp
blobc99800659bfd81aa881693fad4e86fa14b1138a6
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.
11 // The preferred allocation order for a virtual register depends on allocation
12 // hints and target hooks. The AllocationOrder class encapsulates all of that.
14 //===----------------------------------------------------------------------===//
16 #include "AllocationOrder.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/CodeGen/RegisterClassInfo.h"
20 #include "llvm/CodeGen/VirtRegMap.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/raw_ostream.h"
24 using namespace llvm;
26 #define DEBUG_TYPE "regalloc"
28 // Compare VirtRegMap::getRegAllocPref().
29 AllocationOrder::AllocationOrder(unsigned VirtReg,
30 const VirtRegMap &VRM,
31 const RegisterClassInfo &RegClassInfo,
32 const LiveRegMatrix *Matrix)
33 : Pos(0), HardHints(false) {
34 const MachineFunction &MF = VRM.getMachineFunction();
35 const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
36 Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
37 if (TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix))
38 HardHints = true;
39 rewind();
41 LLVM_DEBUG({
42 if (!Hints.empty()) {
43 dbgs() << "hints:";
44 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
45 dbgs() << ' ' << printReg(Hints[I], TRI);
46 dbgs() << '\n';
48 });
49 #ifndef NDEBUG
50 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
51 assert(is_contained(Order, Hints[I]) &&
52 "Target hint is outside allocation order.");
53 #endif