Jlm
Loading...
Searching...
No Matches
remove-redundant-buf.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
17{
18 HandleRegion(module.Rvsdg().GetRootRegion());
19}
20
21void
29
30void
32{
33 for (auto & node : region.Nodes())
34 {
35 // Handle innermost regions first
36 if (auto structuralNode = dynamic_cast<rvsdg::StructuralNode *>(&node))
37 {
38 for (auto & subregion : structuralNode->Subregions())
39 {
40 HandleRegion(subregion);
41 }
42 continue;
43 }
44
45 auto bufferOperation = dynamic_cast<const BufferOperation *>(&node.GetOperation());
46 if (!bufferOperation)
47 continue;
48
49 if (!rvsdg::is<llvm::MemoryStateType>(node.input(0)->Type()))
50 continue;
51
52 if (bufferOperation->IsPassThrough())
53 continue;
54
55 if (!CanTraceToLoadOrStore(*node.input(0)->origin()))
56 continue;
57
58 // Replace the BufferOperation node with a passthrough BufferOperation node
59 auto result =
60 BufferOperation::create(*node.input(0)->origin(), bufferOperation->Capacity(), true)[0];
61 node.output(0)->divert_users(result);
62 }
63
64 // Prune dead nodes
65 region.prune(false);
66}
67
68bool
96
97} // namespace jlm::hls
static jlm::util::StatisticsCollector statisticsCollector
static std::vector< jlm::rvsdg::Output * > create(jlm::rvsdg::Output &value, size_t capacity, bool pass_through=false)
Definition hls.hpp:438
static void HandleRegion(rvsdg::Region &region)
~RedundantBufferElimination() noexcept override
static bool CanTraceToLoadOrStore(const rvsdg::Output &output)
static void CreateAndRun(rvsdg::RvsdgModule &module, util::StatisticsCollector &statisticsCollector)
void Run(rvsdg::RvsdgModule &module, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
Definition node.hpp:366
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
void prune(bool recursive)
Definition region.cpp:326
NodeRange Nodes() noexcept
Definition region.hpp:375
#define JLM_ASSERT(x)
Definition common.hpp:16
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872