HAL
hal::netlist_utils Namespace Reference

Functions

Result< BooleanFunctionget_subgraph_function (const Net *net, const std::vector< const Gate * > &subgraph_gates, std::map< std::pair< u32, const GatePin * >, BooleanFunction > &cache)
 
Result< BooleanFunctionget_subgraph_function (const Net *net, const std::vector< const Gate * > &subgraph_gates)
 
std::unique_ptr< Netlistcopy_netlist (const Netlist *nl)
 
std::pair< std::map< u32, Gate * >, std::vector< std::vector< int > > > get_ff_dependency_matrix (const Netlist *nl)
 
std::unique_ptr< Netlistget_partial_netlist (const Netlist *nl, const std::vector< const Gate * > &subgraph_gates)
 
std::vector< Gate * > get_next_gates (const Gate *gate, bool get_successors, int depth, const std::function< bool(const Gate *)> &filter)
 
std::vector< Gate * > get_next_gates (const Net *net, bool get_successors, int depth, const std::function< bool(const Gate *)> &filter)
 
std::vector< Gate * > get_shortest_path (Gate *start_gate, Gate *end_gate, bool search_both_directions)
 
std::vector< Gate * > get_next_sequential_gates (const Gate *gate, bool get_successors, std::unordered_map< u32, std::vector< Gate * >> &cache)
 
std::vector< Gate * > get_next_sequential_gates (const Net *net, bool get_successors, std::unordered_map< u32, std::vector< Gate * >> &cache)
 
std::vector< Gate * > get_next_sequential_gates (const Gate *gate, bool get_successors)
 
std::vector< Gate * > get_next_sequential_gates (const Net *net, bool get_successors)
 
std::vector< Gate * > get_path (const Gate *gate, bool get_successors, std::set< GateTypeProperty > stop_properties, std::unordered_map< u32, std::vector< Gate * >> &cache)
 
std::vector< Gate * > get_path (const Net *net, bool get_successors, std::set< GateTypeProperty > stop_properties, std::unordered_map< u32, std::vector< Gate * >> &cache)
 
std::vector< Gate * > get_path (const Gate *gate, bool get_successors, std::set< GateTypeProperty > stop_properties)
 
std::vector< Gate * > get_path (const Net *net, bool get_successors, std::set< GateTypeProperty > stop_properties)
 
std::vector< Net * > get_nets_at_pins (Gate *gate, std::vector< GatePin * > pins)
 
Result< u32remove_buffers (Netlist *netlist, bool analyze_inputs)
 
Result< u32remove_unused_lut_endpoints (Netlist *netlist)
 
std::vector< Net * > get_common_inputs (const std::vector< Gate * > &gates, u32 threshold)
 
Result< std::monostate > replace_gate (Gate *gate, GateType *target_type, std::map< GatePin *, GatePin * > pin_map)
 
Result< std::vector< Gate * > > get_gate_chain (Gate *start_gate, const std::vector< const GatePin * > &input_pins, const std::vector< const GatePin * > &output_pins, const std::function< bool(const Gate *)> &filter)
 
Result< std::vector< Gate * > > get_complex_gate_chain (Gate *start_gate, const std::vector< GateType * > &chain_types, const std::map< GateType *, std::vector< const GatePin * >> &input_pins, const std::map< GateType *, std::vector< const GatePin * >> &output_pins, const std::function< bool(const Gate *)> &filter)
 

Function Documentation

◆ copy_netlist()

CORE_API std::unique_ptr< Netlist > hal::netlist_utils::copy_netlist ( const Netlist nl)
Deprecated:
Get a deep copy of an entire netlist including all of its gates, nets, modules, and groupings.
Parameters
[in]nl- The netlist to copy.
Returns
The deep copy of the netlist.

Definition at line 95 of file netlist_utils.cpp.

References hal::Netlist::copy(), and log_error.

Referenced by hal::netlist_utils_init().

◆ get_common_inputs()

CORE_API std::vector< Net * > hal::netlist_utils::get_common_inputs ( const std::vector< Gate * > &  gates,
u32  threshold = 0 
)

Returns all nets that are considered to be common inputs to the provided gates. A threshold value can be provided to specify the number of gates a net must be connected to in order to be classified as a common input. If the theshold value is set to 0, a net must be input to all gates to be considered a common input.

Parameters
[in]gates- The gates.
[in]threshold- The threshold value, defaults to 0.
Returns
The common input nets.

Definition at line 724 of file netlist_utils.cpp.

References test_plugin::g, and test::n.

Referenced by hal::netlist_utils_init().

◆ get_complex_gate_chain()

CORE_API Result< std::vector< Gate * > > hal::netlist_utils::get_complex_gate_chain ( Gate start_gate,
const std::vector< GateType * > &  chain_types,
const std::map< GateType *, std::vector< const GatePin * >> &  input_pins,
const std::map< GateType *, std::vector< const GatePin * >> &  output_pins,
const std::function< bool(const Gate *)> &  filter = nullptr 
)

Find a sequence of gates (of the specified sequence of gate types) that are connected via the specified input and output pins. The start gate may be any gate within a such a sequence, it is not required to be the first or the last gate. However, the start gate must be of the first gate type within the repeating sequence. If input and/or output pins are specified for a gate type, the gates must be connected through one of the input pins and/or one of the output pins. The optional filter is evaluated on every gate such that the result only contains gates matching the specified condition.

Parameters
[in]start_gate- The gate at which to start the chain detection.
[in]chain_types- The sequence of gate types that is expected to make up the gate chain.
[in]input_pins- The input pins (of every gate type of the sequence) through which the gates must be connected.
[in]output_pins- The output pins (of every gate type of the sequence) through which the gates must be connected.
[in]filter- An optional filter function to be evaluated on each gate.
Returns
A vector of gates that form a chain on success, an error otherwise.

Definition at line 904 of file netlist_utils.cpp.

References ERR, hal::Endpoint::get_gate(), hal::Gate::get_id(), hal::Netlist::get_id(), hal::Gate::get_name(), hal::Gate::get_netlist(), hal::Endpoint::get_pin(), hal::Gate::get_predecessors(), hal::Gate::get_successors(), hal::Gate::get_type(), log_debug, and OK.

Referenced by hal::netlist_utils_init().

◆ get_ff_dependency_matrix()

std::pair< std::map< u32, Gate * >, std::vector< std::vector< int > > > hal::netlist_utils::get_ff_dependency_matrix ( const Netlist nl)

Get the FF dependency matrix of a netlist.

Parameters
[in]nl- The netlist to extract the dependency matrix from.
Returns
A pair consisting of std::map<u32, Gate*>, which includes the mapping from the original gate IDs to the ones in the matrix, and a std::vector<std::vector<int>, which is the ff dependency matrix

Definition at line 108 of file netlist_utils.cpp.

References hal::ff, hal::Netlist::get_gates(), and get_next_sequential_gates().

Referenced by hal::netlist_utils_init().

◆ get_gate_chain()

CORE_API Result< std::vector< Gate * > > hal::netlist_utils::get_gate_chain ( Gate start_gate,
const std::vector< const GatePin * > &  input_pins = {},
const std::vector< const GatePin * > &  output_pins = {},
const std::function< bool(const Gate *)> &  filter = nullptr 
)

Find a sequence of identical gates that are connected via the specified input and output pins. The start gate may be any gate within a such a sequence, it is not required to be the first or the last gate. If input and/or output pins are specified, the gates must be connected through one of the input pins and/or one of the output pins. The optional filter is evaluated on every gate such that the result only contains gates matching the specified condition.

Parameters
[in]start_gate- The gate at which to start the chain detection.
[in]input_pins- The input pins through which the gates must be connected. Defaults to an empty vector.
[in]output_pins- The output pins through which the gates must be connected. Defaults to an empty vector.
[in]filter- An optional filter function to be evaluated on each gate.
Returns
A vector of gates that form a chain on success, an error otherwise.

Definition at line 781 of file netlist_utils.cpp.

References ERR, hal::Endpoint::get_gate(), hal::Gate::get_id(), hal::Netlist::get_id(), hal::Gate::get_name(), hal::Gate::get_netlist(), hal::Gate::get_successors(), hal::Gate::get_type(), and log_debug.

Referenced by hal::netlist_utils_init().

◆ get_nets_at_pins()

CORE_API std::vector< Net * > hal::netlist_utils::get_nets_at_pins ( Gate gate,
std::vector< GatePin * >  pins 
)

Get the nets that are connected to a subset of pins of the specified gate.

Parameters
[in]gate- The gate.
[in]pins- The targeted pins.
Returns
A vector of nets connected to the pins.

Definition at line 442 of file netlist_utils.cpp.

References direction, hal::Gate::get_fan_in_net(), hal::Gate::get_fan_out_net(), hal::Gate::get_id(), hal::Gate::get_name(), hal::inout, hal::input, log_warning, net, hal::output, and pins.

Referenced by hal::netlist_utils_init().

◆ get_next_gates() [1/2]

CORE_API std::vector< Gate * > hal::netlist_utils::get_next_gates ( const Gate gate,
bool  get_successors,
int  depth = 0,
const std::function< bool(const Gate *)> &  filter = nullptr 
)
Deprecated:
Find predecessors or successors of a gate. If depth is set to 1 only direct predecessors/successors will be returned. Higher number of depth causes as many steps of recursive calls. If depth is set to 0 there is no limitation and the loop continues until no more predecessors/succesors are found. If a filter function is given only gates matching the filter will be added to the result vector. The result will not include the provided gate itself.
Parameters
[in]gate- The initial gate.
[in]get_successors- True to return successors, false for Predecessors.
[in]depth- Depth of recursion.
[in]filter- User-defined filter function.
Returns
Vector of predecessor/successor gates.

Definition at line 166 of file netlist_utils.cpp.

References test::n.

Referenced by hal::CommonSuccessorPredecessorGateQueue::getNext(), and hal::netlist_utils_init().

◆ get_next_gates() [2/2]

CORE_API std::vector< Gate * > hal::netlist_utils::get_next_gates ( const Net net,
bool  get_successors,
int  depth = 0,
const std::function< bool(const Gate *)> &  filter = nullptr 
)
Deprecated:
Find predecessors or successors of a net. If depth is set to 1 only direct predecessors/successors will be returned. Higher number of depth causes as many steps of recursive calls. If depth is set to 0 there is no limitation and the loop continues until no more predecessors/succesors are found. If a filter function is given, the recursion stops whenever the filter function evaluates to False. Only gates matching the filter will be added to the result vector.
Parameters
[in]net- The initial net.
[in]get_successors- True to return successors, false for Predecessors.
[in]depth- Depth of recursion.
[in]filter- User-defined filter function.
Returns
Vector of predecessor/successor gates.

Definition at line 214 of file netlist_utils.cpp.

References test_plugin::g, test::n, and net.

◆ get_next_sequential_gates() [1/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_next_sequential_gates ( const Gate gate,
bool  get_successors 
)
Deprecated:
Find all sequential predecessors or successors of a gate. Traverses combinational logic of all input or output nets until sequential gates are found. The result may include the provided gate itself.
Parameters
[in]gate- The initial gate.
[in]get_successors- If true, sequential successors are returned, otherwise sequential predecessors are returned.
Returns
All sequential successors or predecessors of the gate.

Definition at line 345 of file netlist_utils.cpp.

References get_next_sequential_gates().

◆ get_next_sequential_gates() [2/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_next_sequential_gates ( const Gate gate,
bool  get_successors,
std::unordered_map< u32, std::vector< Gate * >> &  cache 
)
Deprecated:
Find all sequential predecessors or successors of a gate. Traverses combinational logic of all input or output nets until sequential gates are found. The result may include the provided gate itself. The use of the this cached version is recommended in case of extensive usage to improve performance. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.
Parameters
[in]gate- The initial gate.
[in]get_successors- If true, sequential successors are returned, otherwise sequential predecessors are returned.
[in,out]cache- The cache.
Returns
All sequential successors or predecessors of the gate.

Definition at line 324 of file netlist_utils.cpp.

References hal::Gate::get_fan_in_nets(), hal::Gate::get_fan_out_nets(), and test::n.

Referenced by get_ff_dependency_matrix(), get_next_sequential_gates(), and hal::netlist_utils_init().

◆ get_next_sequential_gates() [3/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_next_sequential_gates ( const Net net,
bool  get_successors 
)
Deprecated:
Find all sequential predecessors or successors of a net. Traverses combinational logic of all input or output nets until sequential gates are found.
Parameters
[in]net- The initial net.
[in]get_successors- If true, sequential successors are returned, otherwise sequential predecessors are returned.
Returns
All sequential successors or predecessors of the net.

Definition at line 351 of file netlist_utils.cpp.

References get_next_sequential_gates(), and net.

◆ get_next_sequential_gates() [4/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_next_sequential_gates ( const Net net,
bool  get_successors,
std::unordered_map< u32, std::vector< Gate * >> &  cache 
)
Deprecated:
Find all sequential predecessors or successors of a net. Traverses combinational logic of all input or output nets until sequential gates are found. The use of the cache is recommended in case of extensive usage of this function. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.
Parameters
[in]net- The initial net.
[in]get_successors- If true, sequential successors are returned, otherwise sequential predecessors are returned.
[in,out]cache- The cache.
Returns
All sequential successors or predecessors of the net.

Definition at line 339 of file netlist_utils.cpp.

References net.

◆ get_partial_netlist()

CORE_API std::unique_ptr< Netlist > hal::netlist_utils::get_partial_netlist ( const Netlist nl,
const std::vector< const Gate * > &  subgraph_gates 
)
Deprecated:
Get a deep copy of an entire partial netlist including all of its gates, nets, excluding modules and groupings.
Parameters
[in]nl- The netlist consisting of the subgraph.
[in]subgraph_gates- The gates the subgraph is supposed to consist of.
Returns
The deep copy of the netlist.

Definition at line 153 of file netlist_utils.cpp.

References hal::SubgraphNetlistDecorator::copy_subgraph_netlist(), and log_error.

◆ get_path() [1/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_path ( const Gate gate,
bool  get_successors,
std::set< GateTypeProperty stop_properties 
)

Find all gates on the predeccessor or successor path of a gate. Traverses all input or output nets until gates of the specified base types are found. The result may include the provided gate itself.

Parameters
[in]gate- The initial gate.
[in]get_successors- If true, the successor path is returned, otherwise the predecessor path is returned.
[in]stop_properties- Stop recursion when reaching a gate of a type with one of the specified properties.
Returns
All gates on the predecessor or successor path of the gate.

Definition at line 430 of file netlist_utils.cpp.

References get_path().

◆ get_path() [2/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_path ( const Gate gate,
bool  get_successors,
std::set< GateTypeProperty stop_properties,
std::unordered_map< u32, std::vector< Gate * >> &  cache 
)

Find all gates on the predecessor or successor path of a gate. Traverses all input or output nets until gates of the specified base types are found. The result may include the provided gate itself. The use of the this cached version is recommended in case of extensive usage to improve performance. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.

Parameters
[in]gate- The initial gate.
[in]get_successors- If true, the successor path is returned, otherwise the predecessor path is returned.
[in]stop_properties- Stop recursion when reaching a gate of a type with one of the specified properties.
[in,out]cache- The cache.
Returns
All gates on the predecessor or successor path of the gate.

Definition at line 409 of file netlist_utils.cpp.

References hal::Gate::get_fan_in_nets(), hal::Gate::get_fan_out_nets(), and test::n.

Referenced by get_path(), and hal::netlist_utils_init().

◆ get_path() [3/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_path ( const Net net,
bool  get_successors,
std::set< GateTypeProperty stop_properties 
)

Find all gates on the predecessor or successor path of a net. Traverses all input or output nets until gates of the specified base types are found.

Parameters
[in]net- The initial net.
[in]get_successors- If true, the successor path is returned, otherwise the predecessor path is returned.
[in]stop_properties- Stop recursion when reaching a gate of a type with one of the specified properties.
Returns
All gates on the predecessor or successor path of the net.

Definition at line 436 of file netlist_utils.cpp.

References get_path(), and net.

◆ get_path() [4/4]

CORE_API std::vector< Gate * > hal::netlist_utils::get_path ( const Net net,
bool  get_successors,
std::set< GateTypeProperty stop_properties,
std::unordered_map< u32, std::vector< Gate * >> &  cache 
)

Find all gates on the predecessor or successor path of a net. Traverses all input or output nets until gates of the specified base types are found. The use of the this cached version is recommended in case of extensive usage to improve performance. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.

Parameters
[in]net- The initial net.
[in]get_successors- If true, the successor path is returned, otherwise the predecessor path is returned.
[in]stop_properties- Stop recursion when reaching a gate of a type with one of the specified properties.
[in,out]cache- The cache.
Returns
All gates on the predecessor or successor path of the net.

Definition at line 424 of file netlist_utils.cpp.

References net.

◆ get_shortest_path()

CORE_API std::vector< Gate * > hal::netlist_utils::get_shortest_path ( Gate start_gate,
Gate end_gate,
bool  search_both_directions = false 
)
Deprecated:
Find the shortest path (i.e., theresult set with the lowest number of gates) that connects the start gate with the end gate. The gate where the search started from will be the first in the result vector, the end gate will be the last. If there is no such path an empty vector is returned. If there is more than one path with the same length only the first one is returned.
Parameters
[in]start_gate- The gate to start from.
[in]end_gate- The gate to connect to.
[in]search_both_directions- True to additionally check whether a shorter path from end to start exists, false otherwise.
Returns
A vector of gates that connect the start with end gate (possibly in reverse order).

Definition at line 271 of file netlist_utils.cpp.

Referenced by hal::GraphGraphicsView::handleShortestPath(), and hal::netlist_utils_init().

◆ get_subgraph_function() [1/2]

CORE_API Result< BooleanFunction > hal::netlist_utils::get_subgraph_function ( const Net net,
const std::vector< const Gate * > &  subgraph_gates 
)
Deprecated:
Get the combined Boolean function of a subgraph of combinational gates starting at the source of the given net. The variables of the resulting Boolean function are made up of the IDs of the nets that influence the output ('net_[ID]').
Parameters
[in]net- The net for which to generate the Boolean function.
[in]subgraph_gates- The gates making up the subgraph to consider.
Returns
The combined Boolean function of the subgraph on success, an error otherwise.

Definition at line 82 of file netlist_utils.cpp.

References ERR, get_subgraph_function(), and net.

◆ get_subgraph_function() [2/2]

CORE_API Result< BooleanFunction > hal::netlist_utils::get_subgraph_function ( const Net net,
const std::vector< const Gate * > &  subgraph_gates,
std::map< std::pair< u32, const GatePin * >, BooleanFunction > &  cache 
)
Deprecated:
Get the combined Boolean function of a subgraph of combinational gates starting at the source of the given net. The variables of the resulting Boolean function are made up of the IDs of the nets that influence the output ('net_[ID]'). Utilizes a cache for speedup on consecutive calls.
Parameters
[in]net- The net for which to generate the Boolean function.
[in]subgraph_gates- The gates making up the subgraph to consider.
[in,out]cache- Cache to speed up computations. The cache is filled by this function.
Returns
The combined Boolean function of the subgraph on success, an error otherwise.

Definition at line 65 of file netlist_utils.cpp.

References ERR, hal::SubgraphNetlistDecorator::get_subgraph_function(), and net.

Referenced by get_subgraph_function(), and hal::netlist_utils_init().

◆ remove_buffers()

CORE_API Result< u32 > hal::netlist_utils::remove_buffers ( Netlist netlist,
bool  analyze_inputs = false 
)
Deprecated:
Remove all buffer gates from the netlist and connect their fan-in to their fan-out nets. If enabled, analyzes every gate's inputs and removes fixed '0' or '1' inputs from the Boolean function.
Parameters
[in]netlist- The target netlist.
[in]analyze_inputs- Set true to dynamically analyze the inputs, false otherwise.
Returns
The number of removed buffers on success, an error otherwise.

Definition at line 482 of file netlist_utils.cpp.

References hal::Net::add_destination(), hal::combinational, hal::BooleanFunction::Const(), ERR, hal::Gate::get_boolean_functions(), hal::Net::get_destinations(), hal::Gate::get_fan_in_endpoints(), hal::Gate::get_fan_out_endpoints(), hal::Gate::get_id(), hal::Net::get_id(), hal::GateType::get_input_pin_names(), hal::Gate::get_name(), hal::Net::get_name(), hal::BasePin< T >::get_name(), hal::Endpoint::get_net(), hal::Endpoint::get_pin(), hal::Gate::get_type(), hal::ground, hal::GateType::has_property(), test_multiple::netlist, OK, hal::power, hal::Net::remove_destination(), hal::BooleanFunction::simplify(), hal::BooleanFunction::substitute(), and hal::BooleanFunction::to_string().

Referenced by hal::netlist_utils_init().

◆ remove_unused_lut_endpoints()

CORE_API Result< u32 > hal::netlist_utils::remove_unused_lut_endpoints ( Netlist netlist)
Deprecated:
Remove all LUT fan-in endpoints that are not present within the Boolean function of the output of a gate.
Parameters
[in]netlist- The target netlist.
Returns
The number of removed endpoints on success, an error otherwise.

Definition at line 671 of file netlist_utils.cpp.

References hal::Net::add_destination(), ERR, test_plugin::g, hal::Gate::get_boolean_functions(), hal::Gate::get_fan_in_endpoints(), hal::Gate::get_id(), hal::Gate::get_name(), test_multiple::netlist, and OK.

Referenced by hal::netlist_utils_init().

◆ replace_gate()

CORE_API Result< std::monostate > hal::netlist_utils::replace_gate ( Gate gate,
GateType target_type,
std::map< GatePin *, GatePin * >  pin_map 
)
Deprecated:
Replace the given gate with a gate of the specified gate type. A map from old to new pins must be provided in order to correctly connect the gates inputs and outputs. A pin can be omitted if no connection at that pin is desired.
Parameters
[in]gate- The gate to be replaced.
[in]target_type- The gate type of the replacement gate.
[in]pin_map- A map from old to new pins.
Returns
Ok on success, an error otherwise.

Definition at line 768 of file netlist_utils.cpp.

References ERR, hal::Gate::get_netlist(), OK, and hal::NetlistModificationDecorator::replace_gate().

Referenced by hal::netlist_utils_init().