Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
circt::FirRegLowering Class Reference

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

#include <FirRegLowering.h>

Collaboration diagram for circt::FirRegLowering:
Collaboration graph
[legend]

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)
 
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 = std::tuple< Block *, sv::EventControl, Value, sv::ResetType, sv::EventControl, Value >
 
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::RegOp 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::ConstantOpconstantCache
 
llvm::SmallDenseMap< std::pair< Value, unsigned >, Value > arrayIndexCache
 
std::vector< RegConditionconditions
 The ambient ifdef conditions we have encountered while lowering.
 
SmallVector< RegLowerInforandomInitRegs
 A list of registers discovered, bucketed by initialization style.
 
SmallVector< RegLowerInfopresetInitRegs
 
DenseMap< sv::RegOp, 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< ReachableMuxesreachableMuxes
 
const PathTablepathTable
 
TypeConverter & typeConverter
 
hw::HWModuleOp bool disableRegRandomization
 
bool emitSeparateAlwaysBlocks
 
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

using circt::FirRegLowering::AlwaysKeyType = std::tuple<Block *, sv::EventControl, Value, sv::ResetType, sv::EventControl, Value>
private

Definition at line 175 of file FirRegLowering.h.

◆ IfKeyType

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

Definition at line 180 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 
)

Definition at line 236 of file FirRegLowering.cpp.

References reachableMuxes.

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 865 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::RegOp  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 798 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 385 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 226 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 341 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 247 of file FirRegLowering.cpp.

References createInitialBlock(), and lowerInBlock().

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

◆ lowerInBlock()

void FirRegLowering::lowerInBlock ( Block *  block)
private

Definition at line 269 of file FirRegLowering.cpp.

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

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

◆ lowerReg()

void FirRegLowering::lowerReg ( seq::FirRegOp  reg)
private

◆ lowerUnderIfDef()

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

◆ needsRegRandomization()

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

Definition at line 98 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 178 of file FirRegLowering.h.

Referenced by addToAlwaysBlock().

◆ arrayIndexCache

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

Definition at line 184 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 197 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 187 of file FirRegLowering.h.

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

◆ constantCache

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

Definition at line 183 of file FirRegLowering.h.

Referenced by getOrCreateConstant().

◆ disableRegRandomization

hw::HWModuleOp bool circt::FirRegLowering::disableRegRandomization
private

Definition at line 205 of file FirRegLowering.h.

Referenced by lowerReg().

◆ emitSeparateAlwaysBlocks

bool circt::FirRegLowering::emitSeparateAlwaysBlocks
private

Definition at line 206 of file FirRegLowering.h.

Referenced by addToAlwaysBlock().

◆ ifCache

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

Definition at line 181 of file FirRegLowering.h.

Referenced by addToIfBlock().

◆ needsRandom

bool circt::FirRegLowering::needsRandom = false
private

Definition at line 208 of file FirRegLowering.h.

Referenced by createInitialBlock(), and needsRegRandomization().

◆ numSubaccessRestored

unsigned circt::FirRegLowering::numSubaccessRestored = 0

Definition at line 100 of file FirRegLowering.h.

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

◆ pathTable

const PathTable& circt::FirRegLowering::pathTable
private

Definition at line 201 of file FirRegLowering.h.

Referenced by lowerReg().

◆ presetInitRegs

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

Definition at line 190 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 190 of file FirRegLowering.h.

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

◆ reachableMuxes

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

Definition at line 199 of file FirRegLowering.h.

Referenced by createTree(), and FirRegLowering().

◆ regConditionTable

DenseMap<sv::RegOp, 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 194 of file FirRegLowering.h.

Referenced by buildRegConditions(), and lowerReg().

◆ typeConverter

TypeConverter& circt::FirRegLowering::typeConverter
private

Definition at line 202 of file FirRegLowering.h.

Referenced by lowerReg().


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