LLVM API Documentation

RegAllocBase.h
Go to the documentation of this file.
00001 //===-- RegAllocBase.h - basic regalloc interface and driver --*- C++ -*---===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the RegAllocBase class, which is the skeleton of a basic
00011 // register allocation algorithm and interface for extending it. It provides the
00012 // building blocks on which to construct other experimental allocators and test
00013 // the validity of two principles:
00014 //
00015 // - If virtual and physical register liveness is modeled using intervals, then
00016 // on-the-fly interference checking is cheap. Furthermore, interferences can be
00017 // lazily cached and reused.
00018 //
00019 // - Register allocation complexity, and generated code performance is
00020 // determined by the effectiveness of live range splitting rather than optimal
00021 // coloring.
00022 //
00023 // Following the first principle, interfering checking revolves around the
00024 // LiveIntervalUnion data structure.
00025 //
00026 // To fulfill the second principle, the basic allocator provides a driver for
00027 // incremental splitting. It essentially punts on the problem of register
00028 // coloring, instead driving the assignment of virtual to physical registers by
00029 // the cost of splitting. The basic allocator allows for heuristic reassignment
00030 // of registers, if a more sophisticated allocator chooses to do that.
00031 //
00032 // This framework provides a way to engineer the compile time vs. code
00033 // quality trade-off without relying on a particular theoretical solver.
00034 //
00035 //===----------------------------------------------------------------------===//
00036 
00037 #ifndef LLVM_LIB_CODEGEN_REGALLOCBASE_H
00038 #define LLVM_LIB_CODEGEN_REGALLOCBASE_H
00039 
00040 #include "llvm/CodeGen/LiveInterval.h"
00041 #include "llvm/CodeGen/RegisterClassInfo.h"
00042 
00043 namespace llvm {
00044 
00045 template<typename T> class SmallVectorImpl;
00046 class TargetRegisterInfo;
00047 class VirtRegMap;
00048 class LiveIntervals;
00049 class LiveRegMatrix;
00050 class Spiller;
00051 
00052 /// RegAllocBase provides the register allocation driver and interface that can
00053 /// be extended to add interesting heuristics.
00054 ///
00055 /// Register allocators must override the selectOrSplit() method to implement
00056 /// live range splitting. They must also override enqueue/dequeue to provide an
00057 /// assignment order.
00058 class RegAllocBase {
00059   virtual void anchor();
00060 protected:
00061   const TargetRegisterInfo *TRI;
00062   MachineRegisterInfo *MRI;
00063   VirtRegMap *VRM;
00064   LiveIntervals *LIS;
00065   LiveRegMatrix *Matrix;
00066   RegisterClassInfo RegClassInfo;
00067 
00068   RegAllocBase()
00069     : TRI(nullptr), MRI(nullptr), VRM(nullptr), LIS(nullptr), Matrix(nullptr) {}
00070 
00071   virtual ~RegAllocBase() {}
00072 
00073   // A RegAlloc pass should call this before allocatePhysRegs.
00074   void init(VirtRegMap &vrm, LiveIntervals &lis, LiveRegMatrix &mat);
00075 
00076   // The top-level driver. The output is a VirtRegMap that us updated with
00077   // physical register assignments.
00078   void allocatePhysRegs();
00079 
00080   // Get a temporary reference to a Spiller instance.
00081   virtual Spiller &spiller() = 0;
00082 
00083   /// enqueue - Add VirtReg to the priority queue of unassigned registers.
00084   virtual void enqueue(LiveInterval *LI) = 0;
00085 
00086   /// dequeue - Return the next unassigned register, or NULL.
00087   virtual LiveInterval *dequeue() = 0;
00088 
00089   // A RegAlloc pass should override this to provide the allocation heuristics.
00090   // Each call must guarantee forward progess by returning an available PhysReg
00091   // or new set of split live virtual registers. It is up to the splitter to
00092   // converge quickly toward fully spilled live ranges.
00093   virtual unsigned selectOrSplit(LiveInterval &VirtReg,
00094                                  SmallVectorImpl<unsigned> &splitLVRs) = 0;
00095 
00096   // Use this group name for NamedRegionTimer.
00097   static const char TimerGroupName[];
00098 
00099 public:
00100   /// VerifyEnabled - True when -verify-regalloc is given.
00101   static bool VerifyEnabled;
00102 
00103 private:
00104   void seedLiveRegs();
00105 };
00106 
00107 } // end namespace llvm
00108 
00109 #endif