|
docc 0.8.3 (0d44999b)
C++ API Reference
|
An expander that bundles several sub-expanders and switches to the correct one per node. More...
#include <sdfg/passes/expansion/switch_expander.h>
Public Member Functions | |
| template<typename... Expanders> | |
| SwitchExpander (Expanders... expanders) | |
| Construct from a variadic list of expanders. | |
| SwitchExpander (std::vector< std::shared_ptr< const LibNodeExpander > > expanders) | |
| Construct from an already assembled list of expanders. | |
| void | register_expander (std::shared_ptr< const LibNodeExpander > expander) |
Register expander. | |
| void | register_for_code (const data_flow::LibraryNodeCode &code, std::shared_ptr< const LibNodeExpander > expander) |
Register expander as the handler for library nodes with the given code. | |
| const LibNodeExpander * | for_lib_node (const data_flow::LibraryNode &node) const override |
Find the expander that applies to node via an O(1) code lookup, with a linear fallback. | |
| ExpandOutcome | handle_expand (ExpandContext &context, structured_control_flow::Block &block, data_flow::LibraryNode &node) const override |
| Delegate expansion to the matching sub-expander. | |
| Public Member Functions inherited from sdfg::passes::LibNodeExpander | |
| virtual | ~LibNodeExpander ()=default |
| virtual const data_flow::LibraryNodeCode * | matched_code () const |
| If this expander dispatches on a single, fixed library node code, expose it here. | |
Additional Inherited Members | |
| Public Types inherited from sdfg::passes::LibNodeExpander | |
| enum class | InputUse { Skip = 0 , Scalar , IndirectRead , IndirectWrite , IndirectReadWrite } |
An expander that bundles several sub-expanders and switches to the correct one per node.
The LibNodeExpander interface already supports "tested" expanders: every expander exposes LibNodeExpander::for_lib_node which returns the concrete expander to use for a given node, or nullptr if the expander does not apply.
Most expanders dispatch on a node's data_flow::LibraryNodeCode (a string match). This class exploits that: code-based children advertise their code via LibNodeExpander::matched_code, so the switch builds a code -> expander hashmap once and then jumps straight to the right expander in O(1) per node, instead of testing every child linearly.
nullptr is returned and the node is left untouched by the pass.Expanders that handle an entire subclass of nodes (and therefore several codes) can be wired into the fast path explicitly via register_for_code, registering the same expander under each code it is responsible for.
Because it is itself a LibNodeExpander, a SwitchExpander plugs straight into the existing SingleExpanderHolder / LibraryNodeExpansionPass machinery without any changes:
|
inlineexplicit |
Construct from a variadic list of expanders.
| expanders | one or more shared_ptr to LibNodeExpander. Code-dispatching expanders (e.g. CodeLibNodeExpander subclasses) are indexed by their code for O(1) lookup; any others are consulted linearly as a fallback. |
|
inlineexplicit |
Construct from an already assembled list of expanders.
|
inlineoverridevirtual |
Find the expander that applies to node via an O(1) code lookup, with a linear fallback.
nullptr if none applies. Reimplemented from sdfg::passes::LibNodeExpander.
|
inlineoverridevirtual |
Delegate expansion to the matching sub-expander.
In the normal pass flow this is not reached, because for_lib_node already hands back the concrete child expander and the pass calls handle_expand on that child directly. It is implemented for completeness and for callers that drive this expander manually.
Implements sdfg::passes::LibNodeExpander.
|
inline |
Register expander.
If it dispatches on a single code, it is added to the fast lookup map via SwitchExpander::register_for_code otherwise it will be matched less efficiently
|
inline |
Register expander as the handler for library nodes with the given code.
| code | the library node code to route to expander. |
| expander | the expander to invoke for nodes with that code. |
| std::invalid_argument | if another expander is already registered for code. |