Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/AllocationOrder.h - Allocation Order -*- C++ -*-------===// |
| 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 | #ifndef LLVM_CODEGEN_ALLOCATIONORDER_H |
| 18 | #define LLVM_CODEGEN_ALLOCATIONORDER_H |
| 19 | |
Jakob Stoklund Olesen | 39b5c0c | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCRegisterInfo.h" |
| 21 | |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 22 | namespace llvm { |
| 23 | |
Jakob Stoklund Olesen | 5f2316a | 2011-06-03 20:34:53 +0000 | [diff] [blame] | 24 | class RegisterClassInfo; |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 25 | class VirtRegMap; |
| 26 | |
| 27 | class AllocationOrder { |
Jakob Stoklund Olesen | 39b5c0c | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 28 | const MCPhysReg *Begin; |
| 29 | const MCPhysReg *End; |
| 30 | const MCPhysReg *Pos; |
Jakob Stoklund Olesen | 5f2316a | 2011-06-03 20:34:53 +0000 | [diff] [blame] | 31 | const RegisterClassInfo &RCI; |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 32 | unsigned Hint; |
Jakob Stoklund Olesen | a46a100 | 2011-06-06 21:02:04 +0000 | [diff] [blame] | 33 | bool OwnedBegin; |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 34 | public: |
| 35 | |
| 36 | /// AllocationOrder - Create a new AllocationOrder for VirtReg. |
| 37 | /// @param VirtReg Virtual register to allocate for. |
| 38 | /// @param VRM Virtual register map for function. |
Jakob Stoklund Olesen | 10c6fdc | 2012-01-24 18:09:18 +0000 | [diff] [blame] | 39 | /// @param RegClassInfo Information about reserved and allocatable registers. |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 40 | AllocationOrder(unsigned VirtReg, |
| 41 | const VirtRegMap &VRM, |
Jakob Stoklund Olesen | 5f2316a | 2011-06-03 20:34:53 +0000 | [diff] [blame] | 42 | const RegisterClassInfo &RegClassInfo); |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 43 | |
Jakob Stoklund Olesen | a46a100 | 2011-06-06 21:02:04 +0000 | [diff] [blame] | 44 | ~AllocationOrder(); |
| 45 | |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 46 | /// next - Return the next physical register in the allocation order, or 0. |
| 47 | /// It is safe to call next again after it returned 0. |
| 48 | /// It will keep returning 0 until rewind() is called. |
Jakob Stoklund Olesen | a46a100 | 2011-06-06 21:02:04 +0000 | [diff] [blame] | 49 | unsigned next() { |
| 50 | // First take the hint. |
| 51 | if (!Pos) { |
| 52 | Pos = Begin; |
| 53 | if (Hint) |
| 54 | return Hint; |
| 55 | } |
| 56 | // Then look at the order from TRI. |
| 57 | while (Pos != End) { |
| 58 | unsigned Reg = *Pos++; |
| 59 | if (Reg != Hint) |
| 60 | return Reg; |
| 61 | } |
| 62 | return 0; |
| 63 | } |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 64 | |
| 65 | /// rewind - Start over from the beginning. |
| 66 | void rewind() { Pos = 0; } |
| 67 | |
Jakob Stoklund Olesen | 57f1e2c | 2011-02-25 01:04:22 +0000 | [diff] [blame] | 68 | /// isHint - Return true if PhysReg is a preferred register. |
| 69 | bool isHint(unsigned PhysReg) const { return PhysReg == Hint; } |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // end namespace llvm |
| 73 | |
| 74 | #endif |