1*9880d681SAndroid Build Coastguard Worker //===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file implements an allocation order for virtual registers.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker // The preferred allocation order for a virtual register depends on allocation
13*9880d681SAndroid Build Coastguard Worker // hints and target hooks. The AllocationOrder class encapsulates all of that.
14*9880d681SAndroid Build Coastguard Worker //
15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker #include "AllocationOrder.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunction.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineRegisterInfo.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/RegisterClassInfo.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/VirtRegMap.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker using namespace llvm;
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "regalloc"
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker // Compare VirtRegMap::getRegAllocPref().
AllocationOrder(unsigned VirtReg,const VirtRegMap & VRM,const RegisterClassInfo & RegClassInfo,const LiveRegMatrix * Matrix)30*9880d681SAndroid Build Coastguard Worker AllocationOrder::AllocationOrder(unsigned VirtReg,
31*9880d681SAndroid Build Coastguard Worker const VirtRegMap &VRM,
32*9880d681SAndroid Build Coastguard Worker const RegisterClassInfo &RegClassInfo,
33*9880d681SAndroid Build Coastguard Worker const LiveRegMatrix *Matrix)
34*9880d681SAndroid Build Coastguard Worker : Pos(0) {
35*9880d681SAndroid Build Coastguard Worker const MachineFunction &MF = VRM.getMachineFunction();
36*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
37*9880d681SAndroid Build Coastguard Worker Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
38*9880d681SAndroid Build Coastguard Worker TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix);
39*9880d681SAndroid Build Coastguard Worker rewind();
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker DEBUG({
42*9880d681SAndroid Build Coastguard Worker if (!Hints.empty()) {
43*9880d681SAndroid Build Coastguard Worker dbgs() << "hints:";
44*9880d681SAndroid Build Coastguard Worker for (unsigned I = 0, E = Hints.size(); I != E; ++I)
45*9880d681SAndroid Build Coastguard Worker dbgs() << ' ' << PrintReg(Hints[I], TRI);
46*9880d681SAndroid Build Coastguard Worker dbgs() << '\n';
47*9880d681SAndroid Build Coastguard Worker }
48*9880d681SAndroid Build Coastguard Worker });
49*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
50*9880d681SAndroid Build Coastguard Worker for (unsigned I = 0, E = Hints.size(); I != E; ++I)
51*9880d681SAndroid Build Coastguard Worker assert(std::find(Order.begin(), Order.end(), Hints[I]) != Order.end() &&
52*9880d681SAndroid Build Coastguard Worker "Target hint is outside allocation order.");
53*9880d681SAndroid Build Coastguard Worker #endif
54*9880d681SAndroid Build Coastguard Worker }
55