Home | History | Annotate | Download | only in CodeGen
      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 
     20 namespace llvm {
     21 
     22 class RegisterClassInfo;
     23 class VirtRegMap;
     24 
     25 class AllocationOrder {
     26   const unsigned *Begin;
     27   const unsigned *End;
     28   const unsigned *Pos;
     29   const RegisterClassInfo &RCI;
     30   unsigned Hint;
     31   bool OwnedBegin;
     32 public:
     33 
     34   /// AllocationOrder - Create a new AllocationOrder for VirtReg.
     35   /// @param VirtReg      Virtual register to allocate for.
     36   /// @param VRM          Virtual register map for function.
     37   /// @param ReservedRegs Set of reserved registers as returned by
     38   ///        TargetRegisterInfo::getReservedRegs().
     39   AllocationOrder(unsigned VirtReg,
     40                   const VirtRegMap &VRM,
     41                   const RegisterClassInfo &RegClassInfo);
     42 
     43   ~AllocationOrder();
     44 
     45   /// next - Return the next physical register in the allocation order, or 0.
     46   /// It is safe to call next again after it returned 0.
     47   /// It will keep returning 0 until rewind() is called.
     48   unsigned next() {
     49     // First take the hint.
     50     if (!Pos) {
     51       Pos = Begin;
     52       if (Hint)
     53         return Hint;
     54     }
     55     // Then look at the order from TRI.
     56     while (Pos != End) {
     57       unsigned Reg = *Pos++;
     58       if (Reg != Hint)
     59         return Reg;
     60     }
     61     return 0;
     62   }
     63 
     64   /// rewind - Start over from the beginning.
     65   void rewind() { Pos = 0; }
     66 
     67   /// isHint - Return true if PhysReg is a preferred register.
     68   bool isHint(unsigned PhysReg) const { return PhysReg == Hint; }
     69 };
     70 
     71 } // end namespace llvm
     72 
     73 #endif
     74