Jlm
Loading...
Searching...
No Matches
delta.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_RVSDG_DELTA_HPP
7#define JLM_RVSDG_DELTA_HPP
8
11
12namespace jlm::rvsdg
13{
14
18{
19public:
21
23 std::shared_ptr<const rvsdg::Type> type,
24 bool constant,
25 std::shared_ptr<const rvsdg::Type> reftype)
27 type_(std::move(type)),
28 reftype_(std::move(reftype))
29 {}
30
32
33 DeltaOperation(DeltaOperation && other) noexcept = default;
34
36 operator=(const DeltaOperation &) = delete;
37
40
41 [[nodiscard]] std::string
42 debug_string() const override;
43
44 [[nodiscard]] std::unique_ptr<Operation>
45 copy() const override;
46
47 [[nodiscard]] bool
48 operator==(const Operation & other) const noexcept override;
49
50 bool
52 {
53 return constant_;
54 }
55
56 [[nodiscard]] const rvsdg::Type &
58 {
59 return *type_;
60 }
61
62 [[nodiscard]] const std::shared_ptr<const rvsdg::Type> &
64 {
65 return type_;
66 }
67
68 [[nodiscard]] const std::shared_ptr<const rvsdg::Type> &
70 {
71 return reftype_;
72 }
73
92 static inline std::unique_ptr<DeltaOperation>
94 std::shared_ptr<const rvsdg::Type> type,
95 bool constant,
96 std::shared_ptr<const rvsdg::Type> reftype)
97 {
98 return std::make_unique<DeltaOperation>(std::move(type), constant, std::move(reftype));
99 }
100
101private:
103 std::shared_ptr<const rvsdg::Type> type_;
104 std::shared_ptr<const rvsdg::Type> reftype_;
105};
106
129{
130public:
132
133private:
135 : StructuralNode(parent, 1),
136 Operation_(std::move(op))
137 {}
138
139public:
168
182
202 MapInputContextVar(const rvsdg::Input & input) const noexcept;
203
220 MapBinderContextVar(const rvsdg::Output & output) const noexcept;
221
230 [[nodiscard]] std::vector<ContextVar>
232
233 rvsdg::Region *
235 {
237 }
238
239 [[nodiscard]] const DeltaOperation &
241
242 [[nodiscard]] const std::shared_ptr<const rvsdg::Type> &
244 {
245 return GetOperation().Type();
246 }
247
248 bool
250 {
251 return GetOperation().constant();
252 }
253
265 template<typename F>
266 size_t
268
276 size_t
278 {
279 auto match = [](const rvsdg::Input &)
280 {
281 return true;
282 };
283
285 }
286
289
290 [[nodiscard]] rvsdg::Input &
292
293 DeltaNode *
294 copy(rvsdg::Region * region, const std::vector<jlm::rvsdg::Output *> & operands) const override;
295
296 DeltaNode *
297 copy(rvsdg::Region * region, rvsdg::SubstitutionMap & smap) const override;
298
313 Create(rvsdg::Region * parent, std::unique_ptr<DeltaOperation> op)
314 {
315 return new DeltaNode(parent, std::move(op));
316 }
317
327
328private:
329 std::unique_ptr<DeltaOperation> Operation_;
330};
331
332template<typename F>
333size_t
335{
338 for (auto [input, argument] : GetContextVars())
339 {
340 if (argument->IsDead() && match(*input))
341 {
343 argumentIndices.insert(argument->index());
344 }
345 }
346
349
352
353 return numRemovedInputs;
354}
355
356}
357
358#endif
ContextVar MapInputContextVar(const rvsdg::Input &input) const noexcept
Maps input to context variable.
Definition delta.cpp:25
rvsdg::Input & result() const noexcept
Definition delta.cpp:116
std::vector< ContextVar > GetContextVars() const noexcept
Gets all bound context variables.
Definition delta.cpp:39
ContextVar MapBinderContextVar(const rvsdg::Output &output) const noexcept
Maps bound variable reference to context variable.
Definition delta.cpp:32
~DeltaNode() noexcept override
size_t RemoveDeltaInputsWhere(const F &match)
Definition delta.hpp:334
ContextVar AddContextVar(jlm::rvsdg::Output &origin)
Adds a context/free variable to the delta node.
Definition delta.cpp:16
const DeltaOperation & GetOperation() const noexcept override
Definition delta.cpp:71
std::unique_ptr< DeltaOperation > Operation_
Definition delta.hpp:329
rvsdg::Region * subregion() const noexcept
Definition delta.hpp:234
size_t PruneDeltaInputs()
Definition delta.hpp:277
bool constant() const noexcept
Definition delta.hpp:249
rvsdg::Output & finalize(rvsdg::Output *result)
Definition delta.cpp:122
static DeltaNode * Create(rvsdg::Region *parent, std::unique_ptr< DeltaOperation > op)
Definition delta.hpp:313
rvsdg::Output & output() const noexcept
Definition delta.cpp:110
DeltaNode * copy(rvsdg::Region *region, const std::vector< jlm::rvsdg::Output * > &operands) const override
Definition delta.cpp:77
Delta operation.
Definition delta.hpp:18
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
Definition delta.hpp:63
~DeltaOperation() noexcept override
std::string debug_string() const override
Definition delta.cpp:50
const rvsdg::Type & type() const noexcept
Definition delta.hpp:57
DeltaOperation & operator=(const DeltaOperation &)=delete
DeltaOperation & operator=(DeltaOperation &&)=delete
DeltaOperation(const DeltaOperation &other)=default
const std::shared_ptr< const rvsdg::Type > & ReferenceType() const noexcept
Definition delta.hpp:69
std::shared_ptr< const rvsdg::Type > reftype_
Definition delta.hpp:104
DeltaOperation(DeltaOperation &&other) noexcept=default
bool constant() const noexcept
Definition delta.hpp:51
static std::unique_ptr< DeltaOperation > Create(std::shared_ptr< const rvsdg::Type > type, bool constant, std::shared_ptr< const rvsdg::Type > reftype)
Creates parameterized delta operation.
Definition delta.hpp:93
std::shared_ptr< const rvsdg::Type > type_
Definition delta.hpp:103
bool operator==(const Operation &other) const noexcept override
Definition delta.cpp:62
std::unique_ptr< Operation > copy() const override
Definition delta.cpp:56
size_t index() const noexcept
Definition node.hpp:52
size_t RemoveInputs(const util::HashSet< size_t > &indices)
Definition node.cpp:306
rvsdg::Region * region() const noexcept
Definition node.hpp:761
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
size_t RemoveArguments(const util::HashSet< size_t > &indices)
Definition region.cpp:213
rvsdg::Region * subregion(size_t index) const noexcept
StructuralInput * input(size_t index) const noexcept
bool insert(ItemType item)
Definition HashSet.hpp:210
#define JLM_ASSERT(x)
Definition common.hpp:16
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Definition node.hpp:1049
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
Bound context variable.
Definition delta.hpp:149
rvsdg::Input * input
Input variable bound into delta node.
Definition delta.hpp:157
rvsdg::Output * inner
Access to bound object in subregion.
Definition delta.hpp:166