docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
expansion_pass.h File Reference

Library node expansion pass. More...

Go to the source code of this file.

Detailed Description

Library node expansion pass.

This file defines a peephole optimizer that will find all LibraryNodes with ImplementationType_NONE in the graph and attempt to expand all of them into more baser operations. It internally uses a list of LibNodeExpanders, so there could be multiple alternative variants to expand a given node, but for now it simply redirects to MathNode.expand() to stay more compatible with existing code.

The pass tries to isolate the contents of the expansion from the surrounding SDFG as best as possible, handling finding access nodes or moving edges in a generic way. This makes expansions simpler and allows us to upgrade the passes' handling in the future, for example to cut Dataflow into multiple parts to allow for expansion.

To achieve this, every Expander is given a context and the block to do preliminary checks, whether it can / wants to expand this node with its properties. Access to src and dest edges may be neccessary, as some LibraryNodes currently infer their data types from other nodes. Access to src and dest nodes however should be avoided, as the pass may change or remove them.

In case, an Expander wants to proceed with the expansion, it needs to call one of the available methods on the ExpansionContext:

  • replacement_requires_access_nodes()
    • The classic way, where every input and output edge is going to be replaced with AccessNodes. This way, the inputs might be accessed inside newly created loops etc.
  • replace_dataflow()
    • A simpler way, where the replacement will happen inside the existing DataFlowGraph. In this case, no access nodes will be touched. The Expander will create its new nodes and define where which original input and output edge will go The generic expansion logic will then check if this is possible or the graph can be changed to make this possible (future improvements here) It might return nullptr, if it does not know how to isolate the LibraryNode Otherwise, if the replacement was started, it must be finished successfully to not leave the SDFG in a possibly broken state.