blob: 37dcb0be824e87b8dceaaa6bff2d1ffdc2982e5f [file] [log] [blame]
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +00001//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements an allocation order for virtual registers.
11//
12// The preferred allocation order for a virtual register depends on allocation
13// hints and target hooks. The AllocationOrder class encapsulates all of that.
14//
15//===----------------------------------------------------------------------===//
16
17#include "AllocationOrder.h"
Jakob Stoklund Olesenfc29db12012-12-03 22:51:04 +000018#include "llvm/CodeGen/MachineFunction.h"
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick15252602012-06-06 20:29:31 +000020#include "llvm/CodeGen/RegisterClassInfo.h"
Jakob Stoklund Olesen1ead68d2012-11-28 19:13:06 +000021#include "llvm/CodeGen/VirtRegMap.h"
Jakob Stoklund Olesenfc29db12012-12-03 22:51:04 +000022#include "llvm/Support/Debug.h"
23#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000024
25using namespace llvm;
26
Chandler Carruth8677f2f2014-04-22 02:02:50 +000027#define DEBUG_TYPE "regalloc"
28
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000029// Compare VirtRegMap::getRegAllocPref().
30AllocationOrder::AllocationOrder(unsigned VirtReg,
31 const VirtRegMap &VRM,
Matthias Braun2aa57272015-07-15 22:16:00 +000032 const RegisterClassInfo &RegClassInfo,
33 const LiveRegMatrix *Matrix)
Jonas Paulssona9fba712017-11-10 08:46:26 +000034 : Pos(0), HardHints(false) {
Jakob Stoklund Olesenfc29db12012-12-03 22:51:04 +000035 const MachineFunction &MF = VRM.getMachineFunction();
36 const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
37 Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
Jonas Paulssona9fba712017-11-10 08:46:26 +000038 if (TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix))
39 HardHints = true;
Jakob Stoklund Olesenf7999fe2012-12-04 22:25:16 +000040 rewind();
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000041
Nicola Zaghen0818e782018-05-14 12:53:11 +000042 LLVM_DEBUG({
Jakob Stoklund Olesenfc29db12012-12-03 22:51:04 +000043 if (!Hints.empty()) {
44 dbgs() << "hints:";
45 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
Francis Visoiu Mistrihaccb3372017-11-28 12:42:37 +000046 dbgs() << ' ' << printReg(Hints[I], TRI);
Jakob Stoklund Olesenfc29db12012-12-03 22:51:04 +000047 dbgs() << '\n';
48 }
49 });
Jakob Stoklund Olesenda5f1ed2013-02-19 18:41:01 +000050#ifndef NDEBUG
51 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
David Majnemer975248e2016-08-11 22:21:41 +000052 assert(is_contained(Order, Hints[I]) &&
Jakob Stoklund Olesenda5f1ed2013-02-19 18:41:01 +000053 "Target hint is outside allocation order.");
54#endif
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000055}