blob: c99800659bfd81aa881693fad4e86fa14b1138a6 [file] [log] [blame]
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +00001//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +00006//
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"
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000017#include "llvm/CodeGen/MachineFunction.h"
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000018#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick05ff4662012-06-06 20:29:31 +000019#include "llvm/CodeGen/RegisterClassInfo.h"
Jakob Stoklund Olesen26c9d702012-11-28 19:13:06 +000020#include "llvm/CodeGen/VirtRegMap.h"
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000021#include "llvm/Support/Debug.h"
22#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000023
24using namespace llvm;
25
Chandler Carruth1b9dde02014-04-22 02:02:50 +000026#define DEBUG_TYPE "regalloc"
27
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000028// Compare VirtRegMap::getRegAllocPref().
29AllocationOrder::AllocationOrder(unsigned VirtReg,
30 const VirtRegMap &VRM,
Matthias Braun5d1f12d2015-07-15 22:16:00 +000031 const RegisterClassInfo &RegClassInfo,
32 const LiveRegMatrix *Matrix)
Jonas Paulsson4b017e62017-11-10 08:46:26 +000033 : Pos(0), HardHints(false) {
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000034 const MachineFunction &MF = VRM.getMachineFunction();
35 const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
36 Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
Jonas Paulsson4b017e62017-11-10 08:46:26 +000037 if (TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix))
38 HardHints = true;
Jakob Stoklund Olesen3cb2cb82012-12-04 22:25:16 +000039 rewind();
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000040
Nicola Zaghend34e60c2018-05-14 12:53:11 +000041 LLVM_DEBUG({
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000042 if (!Hints.empty()) {
43 dbgs() << "hints:";
44 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +000045 dbgs() << ' ' << printReg(Hints[I], TRI);
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000046 dbgs() << '\n';
47 }
48 });
Jakob Stoklund Olesen7e28db02013-02-19 18:41:01 +000049#ifndef NDEBUG
50 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
David Majnemer0d955d02016-08-11 22:21:41 +000051 assert(is_contained(Order, Hints[I]) &&
Jakob Stoklund Olesen7e28db02013-02-19 18:41:01 +000052 "Target hint is outside allocation order.");
53#endif
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000054}