CIRCT 23.0.0git
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
LinearScanRegisterAllocationPass.cpp File Reference
#include "circt/Dialect/RTG/IR/RTGAttributes.h"
#include "circt/Dialect/RTG/IR/RTGISAAssemblyOpInterfaces.h"
#include "circt/Dialect/RTG/IR/RTGOps.h"
#include "circt/Dialect/RTG/Transforms/RTGPasses.h"
#include "circt/Support/UnusedOpPruner.h"
#include "llvm/Support/Debug.h"
#include <variant>
#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc"
Include dependency graph for LinearScanRegisterAllocationPass.cpp:

Go to the source code of this file.

Namespaces

namespace  circt
 The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
 
namespace  circt::rtg
 

Macros

#define GEN_PASS_DEF_LINEARSCANREGISTERALLOCATIONPASS
 
#define DEBUG_TYPE   "rtg-linear-scan-register-allocation"
 

Functions

static LogicalResult foldAndEnqueueResults (Operation *user, Value current, Attribute currentAttr, SmallVectorImpl< std::pair< Value, Attribute > > &worklist, DenseMap< Value, Attribute > &visited)
 Folds an operation and adds its results to the worklist.
 
static RegisterAllocationResult collectTransitiveRegisterAllocationOperands (Value value, rtg::RegisterAttrInterface reg, SetVector< std::pair< Value, rtg::RegisterAttrInterface > > &operands)
 
static void expireOldInterval (SmallVector< FixedLiveRange > &active, const VirtualLiveRange &liveRange)
 
static bool updateLiveRangeFromUsers (const LiveRangeCache &cache, Value value, LiveRange &liveRange)
 Updates the live range based on users of a value.
 
static VirtualLiveRange * createRange (LiveRangeCache &cache, rtg::VirtualRegisterOp op)
 Creates a live range for a virtual register operation.
 
static LogicalResult computeLiveRanges (LiveRangeCache &cache, Region &region)
 Computes live ranges for all virtual registers and identifies reserved (fixed) registers.
 
static RegisterAllocationResult isRegisterAvailable (const LiveRangeCache &cache, ArrayRef< FixedLiveRange > active, rtg::VirtualRegisterOp virtualReg, rtg::RegisterAttrInterface reg, DenseMap< Value, rtg::RegisterAttrInterface > &dependentRegValues)
 Checks if a specific register is available for allocation to a virtual register.
 
static rtg::RegisterAttrInterface findAvailableRegister (const LiveRangeCache &cache, ArrayRef< FixedLiveRange > active, VirtualLiveRange &liveRange, DenseMap< Value, rtg::RegisterAttrInterface > &dependentRegValues)
 Finds an available register for the given virtual register from its allowed register set.
 
static void materializeAllocation (const LiveRangeCache &cache, const DenseMap< rtg::VirtualRegisterOp, rtg::RegisterAttrInterface > &assignedRegisters)
 Replaces all virtual register operations with their allocated fixed registers and removes unused operations.
 
static LogicalResult allocateVirtualRegistersInCache (LiveRangeCache &cache)
 Performs the main register allocation using linear scan algorithm.
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "rtg-linear-scan-register-allocation"

Definition at line 32 of file LinearScanRegisterAllocationPass.cpp.

◆ GEN_PASS_DEF_LINEARSCANREGISTERALLOCATIONPASS

#define GEN_PASS_DEF_LINEARSCANREGISTERALLOCATIONPASS

Definition at line 24 of file LinearScanRegisterAllocationPass.cpp.

Function Documentation

◆ allocateVirtualRegistersInCache()

static LogicalResult allocateVirtualRegistersInCache ( LiveRangeCache &  cache)
static

Performs the main register allocation using linear scan algorithm.

Processes live ranges in order, expires old intervals, and assigns registers to virtual registers.

Definition at line 535 of file LinearScanRegisterAllocationPass.cpp.

References expireOldInterval(), findAvailableRegister(), and materializeAllocation().

◆ collectTransitiveRegisterAllocationOperands()

static RegisterAllocationResult collectTransitiveRegisterAllocationOperands ( Value  value,
rtg::RegisterAttrInterface  reg,
SetVector< std::pair< Value, rtg::RegisterAttrInterface > > &  operands 
)
static

Definition at line 220 of file LinearScanRegisterAllocationPass.cpp.

References foldAndEnqueueResults().

Referenced by createRange(), and isRegisterAvailable().

◆ computeLiveRanges()

static LogicalResult computeLiveRanges ( LiveRangeCache &  cache,
Region &  region 
)
static

Computes live ranges for all virtual registers and identifies reserved (fixed) registers.

Definition at line 373 of file LinearScanRegisterAllocationPass.cpp.

References createRange().

◆ createRange()

static VirtualLiveRange * createRange ( LiveRangeCache &  cache,
rtg::VirtualRegisterOp  op 
)
static

Creates a live range for a virtual register operation.

Returns nullptr if the virtual register has no users that implement RegisterAllocationOpInterface.

Definition at line 335 of file LinearScanRegisterAllocationPass.cpp.

References collectTransitiveRegisterAllocationOperands(), and updateLiveRangeFromUsers().

Referenced by computeLiveRanges().

◆ expireOldInterval()

static void expireOldInterval ( SmallVector< FixedLiveRange > &  active,
const VirtualLiveRange &  liveRange 
)
static

◆ findAvailableRegister()

static rtg::RegisterAttrInterface findAvailableRegister ( const LiveRangeCache &  cache,
ArrayRef< FixedLiveRange >  active,
VirtualLiveRange &  liveRange,
DenseMap< Value, rtg::RegisterAttrInterface > &  dependentRegValues 
)
static

Finds an available register for the given virtual register from its allowed register set.

Returns an empty RegisterAttrInterface on failure.

Definition at line 451 of file LinearScanRegisterAllocationPass.cpp.

References isRegisterAvailable().

Referenced by allocateVirtualRegistersInCache().

◆ foldAndEnqueueResults()

static LogicalResult foldAndEnqueueResults ( Operation *  user,
Value  current,
Attribute  currentAttr,
SmallVectorImpl< std::pair< Value, Attribute > > &  worklist,
DenseMap< Value, Attribute > &  visited 
)
static

Folds an operation and adds its results to the worklist.

Returns Available on success, or an error status on failure.

Definition at line 173 of file LinearScanRegisterAllocationPass.cpp.

Referenced by collectTransitiveRegisterAllocationOperands().

◆ isRegisterAvailable()

static RegisterAllocationResult isRegisterAvailable ( const LiveRangeCache &  cache,
ArrayRef< FixedLiveRange >  active,
rtg::VirtualRegisterOp  virtualReg,
rtg::RegisterAttrInterface  reg,
DenseMap< Value, rtg::RegisterAttrInterface > &  dependentRegValues 
)
static

Checks if a specific register is available for allocation to a virtual register.

Verifies the register is not reserved, not in use by active ranges, and satisfies all constraints.

Definition at line 418 of file LinearScanRegisterAllocationPass.cpp.

References collectTransitiveRegisterAllocationOperands().

Referenced by findAvailableRegister().

◆ materializeAllocation()

static void materializeAllocation ( const LiveRangeCache &  cache,
const DenseMap< rtg::VirtualRegisterOp, rtg::RegisterAttrInterface > &  assignedRegisters 
)
static

Replaces all virtual register operations with their allocated fixed registers and removes unused operations.

Definition at line 503 of file LinearScanRegisterAllocationPass.cpp.

References circt::UnusedOpPruner::eraseNow().

Referenced by allocateVirtualRegistersInCache().

◆ updateLiveRangeFromUsers()

static bool updateLiveRangeFromUsers ( const LiveRangeCache &  cache,
Value  value,
LiveRange &  liveRange 
)
static

Updates the live range based on users of a value.

Returns true if any RegisterAllocationOpInterface users were found.

Definition at line 314 of file LinearScanRegisterAllocationPass.cpp.

Referenced by createRange().