Jlm
Loading...
Searching...
No Matches
add-sinks.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 David Metz <david.c.metz@ntnu.no>
3 * See COPYING for terms of redistribution.
4 */
5
7#include <jlm/hls/ir/hls.hpp>
9
10namespace jlm::hls
11{
12
14
15void
16SinkInsertion::Run(rvsdg::RvsdgModule & module, util::StatisticsCollector &)
17{
18 HandleRootRegion(module.Rvsdg().GetRootRegion());
19}
20
21void
29
30void
32{
33 for (auto & node : region.Nodes())
34 {
35 if (const auto structuralNode = dynamic_cast<rvsdg::StructuralNode *>(&node))
36 {
37 for (auto & subregion : structuralNode->Subregions())
38 {
39 AddSinksToRegion(subregion);
40 }
41 }
42 }
43}
44
45void
47{
48 // Add sinks to region arguments
49 for (const auto argument : region.Arguments())
50 {
51 if (argument->IsDead())
52 {
53 SinkOperation::create(*argument);
54 }
55 }
56
57 for (auto & node : region.Nodes())
58 {
59 // Add sinks to subregions of structural nodes
60 if (const auto structuralNode = dynamic_cast<rvsdg::StructuralNode *>(&node))
61 {
62 for (auto & subregion : structuralNode->Subregions())
63 {
64 AddSinksToRegion(subregion);
65 }
66 }
67
68 // Add sinks to outputs of nodes
69 for (size_t n = 0; n < node.noutputs(); n++)
70 {
71 const auto output = node.output(n);
72 if (output->IsDead())
73 {
74 SinkOperation::create(*output);
75 }
76 }
77 }
78}
79
80}
static jlm::util::StatisticsCollector statisticsCollector
void Run(rvsdg::RvsdgModule &module, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
Definition add-sinks.cpp:16
static void AddSinksToRegion(rvsdg::Region &region)
Definition add-sinks.cpp:46
~SinkInsertion() noexcept override
static void HandleRootRegion(rvsdg::Region &region)
Definition add-sinks.cpp:31
static void CreateAndRun(rvsdg::RvsdgModule &module, util::StatisticsCollector &statisticsCollector)
Definition add-sinks.cpp:22
static std::vector< jlm::rvsdg::Output * > create(jlm::rvsdg::Output &value)
Definition hls.hpp:302
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
RegionArgumentRange Arguments() noexcept
Definition region.hpp:319
NodeRange Nodes() noexcept
Definition region.hpp:375
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872