2010-10-22 23:09:15 +00:00
|
|
|
//===-- RegAllocBase.h - basic regalloc interface and driver --*- C++ -*---===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the RegAllocBase class, which is the skeleton of a basic
|
|
|
|
// register allocation algorithm and interface for extending it. It provides the
|
|
|
|
// building blocks on which to construct other experimental allocators and test
|
|
|
|
// the validity of two principles:
|
2010-11-30 23:18:47 +00:00
|
|
|
//
|
2010-10-22 23:09:15 +00:00
|
|
|
// - If virtual and physical register liveness is modeled using intervals, then
|
|
|
|
// on-the-fly interference checking is cheap. Furthermore, interferences can be
|
|
|
|
// lazily cached and reused.
|
2010-11-30 23:18:47 +00:00
|
|
|
//
|
2010-10-22 23:09:15 +00:00
|
|
|
// - Register allocation complexity, and generated code performance is
|
|
|
|
// determined by the effectiveness of live range splitting rather than optimal
|
|
|
|
// coloring.
|
|
|
|
//
|
|
|
|
// Following the first principle, interfering checking revolves around the
|
|
|
|
// LiveIntervalUnion data structure.
|
|
|
|
//
|
|
|
|
// To fulfill the second principle, the basic allocator provides a driver for
|
|
|
|
// incremental splitting. It essentially punts on the problem of register
|
|
|
|
// coloring, instead driving the assignment of virtual to physical registers by
|
|
|
|
// the cost of splitting. The basic allocator allows for heuristic reassignment
|
|
|
|
// of registers, if a more sophisticated allocator chooses to do that.
|
|
|
|
//
|
|
|
|
// This framework provides a way to engineer the compile time vs. code
|
2010-12-29 04:42:39 +00:00
|
|
|
// quality trade-off without relying on a particular theoretical solver.
|
2010-10-22 23:09:15 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_REGALLOCBASE_H
|
|
|
|
#define LLVM_LIB_CODEGEN_REGALLOCBASE_H
|
2010-10-22 23:09:15 +00:00
|
|
|
|
2013-08-14 17:28:42 +00:00
|
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2010-10-22 23:09:15 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2010-10-26 18:34:01 +00:00
|
|
|
template<typename T> class SmallVectorImpl;
|
|
|
|
class TargetRegisterInfo;
|
2010-10-22 23:09:15 +00:00
|
|
|
class VirtRegMap;
|
2010-10-26 18:34:01 +00:00
|
|
|
class LiveIntervals;
|
2012-06-20 22:52:24 +00:00
|
|
|
class LiveRegMatrix;
|
2010-11-10 19:18:47 +00:00
|
|
|
class Spiller;
|
2010-10-26 18:34:01 +00:00
|
|
|
|
2010-10-22 23:09:15 +00:00
|
|
|
/// RegAllocBase provides the register allocation driver and interface that can
|
|
|
|
/// be extended to add interesting heuristics.
|
|
|
|
///
|
2010-11-30 23:18:47 +00:00
|
|
|
/// Register allocators must override the selectOrSplit() method to implement
|
2011-02-22 23:01:52 +00:00
|
|
|
/// live range splitting. They must also override enqueue/dequeue to provide an
|
|
|
|
/// assignment order.
|
2013-09-11 18:05:11 +00:00
|
|
|
class RegAllocBase {
|
2013-11-19 00:57:56 +00:00
|
|
|
virtual void anchor();
|
2012-01-11 23:19:08 +00:00
|
|
|
protected:
|
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
MachineRegisterInfo *MRI;
|
|
|
|
VirtRegMap *VRM;
|
|
|
|
LiveIntervals *LIS;
|
2012-06-20 22:52:24 +00:00
|
|
|
LiveRegMatrix *Matrix;
|
2012-01-11 23:19:08 +00:00
|
|
|
RegisterClassInfo RegClassInfo;
|
|
|
|
|
2014-04-16 04:21:27 +00:00
|
|
|
RegAllocBase()
|
|
|
|
: TRI(nullptr), MRI(nullptr), VRM(nullptr), LIS(nullptr), Matrix(nullptr) {}
|
2010-10-22 23:09:15 +00:00
|
|
|
|
2010-10-22 23:33:19 +00:00
|
|
|
virtual ~RegAllocBase() {}
|
|
|
|
|
2010-10-22 23:09:15 +00:00
|
|
|
// A RegAlloc pass should call this before allocatePhysRegs.
|
2012-06-20 22:52:29 +00:00
|
|
|
void init(VirtRegMap &vrm, LiveIntervals &lis, LiveRegMatrix &mat);
|
2011-05-10 17:37:41 +00:00
|
|
|
|
2010-10-26 18:34:01 +00:00
|
|
|
// The top-level driver. The output is a VirtRegMap that us updated with
|
|
|
|
// physical register assignments.
|
|
|
|
void allocatePhysRegs();
|
2010-10-22 23:09:15 +00:00
|
|
|
|
2010-11-10 19:18:47 +00:00
|
|
|
// Get a temporary reference to a Spiller instance.
|
|
|
|
virtual Spiller &spiller() = 0;
|
2010-11-30 23:18:47 +00:00
|
|
|
|
2011-02-22 23:01:52 +00:00
|
|
|
/// enqueue - Add VirtReg to the priority queue of unassigned registers.
|
|
|
|
virtual void enqueue(LiveInterval *LI) = 0;
|
|
|
|
|
|
|
|
/// dequeue - Return the next unassigned register, or NULL.
|
|
|
|
virtual LiveInterval *dequeue() = 0;
|
2010-12-08 22:22:41 +00:00
|
|
|
|
2010-10-22 23:09:15 +00:00
|
|
|
// A RegAlloc pass should override this to provide the allocation heuristics.
|
2010-10-26 18:34:01 +00:00
|
|
|
// Each call must guarantee forward progess by returning an available PhysReg
|
|
|
|
// or new set of split live virtual registers. It is up to the splitter to
|
2010-10-22 23:09:15 +00:00
|
|
|
// converge quickly toward fully spilled live ranges.
|
2010-11-30 23:18:47 +00:00
|
|
|
virtual unsigned selectOrSplit(LiveInterval &VirtReg,
|
2013-08-14 23:50:04 +00:00
|
|
|
SmallVectorImpl<unsigned> &splitLVRs) = 0;
|
2010-10-22 23:09:15 +00:00
|
|
|
|
2010-12-11 00:19:56 +00:00
|
|
|
// Use this group name for NamedRegionTimer.
|
2013-07-17 03:11:32 +00:00
|
|
|
static const char TimerGroupName[];
|
2010-12-11 00:19:56 +00:00
|
|
|
|
2010-12-17 23:16:35 +00:00
|
|
|
public:
|
|
|
|
/// VerifyEnabled - True when -verify-regalloc is given.
|
|
|
|
static bool VerifyEnabled;
|
|
|
|
|
2010-10-22 23:09:15 +00:00
|
|
|
private:
|
2011-02-22 23:01:52 +00:00
|
|
|
void seedLiveRegs();
|
2010-10-22 23:09:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#endif
|