Add a function for profiling to run at shutdown. Unlike the existing API, this
[llvm/stm8.git] / lib / CodeGen / AllocationOrder.cpp
blob20c7625f3253577c41c3f4541cacf125d97c735c
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.
12 // The preferred allocation order for a virtual register depends on allocation
13 // hints and target hooks. The AllocationOrder class encapsulates all of that.
15 //===----------------------------------------------------------------------===//
17 #include "AllocationOrder.h"
18 #include "VirtRegMap.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
21 using namespace llvm;
23 // Compare VirtRegMap::getRegAllocPref().
24 AllocationOrder::AllocationOrder(unsigned VirtReg,
25 const VirtRegMap &VRM,
26 const BitVector &ReservedRegs)
27 : Pos(0), Reserved(ReservedRegs) {
28 const TargetRegisterClass *RC = VRM.getRegInfo().getRegClass(VirtReg);
29 std::pair<unsigned, unsigned> HintPair =
30 VRM.getRegInfo().getRegAllocationHint(VirtReg);
32 // HintPair.second is a register, phys or virt.
33 Hint = HintPair.second;
35 // Translate to physreg, or 0 if not assigned yet.
36 if (TargetRegisterInfo::isVirtualRegister(Hint))
37 Hint = VRM.getPhys(Hint);
39 // The remaining allocation order may depend on the hint.
40 tie(Begin, End) = VRM.getTargetRegInfo()
41 .getAllocationOrder(RC, HintPair.first, Hint, VRM.getMachineFunction());
43 // Target-dependent hints require resolution.
44 if (HintPair.first)
45 Hint = VRM.getTargetRegInfo().ResolveRegAllocHint(HintPair.first, Hint,
46 VRM.getMachineFunction());
48 // The hint must be a valid physreg for allocation.
49 if (Hint && (!TargetRegisterInfo::isPhysicalRegister(Hint) ||
50 !RC->contains(Hint) || ReservedRegs.test(Hint)))
51 Hint = 0;
54 unsigned AllocationOrder::next() {
55 // First take the hint.
56 if (!Pos) {
57 Pos = Begin;
58 if (Hint)
59 return Hint;
61 // Then look at the order from TRI.
62 while(Pos != End) {
63 unsigned Reg = *Pos++;
64 if (Reg != Hint && !Reserved.test(Reg))
65 return Reg;
67 return 0;