Jlm
Loading...
Searching...
No Matches
TestOperations.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_RVSDG_TESTOPERATIONS_HPP
7#define JLM_RVSDG_TESTOPERATIONS_HPP
8
10#include <jlm/rvsdg/nullary.hpp>
11#include <jlm/rvsdg/unary.hpp>
12
13namespace jlm::rvsdg
14{
15
17{
18public:
19 explicit TestNullaryOperation(const std::shared_ptr<const Type> & resultType)
21 {}
22
23 bool
24 operator==(const Operation & other) const noexcept override
25 {
26 const auto nullaryOperation = dynamic_cast<const TestNullaryOperation *>(&other);
27 return nullaryOperation && *result(0) == *nullaryOperation->result(0);
28 }
29
30 [[nodiscard]] std::string
31 debug_string() const override
32 {
33 return "NullaryOperation";
34 }
35
36 [[nodiscard]] std::unique_ptr<Operation>
37 copy() const override
38 {
39 return std::make_unique<TestNullaryOperation>(this->result(0));
40 }
41};
42
44{
45public:
47
53
54 bool
55 operator==(const Operation & other) const noexcept override;
56
57 [[nodiscard]] std::string
58 debug_string() const override;
59
60 [[nodiscard]] std::unique_ptr<Operation>
61 copy() const override;
62
63 static Node *
65 Region *,
66 std::shared_ptr<const Type> operandType,
67 Output * operand,
68 std::shared_ptr<const Type> resultType)
69 {
71 { operand },
72 std::move(operandType),
73 std::move(resultType));
74 }
75
76 static Output *
78 std::shared_ptr<const Type> operandType,
79 Output * operand,
80 std::shared_ptr<const Type> resultType)
81 {
83 { operand },
84 std::move(operandType),
85 std::move(resultType))
86 .output(0);
87 }
88};
89
91{
92public:
94
102
103 bool
104 operator==(const Operation & other) const noexcept override;
105
107 can_reduce_operand_pair(const Output * op1, const Output * op2) const noexcept override;
108
109 Output *
110 reduce_operand_pair(binop_reduction_path_t path, Output * op1, Output * op2) const override;
111
114
115 [[nodiscard]] std::string
117
118 [[nodiscard]] std::unique_ptr<Operation>
120
121 static Node *
125 Output * op1,
126 Output * op2)
127 {
129 { op1, op2 },
131 std::move(resultType),
132 flags::none);
133 }
134
135 static Output *
137 const std::shared_ptr<const Type> operandType,
138 std::shared_ptr<const Type> resultType,
139 Output * op1,
140 Output * op2)
141 {
143 { op1, op2 },
145 std::move(resultType),
146 flags::none)
147 .output(0);
148 }
149
150private:
152};
153
155{
156public:
158
164
165 TestOperation(const TestOperation &) = default;
166
167 bool
168 operator==(const Operation & other) const noexcept override;
169
170 [[nodiscard]] std::string
171 debug_string() const override;
172
173 [[nodiscard]] std::unique_ptr<Operation>
174 copy() const override;
175
176 static std::unique_ptr<TestOperation>
178 std::vector<std::shared_ptr<const Type>> operandTypes,
179 std::vector<std::shared_ptr<const Type>> resultTypes)
180 {
181 return std::make_unique<TestOperation>(std::move(operandTypes), std::move(resultTypes));
182 }
183
184 static SimpleNode *
186 Region * region,
187 const std::vector<Output *> & operands,
188 std::vector<std::shared_ptr<const Type>> resultTypes)
189 {
190 std::vector<std::shared_ptr<const Type>> operandTypes;
191 for (const auto & operand : operands)
192 operandTypes.push_back(operand->Type());
193
194 return createNode(region, operandTypes, operands, std::move(resultTypes));
195 }
196
197 static SimpleNode *
199 Region * region,
200 std::vector<std::shared_ptr<const Type>> operandTypes,
201 const std::vector<rvsdg::Output *> & operands,
202 std::vector<std::shared_ptr<const Type>> resultTypes)
203 {
205 *region,
206 std::move(operandTypes),
207 std::move(resultTypes))
209 { operands },
210 std::move(operandTypes),
211 std::move(resultTypes));
212 }
213};
214
215}
216
217#endif
Nullary operator (operator taking no formal arguments)
Definition nullary.hpp:22
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
const std::shared_ptr< const rvsdg::Type > & result(size_t index) const noexcept
Definition operation.cpp:36
binop_reduction_path_t can_reduce_operand_pair(const Output *op1, const Output *op2) const noexcept override
static Node * create(const std::shared_ptr< const Type > &operandType, std::shared_ptr< const Type > resultType, Output *op1, Output *op2)
~TestBinaryOperation() noexcept override
std::unique_ptr< Operation > copy() const override
Output * reduce_operand_pair(binop_reduction_path_t path, Output *op1, Output *op2) const override
bool operator==(const Operation &other) const noexcept override
enum BinaryOperation::flags flags_
enum BinaryOperation::flags flags() const noexcept override
std::string debug_string() const override
static Output * create_normalized(const std::shared_ptr< const Type > operandType, std::shared_ptr< const Type > resultType, Output *op1, Output *op2)
bool operator==(const Operation &other) const noexcept override
TestNullaryOperation(const std::shared_ptr< const Type > &resultType)
std::unique_ptr< Operation > copy() const override
std::string debug_string() const override
static SimpleNode * createNode(Region *region, const std::vector< Output * > &operands, std::vector< std::shared_ptr< const Type > > resultTypes)
std::string debug_string() const override
std::unique_ptr< Operation > copy() const override
~TestOperation() noexcept override
TestOperation(const TestOperation &)=default
bool operator==(const Operation &other) const noexcept override
static std::unique_ptr< TestOperation > create(std::vector< std::shared_ptr< const Type > > operandTypes, std::vector< std::shared_ptr< const Type > > resultTypes)
static SimpleNode * createNode(Region *region, std::vector< std::shared_ptr< const Type > > operandTypes, const std::vector< rvsdg::Output * > &operands, std::vector< std::shared_ptr< const Type > > resultTypes)
~TestUnaryOperation() noexcept override
bool operator==(const Operation &other) const noexcept override
static Output * create_normalized(std::shared_ptr< const Type > operandType, Output *operand, std::shared_ptr< const Type > resultType)
std::unique_ptr< Operation > copy() const override
std::string debug_string() const override
static Node * create(Region *, std::shared_ptr< const Type > operandType, Output *operand, std::shared_ptr< const Type > resultType)
Unary operator.
Definition unary.hpp:24
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Definition node.hpp:1049
size_t binop_reduction_path_t
Definition binary.hpp:19
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872