CIRCT 24.0.0git
Loading...
Searching...
No Matches
circt::FirRegLowering Class Reference

Lower FirRegOp to sv.reg and sv.always. More...

#include <FirRegLowering.h>

Collaboration diagram for circt::FirRegLowering:

Classes

struct  RegCondition
 The conditions under which a register is defined. More...
struct  RegLowerInfo

Public Types

using PathTable = DenseMap<seq::FirRegOp, hw::HierPathOp>
 A map sending registers to their paths.

Public Member Functions

 FirRegLowering (TypeConverter &typeConverter, hw::HWModuleOp module, const PathTable &pathTable, bool disableRegRandomization=false, bool emitSeparateAlwaysBlocks=false, bool emitPresetAsInlineInit=true)
void lower ()
bool needsRegRandomization () const

Static Public Member Functions

static PathTable createPaths (mlir::ModuleOp top)
 When a register is buried under an ifdef op, the initialization code at the footer of the HW module will refer to the register using a hierarchical path op.

Public Attributes

unsigned numSubaccessRestored = 0

Private Types

using AlwaysKeyType
using IfKeyType = std::pair<Block *, Value>

Private Member Functions

void lowerUnderIfDef (sv::IfDefOp ifDefOp)
void lowerInBlock (Block *block)
void lowerReg (seq::FirRegOp reg)
void createInitialBlock ()
void initialize (OpBuilder &builder, RegLowerInfo reg, ArrayRef< Value > rands)
void initializeRegisterElements (Location loc, OpBuilder &builder, Value reg, Value rand, unsigned &pos)
void createTree (OpBuilder &builder, Value reg, Value term, Value next)
std::optional< std::tuple< Value, Value, Value > > tryRestoringSubaccess (OpBuilder &builder, Value reg, Value term, hw::ArrayCreateOp nextRegValue)
void addToAlwaysBlock (Block *block, sv::EventControl clockEdge, Value clock, const std::function< void(OpBuilder &)> &body, sv::ResetType resetStyle={}, sv::EventControl resetEdge={}, Value reset={}, const std::function< void(OpBuilder &)> &resetBody={})
void addToIfBlock (OpBuilder &builder, Value cond, const std::function< void()> &trueSide, const std::function< void()> &falseSide)
SmallVector< Value > createRandomizationVector (OpBuilder &builder, Location loc)
void createRandomInitialization (ImplicitLocOpBuilder &builder)
void createPresetInitialization (ImplicitLocOpBuilder &builder)
void createAsyncResetInitialization (ImplicitLocOpBuilder &builder)
hw::ConstantOp getOrCreateConstant (Location loc, const APInt &value)
void buildRegConditions (OpBuilder &b, sv::VarOp reg)
 Recreate the ifdefs under which reg was defined.

Private Attributes

llvm::SmallDenseMap< AlwaysKeyType, std::pair< sv::AlwaysOp, sv::IfOp > > alwaysBlocks
llvm::SmallDenseMap< IfKeyType, sv::IfOp > ifCache
llvm::SmallDenseMap< APInt, hw::ConstantOp > constantCache
llvm::SmallDenseMap< std::pair< Value, unsigned >, Value > arrayIndexCache
std::vector< RegCondition > conditions
 The ambient ifdef conditions we have encountered while lowering.
SmallVector< RegLowerInfo > randomInitRegs
 A list of registers discovered, bucketed by initialization style.
SmallVector< RegLowerInfo > presetInitRegs
DenseMap< sv::VarOp, std::vector< RegCondition > > regConditionTable
 A map from RegOps to the ifdef conditions under which they are defined.
llvm::MapVector< Value, SmallVector< RegLowerInfo > > asyncResets
 A map from async reset signal to the registers that use it.
std::unique_ptr< ReachableMuxes > reachableMuxes
const PathTable & pathTable
TypeConverter & typeConverter
hw::HWModuleOp module
bool disableRegRandomization
bool emitSeparateAlwaysBlocks
bool emitPresetAsInlineInit
bool needsRandom = false

Detailed Description

Lower FirRegOp to sv.reg and sv.always.

Definition at line 78 of file FirRegLowering.h.

Member Typedef Documentation

◆ AlwaysKeyType

Initial value:
std::tuple<Block *, sv::EventControl, Value,
sv::ResetType, sv::EventControl, Value>

Definition at line 176 of file FirRegLowering.h.

◆ IfKeyType

using circt::FirRegLowering::IfKeyType = std::pair<Block *, Value>
private

Definition at line 181 of file FirRegLowering.h.

◆ PathTable

using circt::FirRegLowering::PathTable = DenseMap<seq::FirRegOp, hw::HierPathOp>

A map sending registers to their paths.

Definition at line 81 of file FirRegLowering.h.

Constructor & Destructor Documentation

◆ FirRegLowering()

FirRegLowering::FirRegLowering ( TypeConverter & typeConverter,
hw::HWModuleOp module,
const PathTable & pathTable,
bool disableRegRandomization = false,
bool emitSeparateAlwaysBlocks = false,
bool emitPresetAsInlineInit = true )

Member Function Documentation

◆ addToAlwaysBlock()

void FirRegLowering::addToAlwaysBlock ( Block * block,
sv::EventControl clockEdge,
Value clock,
const std::function< void(OpBuilder &)> & body,
sv::ResetType resetStyle = {},
sv::EventControl resetEdge = {},
Value reset = {},
const std::function< void(OpBuilder &)> & resetBody = {} )
private

Definition at line 894 of file FirRegLowering.cpp.

References alwaysBlocks, assert(), emitSeparateAlwaysBlocks, and getBlockEnd().

Referenced by lowerReg().

◆ addToIfBlock()

void FirRegLowering::addToIfBlock ( OpBuilder & builder,
Value cond,
const std::function< void()> & trueSide,
const std::function< void()> & falseSide )
private

Definition at line 106 of file FirRegLowering.cpp.

References ifCache.

Referenced by createTree().

◆ buildRegConditions()

void FirRegLowering::buildRegConditions ( OpBuilder & b,
sv::VarOp reg )
private

Recreate the ifdefs under which reg was defined.

Leave the builder with its insertion point inside the created ifdef guards.

Definition at line 827 of file FirRegLowering.cpp.

References conditions, circt::FirRegLowering::RegCondition::IfDefElse, circt::FirRegLowering::RegCondition::IfDefThen, seq::reg(), and regConditionTable.

Referenced by createPresetInitialization(), and initialize().

◆ createAsyncResetInitialization()

void FirRegLowering::createAsyncResetInitialization ( ImplicitLocOpBuilder & builder)
private

Definition at line 388 of file FirRegLowering.cpp.

References asyncResets.

Referenced by createInitialBlock().

◆ createInitialBlock()

void FirRegLowering::createInitialBlock ( )
private

◆ createPaths()

FirRegLowering::PathTable FirRegLowering::createPaths ( mlir::ModuleOp top)
static

When a register is buried under an ifdef op, the initialization code at the footer of the HW module will refer to the register using a hierarchical path op.

This function creates any necessary hier paths and returns a map from buried registers to their hier path ops. HierPathOps creation needs to be serialized to keep the symbol creation deterministic, so this is done as a pre-pass on the entire MLIR module. The result should be passed in to each invocation of FirRefLowering.

Definition at line 227 of file FirRegLowering.cpp.

References circt::Namespace::add(), getAllBuriedRegs(), and getHierPathTo().

Referenced by circt::SeqToSVPass::runOnOperation().

◆ createPresetInitialization()

void FirRegLowering::createPresetInitialization ( ImplicitLocOpBuilder & builder)
private

◆ createRandomInitialization()

void FirRegLowering::createRandomInitialization ( ImplicitLocOpBuilder & builder)
private

Definition at line 344 of file FirRegLowering.cpp.

References createRandomizationVector(), initialize(), and randomInitRegs.

Referenced by createInitialBlock().

◆ createRandomizationVector()

SmallVector< Value > FirRegLowering::createRandomizationVector ( OpBuilder & builder,
Location loc )
private

◆ createTree()

void FirRegLowering::createTree ( OpBuilder & builder,
Value reg,
Value term,
Value next )
private

◆ getOrCreateConstant()

hw::ConstantOp circt::FirRegLowering::getOrCreateConstant ( Location loc,
const APInt & value )
inlineprivate

◆ initialize()

void FirRegLowering::initialize ( OpBuilder & builder,
RegLowerInfo reg,
ArrayRef< Value > rands )
private

◆ initializeRegisterElements()

void FirRegLowering::initializeRegisterElements ( Location loc,
OpBuilder & builder,
Value reg,
Value rand,
unsigned & pos )
private

◆ lower()

void FirRegLowering::lower ( )

Definition at line 250 of file FirRegLowering.cpp.

References createInitialBlock(), lowerInBlock(), and module.

Referenced by circt::SeqToSVPass::runOnOperation().

◆ lowerInBlock()

void FirRegLowering::lowerInBlock ( Block * block)
private

Definition at line 272 of file FirRegLowering.cpp.

References lowerInBlock(), lowerReg(), and lowerUnderIfDef().

Referenced by lower(), lowerInBlock(), and lowerUnderIfDef().

◆ lowerReg()

◆ lowerUnderIfDef()

void FirRegLowering::lowerUnderIfDef ( sv::IfDefOp ifDefOp)
private

◆ needsRegRandomization()

bool circt::FirRegLowering::needsRegRandomization ( ) const
inline

Definition at line 99 of file FirRegLowering.h.

References needsRandom.

Referenced by circt::SeqToSVPass::runOnOperation().

◆ tryRestoringSubaccess()

std::optional< std::tuple< Value, Value, Value > > FirRegLowering::tryRestoringSubaccess ( OpBuilder & builder,
Value reg,
Value term,
hw::ArrayCreateOp nextRegValue )
private

Member Data Documentation

◆ alwaysBlocks

llvm::SmallDenseMap<AlwaysKeyType, std::pair<sv::AlwaysOp, sv::IfOp> > circt::FirRegLowering::alwaysBlocks
private

Definition at line 179 of file FirRegLowering.h.

Referenced by addToAlwaysBlock().

◆ arrayIndexCache

llvm::SmallDenseMap<std::pair<Value, unsigned>, Value> circt::FirRegLowering::arrayIndexCache
private

Definition at line 185 of file FirRegLowering.h.

Referenced by createTree().

◆ asyncResets

llvm::MapVector<Value, SmallVector<RegLowerInfo> > circt::FirRegLowering::asyncResets
private

A map from async reset signal to the registers that use it.

Definition at line 198 of file FirRegLowering.h.

Referenced by createAsyncResetInitialization(), createInitialBlock(), and lowerReg().

◆ conditions

std::vector<RegCondition> circt::FirRegLowering::conditions
private

The ambient ifdef conditions we have encountered while lowering.

Definition at line 188 of file FirRegLowering.h.

Referenced by buildRegConditions(), lowerReg(), and lowerUnderIfDef().

◆ constantCache

llvm::SmallDenseMap<APInt, hw::ConstantOp> circt::FirRegLowering::constantCache
private

Definition at line 184 of file FirRegLowering.h.

Referenced by getOrCreateConstant().

◆ disableRegRandomization

bool circt::FirRegLowering::disableRegRandomization
private

Definition at line 206 of file FirRegLowering.h.

Referenced by FirRegLowering(), and lowerReg().

◆ emitPresetAsInlineInit

bool circt::FirRegLowering::emitPresetAsInlineInit
private

Definition at line 208 of file FirRegLowering.h.

Referenced by FirRegLowering(), and lowerReg().

◆ emitSeparateAlwaysBlocks

bool circt::FirRegLowering::emitSeparateAlwaysBlocks
private

Definition at line 207 of file FirRegLowering.h.

Referenced by addToAlwaysBlock(), and FirRegLowering().

◆ ifCache

llvm::SmallDenseMap<IfKeyType, sv::IfOp> circt::FirRegLowering::ifCache
private

Definition at line 182 of file FirRegLowering.h.

Referenced by addToIfBlock().

◆ module

hw::HWModuleOp circt::FirRegLowering::module
private

◆ needsRandom

bool circt::FirRegLowering::needsRandom = false
private

Definition at line 210 of file FirRegLowering.h.

Referenced by createInitialBlock(), and needsRegRandomization().

◆ numSubaccessRestored

unsigned circt::FirRegLowering::numSubaccessRestored = 0

Definition at line 101 of file FirRegLowering.h.

Referenced by createTree(), and circt::SeqToSVPass::runOnOperation().

◆ pathTable

const PathTable& circt::FirRegLowering::pathTable
private

Definition at line 202 of file FirRegLowering.h.

Referenced by FirRegLowering(), and lowerReg().

◆ presetInitRegs

SmallVector<RegLowerInfo> circt::FirRegLowering::presetInitRegs
private

Definition at line 191 of file FirRegLowering.h.

Referenced by createInitialBlock(), createPresetInitialization(), and lowerReg().

◆ randomInitRegs

SmallVector<RegLowerInfo> circt::FirRegLowering::randomInitRegs
private

A list of registers discovered, bucketed by initialization style.

Definition at line 191 of file FirRegLowering.h.

Referenced by createInitialBlock(), createRandomInitialization(), createRandomizationVector(), and lowerReg().

◆ reachableMuxes

std::unique_ptr<ReachableMuxes> circt::FirRegLowering::reachableMuxes
private

Definition at line 200 of file FirRegLowering.h.

Referenced by createTree(), and FirRegLowering().

◆ regConditionTable

DenseMap<sv::VarOp, std::vector<RegCondition> > circt::FirRegLowering::regConditionTable
private

A map from RegOps to the ifdef conditions under which they are defined.

We only bother recording a list of conditions if there is at least one.

Definition at line 195 of file FirRegLowering.h.

Referenced by buildRegConditions(), and lowerReg().

◆ typeConverter

TypeConverter& circt::FirRegLowering::typeConverter
private

Definition at line 203 of file FirRegLowering.h.

Referenced by FirRegLowering(), and lowerReg().


The documentation for this class was generated from the following files: