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" |
Jakob Stoklund Olesen | fc29db1 | 2012-12-03 22:51:04 +0000 | [diff] [blame^] | 21 | #include "llvm/ADT/ArrayRef.h" |
Jakob Stoklund Olesen | 39b5c0c | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 22 | |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | |
Jakob Stoklund Olesen | 5f2316a | 2011-06-03 20:34:53 +0000 | [diff] [blame] | 25 | class RegisterClassInfo; |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 26 | class VirtRegMap; |
| 27 | |
| 28 | class AllocationOrder { |
Jakob Stoklund Olesen | fc29db1 | 2012-12-03 22:51:04 +0000 | [diff] [blame^] | 29 | SmallVector<MCPhysReg, 16> Hints; |
| 30 | ArrayRef<MCPhysReg> Order; |
| 31 | unsigned Pos; |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 32 | |
Jakob Stoklund Olesen | fc29db1 | 2012-12-03 22:51:04 +0000 | [diff] [blame^] | 33 | public: |
| 34 | /// Create a new AllocationOrder for VirtReg. |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 35 | /// @param VirtReg Virtual register to allocate for. |
| 36 | /// @param VRM Virtual register map for function. |
Jakob Stoklund Olesen | 10c6fdc | 2012-01-24 18:09:18 +0000 | [diff] [blame] | 37 | /// @param RegClassInfo Information about reserved and allocatable registers. |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 38 | AllocationOrder(unsigned VirtReg, |
| 39 | const VirtRegMap &VRM, |
Jakob Stoklund Olesen | 5f2316a | 2011-06-03 20:34:53 +0000 | [diff] [blame] | 40 | const RegisterClassInfo &RegClassInfo); |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 41 | |
Jakob Stoklund Olesen | fc29db1 | 2012-12-03 22:51:04 +0000 | [diff] [blame^] | 42 | /// Return the next physical register in the allocation order, or 0. |
| 43 | /// It is safe to call next() again after it returned 0, it will keep |
| 44 | /// returning 0 until rewind() is called. |
| 45 | unsigned next(); |
Jakob Stoklund Olesen | a46a100 | 2011-06-06 21:02:04 +0000 | [diff] [blame] | 46 | |
Jakob Stoklund Olesen | fc29db1 | 2012-12-03 22:51:04 +0000 | [diff] [blame^] | 47 | /// Start over from the beginning. |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 48 | void rewind() { Pos = 0; } |
| 49 | |
Jakob Stoklund Olesen | fc29db1 | 2012-12-03 22:51:04 +0000 | [diff] [blame^] | 50 | /// Return true if the last register returned from next() was a preferred register. |
| 51 | bool isHint() const { return Pos <= Hints.size(); } |
| 52 | |
| 53 | /// Return true if PhysReg is a preferred register. |
| 54 | bool isHint(unsigned PhysReg) const; |
Jakob Stoklund Olesen | c9672cb | 2010-12-10 18:36:02 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // end namespace llvm |
| 58 | |
| 59 | #endif |