Skip to content

Commit

Permalink
more funcitonality added to netlist traversal and netlist abstraction…
Browse files Browse the repository at this point in the history
… decorators
  • Loading branch information
SimonKlx committed Nov 4, 2024
1 parent 280d202 commit 8c9ce51
Show file tree
Hide file tree
Showing 4 changed files with 779 additions and 272 deletions.
148 changes: 144 additions & 4 deletions include/hal_core/netlist/decorators/netlist_abstraction_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "hal_core/netlist/netlist.h"
#include "hal_core/utilities/result.h"

#include <optional>

namespace hal
{
/**
Expand All @@ -42,7 +44,7 @@ namespace hal
* This struct holds an abstraction of a netlist by focusing on a subset of gates and their connections.
* It provides methods to retrieve predecessors and successors within the abstraction.
*/
struct NetlistAbstraction
struct NETLIST_API NetlistAbstraction
{
public:
/**
Expand Down Expand Up @@ -121,15 +123,15 @@ namespace hal
std::vector<Gate*> get_unique_successors(const Endpoint* endpoint) const;

/**
* @brief Gets the global input nets that are predecessors of an endpoint within the abstraction.
* @brief Gets the global input nets that are predecessors of an endpoint.
*
* @param[in] endpoint - The endpoint to get global input predecessors for.
* @returns A vector of global input nets.
*/
std::vector<Net*> get_global_input_predecessors(const Endpoint* endpoint) const;

/**
* @brief Gets the global output nets that are successors of an endpoint within the abstraction.
* @brief Gets the global output nets that are successors of an endpoint.
*
* @param[in] endpoint - The endpoint to get global output successors for.
* @returns A vector of global output nets.
Expand Down Expand Up @@ -210,6 +212,108 @@ namespace hal
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Finds the length of the shortest path connecting the start gate to a target matching the given filter.
* If there is no such path, an empty optional is returned.
* Computing only the shortest distance is faster than computing the actual path, as it does not keep track of the path to each gate.
*
* @param[in] start - The starting gate.
* @param[in] target_gate - The target gate.
* @param[in] direction - The direction to search in (`PinDirection::input`, `PinDirection::output`, or `PinDirection::inout`).
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and an optional unsigned integer representing the shortest distance on success, an error otherwise.
*/
Result<std::optional<u32>> get_shortest_path_distance(const Gate* start,
const Gate* target_gate,
const PinDirection& direction,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given endpoint, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Traverse over gates that do not meet the `target_gate_filter` condition.
* Stop traversal if (1) `continue_on_match` is `false` and the `target_gate_filter` evaluates to `true`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint, or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint.
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] endpoint - The starting endpoint.
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] continue_on_match - Set `true` to continue even if `target_gate_filter` evaluates to `true`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates(const Endpoint* endpoint,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given gate, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Traverse over gates that do not meet the `target_gate_filter` condition.
* Stop traversal if (1) `continue_on_match` is `false` and the `target_gate_filter` evaluates to `true`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint, or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint.
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] gate - The starting gate.
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] continue_on_match - Set `true` to continue even if `target_gate_filter` evaluates to `true`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates(const Gate* gate,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given endpoint, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Continue traversal regardless of whether `target_gate_filter` evaluates to `true` or `false`.
* Stop traversal if (1) `continue_on_mismatch` is `false` and the `target_gate_filter` evaluates to `false`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint, or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint.
* Both `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] endpoint - The starting endpoint.
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] continue_on_mismatch - Set `true` to continue even if `target_gate_filter` evaluates to `false`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_until(const Endpoint* endpoint,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_mismatch = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Starting from the given gate, traverse the netlist abstraction and return the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Continue traversal regardless of whether `target_gate_filter` evaluates to `true` or `false`.
* Stop traversal if (1) `continue_on_mismatch` is `false` and the `target_gate_filter` evaluates to `false`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint, or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint.
* Both `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] gate - The starting gate.
* @param[in] direction - The direction to search in (`PinDirection::input` or `PinDirection::output`).
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] continue_on_mismatch - Set `true` to continue even if `target_gate_filter` evaluates to `false`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_until(const Gate* gate,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_mismatch = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

private:
/**
* @brief Internal method to find the shortest path distance from a set of starting endpoints.
Expand All @@ -221,12 +325,48 @@ namespace hal
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and an optional unsigned integer representing the shortest distance on success, an error otherwise.
*/
Result<std::optional<u32>> get_shortest_path_distance_internal(const std::vector<Endpoint*> start,
Result<std::optional<u32>> get_shortest_path_distance_internal(const std::vector<Endpoint*>& start,
const std::function<bool(const Endpoint*, const NetlistAbstraction&)>& target_filter,
const PinDirection& direction,
const std::function<bool(const Endpoint*, u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief Internal method to traverse the netlist abstraction and return matching gates based on the provided filters.
*
* @param[in] start - The starting endpoints.
* @param[in] direction - The direction to search in.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] continue_on_match - Determines whether to continue traversal after a match.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_internal(const std::vector<const Endpoint*>& start,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_match,
const std::function<bool(const Endpoint*, u32 current_depth)>& exit_endpoint_filter,
const std::function<bool(const Endpoint*, u32 current_depth)>& entry_endpoint_filter) const;

/**
* @brief Internal method to traverse the netlist abstraction and return matching gates until certain conditions are met.
*
* @param[in] start - The starting endpoints.
* @param[in] direction - The direction to search in.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] continue_on_mismatch - Determines whether to continue traversal after a mismatch.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_until_internal(const std::vector<const Endpoint*>& start,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_mismatch = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* @brief The netlist abstraction to operate on.
*/
Expand Down
Loading

0 comments on commit 8c9ce51

Please sign in to comment.