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