blob: 40451c0d6c19dcaf8230b63ad714554f8e3c33bd [file] [log] [blame]
Jakob Stoklund Olesen0c67e012010-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 Olesenc784a1f2012-12-03 22:51:04 +000018#include "llvm/CodeGen/MachineFunction.h"
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick05ff4662012-06-06 20:29:31 +000020#include "llvm/CodeGen/RegisterClassInfo.h"
Jakob Stoklund Olesen26c9d702012-11-28 19:13:06 +000021#include "llvm/CodeGen/VirtRegMap.h"
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000022#include "llvm/Support/Debug.h"
23#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000024
25using namespace llvm;
26
Chandler Carruth1b9dde02014-04-22 02:02:50 +000027#define DEBUG_TYPE "regalloc"
28
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000029// Compare VirtRegMap::getRegAllocPref().
30AllocationOrder::AllocationOrder(unsigned VirtReg,
31 const VirtRegMap &VRM,
Matthias Braun5d1f12d2015-07-15 22:16:00 +000032 const RegisterClassInfo &RegClassInfo,
33 const LiveRegMatrix *Matrix)
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000034 : Pos(0) {
35 const MachineFunction &MF = VRM.getMachineFunction();
36 const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
37 Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
Matthias Braun5d1f12d2015-07-15 22:16:00 +000038 TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix);
Jakob Stoklund Olesen3cb2cb82012-12-04 22:25:16 +000039 rewind();
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000040
Jakob Stoklund Olesenc784a1f2012-12-03 22:51:04 +000041 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';
47 }
48 });
Jakob Stoklund Olesen7e28db02013-02-19 18:41:01 +000049#ifndef NDEBUG
50 for (unsigned I = 0, E = Hints.size(); I != E; ++I)
51 assert(std::find(Order.begin(), Order.end(), Hints[I]) != Order.end() &&
52 "Target hint is outside allocation order.");
53#endif
Jakob Stoklund Olesen0c67e012010-12-10 18:36:02 +000054}