CIRCT 23.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
circt::synth::LogicNetwork Class Reference

Flat logic network representation for efficient cut enumeration. More...

#include <CutRewriter.h>

Collaboration diagram for circt::synth::LogicNetwork:
Collaboration graph
[legend]

Public Member Functions

ArrayRef< LogicNetworkGategetGates () const
 
 LogicNetwork ()
 
uint32_t getOrCreateIndex (Value value)
 Get or create an index for a value.
 
uint32_t getIndex (Value value) const
 Get the raw index for a value.
 
bool hasIndex (Value value) const
 Check if a value has been indexed.
 
Value getValue (uint32_t index) const
 Get the value for a given raw index.
 
void getValues (ArrayRef< uint32_t > indices, SmallVectorImpl< Value > &values) const
 Fill values for the given raw indices.
 
Signal getSignal (Value value, bool inverted) const
 Get a Signal for a value.
 
Signal getOrCreateSignal (Value value, bool inverted)
 Get or create a Signal for a value.
 
Value getValue (Signal signal) const
 Get the value for a given Signal (extracts index from Signal).
 
const LogicNetworkGategetGate (uint32_t index) const
 Get the gate at a given index.
 
LogicNetworkGategetGate (uint32_t index)
 Get mutable reference to gate at index.
 
size_t size () const
 Get the total number of nodes in the network.
 
uint32_t addPrimaryInput (Value value)
 Add a primary input to the network.
 
uint32_t addGate (Operation *op, LogicNetworkGate::Kind kind, Value result, llvm::ArrayRef< Signal > operands={})
 Add a gate with explicit result value and operand signals.
 
uint32_t addGate (Operation *op, LogicNetworkGate::Kind kind, llvm::ArrayRef< Signal > operands={})
 Add a gate using op->getResult(0) as the result value.
 
LogicalResult buildFromBlock (Block *block)
 Build the logic network from a region/block in topological order.
 
void clear ()
 Clear the network and reset to initial state.
 

Static Public Member Functions

static Signal getConstant0 ()
 Get a LogicEdge representing constant 0.
 
static Signal getConstant1 ()
 Get a LogicEdge representing constant 1 (constant 0 inverted).
 

Static Public Attributes

static constexpr uint32_t kConstant0 = 0
 Special constant indices.
 
static constexpr uint32_t kConstant1 = 1
 

Private Attributes

llvm::DenseMap< Value, uint32_t > valueToIndex
 Map from MLIR Value to network index.
 
llvm::SmallVector< Value > indexToValue
 Map from network index to MLIR Value.
 
llvm::SmallVector< LogicNetworkGategates
 Vector of all gates in the network.
 

Detailed Description

Flat logic network representation for efficient cut enumeration.

This class provides a mockturtle-style flat representation of the combinational logic network. Each value in the MLIR IR is assigned a unique index, and gates are stored in a contiguous vector for cache efficiency.

The network supports:

Special reserved indices:

Definition at line 191 of file CutRewriter.h.

Constructor & Destructor Documentation

◆ LogicNetwork()

circt::synth::LogicNetwork::LogicNetwork ( )
inline

Definition at line 199 of file CutRewriter.h.

References circt::synth::LogicNetworkGate::Constant, gates, and indexToValue.

Member Function Documentation

◆ addGate() [1/2]

uint32_t circt::synth::LogicNetwork::addGate ( Operation *  op,
LogicNetworkGate::Kind  kind,
llvm::ArrayRef< Signal operands = {} 
)
inline

Add a gate using op->getResult(0) as the result value.

Definition at line 265 of file CutRewriter.h.

◆ addGate() [2/2]

uint32_t circt::synth::LogicNetwork::addGate ( Operation *  op,
LogicNetworkGate::Kind  kind,
Value  result,
llvm::ArrayRef< Signal operands = {} 
)

Add a gate with explicit result value and operand signals.

Referenced by buildFromBlock().

◆ addPrimaryInput()

uint32_t LogicNetwork::addPrimaryInput ( Value  value)

Add a primary input to the network.

Definition at line 104 of file CutRewriter.cpp.

References gates, getOrCreateIndex(), and circt::synth::LogicNetworkGate::PrimaryInput.

Referenced by buildFromBlock().

◆ buildFromBlock()

LogicalResult LogicNetwork::buildFromBlock ( Block *  block)

◆ clear()

void LogicNetwork::clear ( )

Clear the network and reset to initial state.

Definition at line 232 of file CutRewriter.cpp.

References circt::synth::LogicNetworkGate::Constant, gates, indexToValue, and valueToIndex.

Referenced by circt::synth::CutEnumerator::clear().

◆ getConstant0()

static Signal circt::synth::LogicNetwork::getConstant0 ( )
inlinestatic

Get a LogicEdge representing constant 0.

Definition at line 209 of file CutRewriter.h.

References kConstant0.

◆ getConstant1()

static Signal circt::synth::LogicNetwork::getConstant1 ( )
inlinestatic

Get a LogicEdge representing constant 1 (constant 0 inverted).

Definition at line 212 of file CutRewriter.h.

References kConstant0.

◆ getGate() [1/2]

LogicNetworkGate & circt::synth::LogicNetwork::getGate ( uint32_t  index)
inline

Get mutable reference to gate at index.

Definition at line 252 of file CutRewriter.h.

References gates.

◆ getGate() [2/2]

const LogicNetworkGate & circt::synth::LogicNetwork::getGate ( uint32_t  index) const
inline

◆ getGates()

ArrayRef< LogicNetworkGate > circt::synth::LogicNetwork::getGates ( ) const
inline

Definition at line 197 of file CutRewriter.h.

References gates.

Referenced by circt::synth::CutEnumerator::enumerateCuts().

◆ getIndex()

uint32_t LogicNetwork::getIndex ( Value  value) const

Get the raw index for a value.

Asserts if value is not found. Note: This returns only the index, not a Signal with inversion info. Use hasIndex() to check existence first, or use getOrCreateIndex().

Definition at line 74 of file CutRewriter.cpp.

References assert(), and valueToIndex.

Referenced by getSignal(), and simulateGate().

◆ getOrCreateIndex()

uint32_t LogicNetwork::getOrCreateIndex ( Value  value)

Get or create an index for a value.

If the value doesn't have an index yet, assigns one and returns the index.

Definition at line 65 of file CutRewriter.cpp.

References gates, indexToValue, and valueToIndex.

Referenced by addPrimaryInput(), and getOrCreateSignal().

◆ getOrCreateSignal()

Signal circt::synth::LogicNetwork::getOrCreateSignal ( Value  value,
bool  inverted 
)
inline

Get or create a Signal for a value.

Definition at line 241 of file CutRewriter.h.

References getOrCreateIndex().

Referenced by buildFromBlock().

◆ getSignal()

Signal circt::synth::LogicNetwork::getSignal ( Value  value,
bool  inverted 
) const
inline

Get a Signal for a value.

Asserts if value not found - use hasIndex() first if unsure.

Definition at line 236 of file CutRewriter.h.

References getIndex().

◆ getValue() [1/2]

Value circt::synth::LogicNetwork::getValue ( Signal  signal) const
inline

Get the value for a given Signal (extracts index from Signal).

Definition at line 246 of file CutRewriter.h.

References circt::synth::Signal::getIndex(), and getValue().

Referenced by getValue().

◆ getValue() [2/2]

Value LogicNetwork::getValue ( uint32_t  index) const

Get the value for a given raw index.

Asserts if index is out of bounds. Returns null Value for constant indices (0 and 1).

Definition at line 86 of file CutRewriter.cpp.

References assert(), indexToValue, kConstant0, and kConstant1.

Referenced by circt::synth::CutEnumerator::dump(), circt::synth::Cut::dump(), and getValues().

◆ getValues()

void LogicNetwork::getValues ( ArrayRef< uint32_t >  indices,
SmallVectorImpl< Value > &  values 
) const

Fill values for the given raw indices.

Definition at line 96 of file CutRewriter.cpp.

References getValue().

◆ hasIndex()

bool LogicNetwork::hasIndex ( Value  value) const

Check if a value has been indexed.

Definition at line 82 of file CutRewriter.cpp.

References valueToIndex.

Referenced by buildFromBlock().

◆ size()

size_t circt::synth::LogicNetwork::size ( ) const
inline

Get the total number of nodes in the network.

Definition at line 255 of file CutRewriter.h.

References gates.

Referenced by esiaccel.types.ArrayType::bit_width(), esiaccel.types.ArrayType::deserialize(), and esiaccel.types.ArrayType::is_valid().

Member Data Documentation

◆ gates

llvm::SmallVector<LogicNetworkGate> circt::synth::LogicNetwork::gates
private

Vector of all gates in the network.

Definition at line 285 of file CutRewriter.h.

Referenced by addPrimaryInput(), buildFromBlock(), clear(), getGate(), getGate(), getGates(), getOrCreateIndex(), LogicNetwork(), and size().

◆ indexToValue

llvm::SmallVector<Value> circt::synth::LogicNetwork::indexToValue
private

Map from network index to MLIR Value.

Definition at line 282 of file CutRewriter.h.

Referenced by buildFromBlock(), clear(), getOrCreateIndex(), getValue(), and LogicNetwork().

◆ kConstant0

constexpr uint32_t circt::synth::LogicNetwork::kConstant0 = 0
staticconstexpr

Special constant indices.

Definition at line 194 of file CutRewriter.h.

Referenced by buildFromBlock(), getConstant0(), getConstant1(), getValue(), simulateGate(), and circt::synth::CutEnumerator::visitLogicOp().

◆ kConstant1

constexpr uint32_t circt::synth::LogicNetwork::kConstant1 = 1
staticconstexpr

◆ valueToIndex

llvm::DenseMap<Value, uint32_t> circt::synth::LogicNetwork::valueToIndex
private

Map from MLIR Value to network index.

Definition at line 279 of file CutRewriter.h.

Referenced by buildFromBlock(), clear(), getIndex(), getOrCreateIndex(), and hasIndex().


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