Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 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" |
Jakob Stoklund Olesen | c784a1f | 2012-12-03 22:51:04 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFunction.h" |
Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Andrew Trick | 05ff466 | 2012-06-06 20:29:31 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/RegisterClassInfo.h" |
Jakob Stoklund Olesen | 26c9d70 | 2012-11-28 19:13:06 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/VirtRegMap.h" |
Jakob Stoklund Olesen | c784a1f | 2012-12-03 22:51:04 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Debug.h" |
| 22 | #include "llvm/Support/raw_ostream.h" |
Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
| 25 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 26 | #define DEBUG_TYPE "regalloc" |
| 27 | |
Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 28 | // Compare VirtRegMap::getRegAllocPref(). |
| 29 | AllocationOrder::AllocationOrder(unsigned VirtReg, |
| 30 | const VirtRegMap &VRM, |
Matthias Braun | 5d1f12d | 2015-07-15 22:16:00 +0000 | [diff] [blame] | 31 | const RegisterClassInfo &RegClassInfo, |
| 32 | const LiveRegMatrix *Matrix) |
Jonas Paulsson | 4b017e6 | 2017-11-10 08:46:26 +0000 | [diff] [blame] | 33 | : Pos(0), HardHints(false) { |
Jakob Stoklund Olesen | c784a1f | 2012-12-03 22:51:04 +0000 | [diff] [blame] | 34 | const MachineFunction &MF = VRM.getMachineFunction(); |
| 35 | const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo(); |
| 36 | Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg)); |
Jonas Paulsson | 4b017e6 | 2017-11-10 08:46:26 +0000 | [diff] [blame] | 37 | if (TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix)) |
| 38 | HardHints = true; |
Jakob Stoklund Olesen | 3cb2cb8 | 2012-12-04 22:25:16 +0000 | [diff] [blame] | 39 | rewind(); |
Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 40 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 41 | LLVM_DEBUG({ |
Jakob Stoklund Olesen | c784a1f | 2012-12-03 22:51:04 +0000 | [diff] [blame] | 42 | if (!Hints.empty()) { |
| 43 | dbgs() << "hints:"; |
| 44 | for (unsigned I = 0, E = Hints.size(); I != E; ++I) |
Francis Visoiu Mistrih | 9d419d3 | 2017-11-28 12:42:37 +0000 | [diff] [blame] | 45 | dbgs() << ' ' << printReg(Hints[I], TRI); |
Jakob Stoklund Olesen | c784a1f | 2012-12-03 22:51:04 +0000 | [diff] [blame] | 46 | dbgs() << '\n'; |
| 47 | } |
| 48 | }); |
Jakob Stoklund Olesen | 7e28db0 | 2013-02-19 18:41:01 +0000 | [diff] [blame] | 49 | #ifndef NDEBUG |
| 50 | for (unsigned I = 0, E = Hints.size(); I != E; ++I) |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 51 | assert(is_contained(Order, Hints[I]) && |
Jakob Stoklund Olesen | 7e28db0 | 2013-02-19 18:41:01 +0000 | [diff] [blame] | 52 | "Target hint is outside allocation order."); |
| 53 | #endif |
Jakob Stoklund Olesen | 0c67e01 | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 54 | } |