diff --git a/.clang-tidy b/.clang-tidy index 2bcbaae63..dd474def7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,8 +1,10 @@ --- Checks: '-*, modernize-deprecated-headers, + modernize-redundant-void-arg, ' WarningsAsErrors: ' modernize-deprecated-headers, + modernize-redundant-void-arg, ' \ No newline at end of file diff --git a/jlm/rvsdg/binary.cpp b/jlm/rvsdg/binary.cpp index 67407691e..db35d1360 100644 --- a/jlm/rvsdg/binary.cpp +++ b/jlm/rvsdg/binary.cpp @@ -319,6 +319,69 @@ binary_op::flags() const noexcept return jlm::rvsdg::binary_op::flags::none; } +std::optional> +FlattenAssociativeBinaryOperation( + const binary_op & operation, + const std::vector & operands) +{ + JLM_ASSERT(!operands.empty()); + auto region = operands[0]->region(); + + if (!operation.is_associative()) + { + return std::nullopt; + } + + auto newOperands = base::detail::associative_flatten( + operands, + [&operation](rvsdg::output * operand) + { + auto node = TryGetOwnerNode(*operand); + if (node == nullptr) + return false; + + auto flattenedBinaryOperation = + dynamic_cast(&node->GetOperation()); + return node->GetOperation() == operation + || (flattenedBinaryOperation && flattenedBinaryOperation->bin_operation() == operation); + }); + + if (operands == newOperands) + { + JLM_ASSERT(newOperands.size() == 2); + return std::nullopt; + } + + JLM_ASSERT(newOperands.size() > 2); + auto flattenedBinaryOperation = + std::make_unique(operation, newOperands.size()); + return outputs(SimpleNode::create(region, *flattenedBinaryOperation, newOperands)); +} + +std::optional> +NormalizeBinaryOperation(const binary_op & operation, const std::vector & operands) +{ + JLM_ASSERT(!operands.empty()); + auto region = operands[0]->region(); + + auto newOperands = reduce_operands(operation, operands); + + if (newOperands == operands) + { + // The operands did not change, which means that none of the normalizations triggered. + return std::nullopt; + } + + if (newOperands.size() == 1) + { + // The operands could be reduced to a single value by applying constant folding. + return newOperands; + } + + JLM_ASSERT(newOperands.size() == 2); + return outputs(SimpleNode::create(region, operation, newOperands)); +} + /* flattened binary operator */ flattened_binary_op::~flattened_binary_op() noexcept @@ -459,7 +522,7 @@ flattened_binary_operation_get_default_normal_form_( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::binary_op), diff --git a/jlm/rvsdg/binary.hpp b/jlm/rvsdg/binary.hpp index be2ef06c2..07f0fbe74 100644 --- a/jlm/rvsdg/binary.hpp +++ b/jlm/rvsdg/binary.hpp @@ -12,6 +12,8 @@ #include #include +#include + namespace jlm::rvsdg { @@ -167,6 +169,43 @@ class binary_op : public SimpleOperation } }; +/** + * \brief Flattens a cascade of the same binary operations into a single flattened binary operation. + * + * o1 = binaryNode i1 i2 + * o2 = binaryNode o1 i3 + * => + * o2 = flattenedBinaryNode i1 i2 i3 + * + * \pre The binary operation must be associative. + * + * @param operation The binary operation on which the transformation is performed. + * @param operands The operands of the binary node. + * @return If the normalization could be applied, then the results of the binary operation after + * the transformation. Otherwise, std::nullopt. + */ +std::optional> +FlattenAssociativeBinaryOperation( + const binary_op & operation, + const std::vector & operands); + +/** + * \brief Applies the reductions implemented in the binary operations reduction functions. + * + * @param operation The binary operation on which the transformation is performed. + * @param operands The operands of the binary node. + * + * @return If the normalization could be applied, then the results of the binary operation after + * the transformation. Otherwise, std::nullopt. + * + * \see binary_op::can_reduce_operand_pair() + * \see binary_op::reduce_operand_pair() + */ +std::optional> +NormalizeBinaryOperation( + const binary_op & operation, + const std::vector & operands); + class flattened_binary_op final : public SimpleOperation { public: diff --git a/jlm/rvsdg/bitstring/concat.cpp b/jlm/rvsdg/bitstring/concat.cpp index e188db419..f250de767 100644 --- a/jlm/rvsdg/bitstring/concat.cpp +++ b/jlm/rvsdg/bitstring/concat.cpp @@ -237,7 +237,7 @@ get_default_normal_form( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::bitconcat_op), diff --git a/jlm/rvsdg/gamma.cpp b/jlm/rvsdg/gamma.cpp index ea2b71e9f..3cf53e929 100644 --- a/jlm/rvsdg/gamma.cpp +++ b/jlm/rvsdg/gamma.cpp @@ -471,7 +471,7 @@ gamma_node_get_default_normal_form_( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::GammaOperation), diff --git a/jlm/rvsdg/node.cpp b/jlm/rvsdg/node.cpp index f09dca107..46e4b2a7c 100644 --- a/jlm/rvsdg/node.cpp +++ b/jlm/rvsdg/node.cpp @@ -147,7 +147,7 @@ node_get_default_normal_form_( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::Operation), diff --git a/jlm/rvsdg/nullary.cpp b/jlm/rvsdg/nullary.cpp index c78350ec0..a8baa960f 100644 --- a/jlm/rvsdg/nullary.cpp +++ b/jlm/rvsdg/nullary.cpp @@ -44,7 +44,7 @@ nullary_operation_get_default_normal_form_( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::nullary_op), diff --git a/jlm/rvsdg/simple-normal-form.cpp b/jlm/rvsdg/simple-normal-form.cpp index 07ca14cdb..d2eeee55b 100644 --- a/jlm/rvsdg/simple-normal-form.cpp +++ b/jlm/rvsdg/simple-normal-form.cpp @@ -119,7 +119,7 @@ get_default_normal_form( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::SimpleOperation), diff --git a/jlm/rvsdg/statemux.cpp b/jlm/rvsdg/statemux.cpp index 83e27ed92..79621b99d 100644 --- a/jlm/rvsdg/statemux.cpp +++ b/jlm/rvsdg/statemux.cpp @@ -210,7 +210,7 @@ create_mux_normal_form( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::mux_op), diff --git a/jlm/rvsdg/structural-normal-form.cpp b/jlm/rvsdg/structural-normal-form.cpp index 122a39a69..bf2aee5d9 100644 --- a/jlm/rvsdg/structural-normal-form.cpp +++ b/jlm/rvsdg/structural-normal-form.cpp @@ -31,7 +31,7 @@ get_default_normal_form( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::StructuralOperation), diff --git a/jlm/rvsdg/unary.cpp b/jlm/rvsdg/unary.cpp index e2f4a4304..45f5eb7d6 100644 --- a/jlm/rvsdg/unary.cpp +++ b/jlm/rvsdg/unary.cpp @@ -110,7 +110,7 @@ unary_operation_get_default_normal_form_( } static void __attribute__((constructor)) -register_node_normal_form(void) +register_node_normal_form() { jlm::rvsdg::node_normal_form::register_factory( typeid(jlm::rvsdg::unary_op), diff --git a/jlm/util/intrusive-hash.hpp b/jlm/util/intrusive-hash.hpp index 54d979fc9..bbd8a76c3 100644 --- a/jlm/util/intrusive-hash.hpp +++ b/jlm/util/intrusive-hash.hpp @@ -173,7 +173,7 @@ class intrusive_hash {} inline const iterator & - operator++(void) noexcept + operator++() noexcept { ElementType * next = map_->accessor_.get_next(element_); if (next == nullptr) @@ -262,7 +262,7 @@ class intrusive_hash {} inline const const_iterator & - operator++(void) noexcept + operator++() noexcept { ElementType * next = map_->accessor_.get_next(element_); if (next == nullptr) diff --git a/jlm/util/intrusive-list.hpp b/jlm/util/intrusive-list.hpp index d26adb338..3b743b471 100644 --- a/jlm/util/intrusive-list.hpp +++ b/jlm/util/intrusive-list.hpp @@ -116,7 +116,7 @@ class intrusive_list {} inline const iterator & - operator++(void) noexcept + operator++() noexcept { element_ = list_->accessor_.get_next(element_); return *this; @@ -131,7 +131,7 @@ class intrusive_list } inline const iterator & - operator--(void) noexcept + operator--() noexcept { if (element_) { @@ -216,7 +216,7 @@ class intrusive_list {} inline const const_iterator & - operator++(void) noexcept + operator++() noexcept { element_ = list_->accessor_.get_next(element_); return *this; @@ -231,7 +231,7 @@ class intrusive_list } inline const const_iterator & - operator--(void) noexcept + operator--() noexcept { if (element_) { diff --git a/tests/jlm/rvsdg/bitstring/bitstring.cpp b/tests/jlm/rvsdg/bitstring/bitstring.cpp index 93fda72cb..1a6dbcead 100644 --- a/tests/jlm/rvsdg/bitstring/bitstring.cpp +++ b/tests/jlm/rvsdg/bitstring/bitstring.cpp @@ -11,7 +11,7 @@ #include static int -types_bitstring_arithmetic_test_bitand(void) +types_bitstring_arithmetic_test_bitand() { using namespace jlm::rvsdg; @@ -39,7 +39,7 @@ types_bitstring_arithmetic_test_bitand(void) } static int -types_bitstring_arithmetic_test_bitashr(void) +types_bitstring_arithmetic_test_bitashr() { using namespace jlm::rvsdg; @@ -78,7 +78,7 @@ types_bitstring_arithmetic_test_bitashr(void) } static int -types_bitstring_arithmetic_test_bitdifference(void) +types_bitstring_arithmetic_test_bitdifference() { using namespace jlm::rvsdg; @@ -101,7 +101,7 @@ types_bitstring_arithmetic_test_bitdifference(void) } static int -types_bitstring_arithmetic_test_bitnegate(void) +types_bitstring_arithmetic_test_bitnegate() { using namespace jlm::rvsdg; @@ -129,7 +129,7 @@ types_bitstring_arithmetic_test_bitnegate(void) } static int -types_bitstring_arithmetic_test_bitnot(void) +types_bitstring_arithmetic_test_bitnot() { using namespace jlm::rvsdg; @@ -157,7 +157,7 @@ types_bitstring_arithmetic_test_bitnot(void) } static int -types_bitstring_arithmetic_test_bitor(void) +types_bitstring_arithmetic_test_bitor() { using namespace jlm::rvsdg; @@ -185,7 +185,7 @@ types_bitstring_arithmetic_test_bitor(void) } static int -types_bitstring_arithmetic_test_bitproduct(void) +types_bitstring_arithmetic_test_bitproduct() { using namespace jlm::rvsdg; @@ -214,7 +214,7 @@ types_bitstring_arithmetic_test_bitproduct(void) } static int -types_bitstring_arithmetic_test_bitshiproduct(void) +types_bitstring_arithmetic_test_bitshiproduct() { using namespace jlm::rvsdg; @@ -237,7 +237,7 @@ types_bitstring_arithmetic_test_bitshiproduct(void) } static int -types_bitstring_arithmetic_test_bitshl(void) +types_bitstring_arithmetic_test_bitshl() { using namespace jlm::rvsdg; @@ -269,7 +269,7 @@ types_bitstring_arithmetic_test_bitshl(void) } static int -types_bitstring_arithmetic_test_bitshr(void) +types_bitstring_arithmetic_test_bitshr() { using namespace jlm::rvsdg; @@ -301,7 +301,7 @@ types_bitstring_arithmetic_test_bitshr(void) } static int -types_bitstring_arithmetic_test_bitsmod(void) +types_bitstring_arithmetic_test_bitsmod() { using namespace jlm::rvsdg; @@ -330,7 +330,7 @@ types_bitstring_arithmetic_test_bitsmod(void) } static int -types_bitstring_arithmetic_test_bitsquotient(void) +types_bitstring_arithmetic_test_bitsquotient() { using namespace jlm::rvsdg; @@ -359,7 +359,7 @@ types_bitstring_arithmetic_test_bitsquotient(void) } static int -types_bitstring_arithmetic_test_bitsum(void) +types_bitstring_arithmetic_test_bitsum() { using namespace jlm::rvsdg; @@ -388,7 +388,7 @@ types_bitstring_arithmetic_test_bitsum(void) } static int -types_bitstring_arithmetic_test_bituhiproduct(void) +types_bitstring_arithmetic_test_bituhiproduct() { using namespace jlm::rvsdg; @@ -411,7 +411,7 @@ types_bitstring_arithmetic_test_bituhiproduct(void) } static int -types_bitstring_arithmetic_test_bitumod(void) +types_bitstring_arithmetic_test_bitumod() { using namespace jlm::rvsdg; @@ -440,7 +440,7 @@ types_bitstring_arithmetic_test_bitumod(void) } static int -types_bitstring_arithmetic_test_bituquotient(void) +types_bitstring_arithmetic_test_bituquotient() { using namespace jlm::rvsdg; @@ -469,7 +469,7 @@ types_bitstring_arithmetic_test_bituquotient(void) } static int -types_bitstring_arithmetic_test_bitxor(void) +types_bitstring_arithmetic_test_bitxor() { using namespace jlm::rvsdg; @@ -513,7 +513,7 @@ expect_static_false(jlm::rvsdg::output * port) } static int -types_bitstring_comparison_test_bitequal(void) +types_bitstring_comparison_test_bitequal() { using namespace jlm::rvsdg; @@ -547,7 +547,7 @@ types_bitstring_comparison_test_bitequal(void) } static int -types_bitstring_comparison_test_bitnotequal(void) +types_bitstring_comparison_test_bitnotequal() { using namespace jlm::rvsdg; @@ -581,7 +581,7 @@ types_bitstring_comparison_test_bitnotequal(void) } static int -types_bitstring_comparison_test_bitsgreater(void) +types_bitstring_comparison_test_bitsgreater() { using namespace jlm::rvsdg; @@ -619,7 +619,7 @@ types_bitstring_comparison_test_bitsgreater(void) } static int -types_bitstring_comparison_test_bitsgreatereq(void) +types_bitstring_comparison_test_bitsgreatereq() { using namespace jlm::rvsdg; @@ -660,7 +660,7 @@ types_bitstring_comparison_test_bitsgreatereq(void) } static int -types_bitstring_comparison_test_bitsless(void) +types_bitstring_comparison_test_bitsless() { using namespace jlm::rvsdg; @@ -698,7 +698,7 @@ types_bitstring_comparison_test_bitsless(void) } static int -types_bitstring_comparison_test_bitslesseq(void) +types_bitstring_comparison_test_bitslesseq() { using namespace jlm::rvsdg; @@ -739,7 +739,7 @@ types_bitstring_comparison_test_bitslesseq(void) } static int -types_bitstring_comparison_test_bitugreater(void) +types_bitstring_comparison_test_bitugreater() { using namespace jlm::rvsdg; @@ -777,7 +777,7 @@ types_bitstring_comparison_test_bitugreater(void) } static int -types_bitstring_comparison_test_bitugreatereq(void) +types_bitstring_comparison_test_bitugreatereq() { using namespace jlm::rvsdg; @@ -818,7 +818,7 @@ types_bitstring_comparison_test_bitugreatereq(void) } static int -types_bitstring_comparison_test_bituless(void) +types_bitstring_comparison_test_bituless() { using namespace jlm::rvsdg; @@ -856,7 +856,7 @@ types_bitstring_comparison_test_bituless(void) } static int -types_bitstring_comparison_test_bitulesseq(void) +types_bitstring_comparison_test_bitulesseq() { using namespace jlm::rvsdg; @@ -925,7 +925,7 @@ types_bitstring_comparison_test_bitulesseq(void) "11111111" static int -types_bitstring_test_constant(void) +types_bitstring_test_constant() { using namespace jlm::rvsdg; @@ -961,7 +961,7 @@ types_bitstring_test_constant(void) } static int -types_bitstring_test_normalize(void) +types_bitstring_test_normalize() { using namespace jlm::rvsdg; @@ -1020,7 +1020,7 @@ assert_constant(jlm::rvsdg::output * bitstr, size_t nbits, const char bits[]) } static int -types_bitstring_test_reduction(void) +types_bitstring_test_reduction() { using namespace jlm::rvsdg; @@ -1074,7 +1074,7 @@ types_bitstring_test_reduction(void) } static int -types_bitstring_test_slice_concat(void) +types_bitstring_test_slice_concat() { using namespace jlm::rvsdg; diff --git a/tests/jlm/rvsdg/test-binary.cpp b/tests/jlm/rvsdg/test-binary.cpp index eee0cd3ff..64ba71182 100644 --- a/tests/jlm/rvsdg/test-binary.cpp +++ b/tests/jlm/rvsdg/test-binary.cpp @@ -7,10 +7,80 @@ #include "test-registry.hpp" #include "test-types.hpp" +#include #include -static void -test_flattened_binary_reduction() +class BinaryOperation final : public jlm::rvsdg::binary_op +{ +public: + BinaryOperation( + const std::shared_ptr operandType, + const std::shared_ptr resultType, + const enum jlm::rvsdg::binary_op::flags & flags) + : jlm::rvsdg::binary_op({ operandType, operandType }, resultType), + Flags_(flags) + {} + + jlm::rvsdg::binop_reduction_path_t + can_reduce_operand_pair(const jlm::rvsdg::output * operand1, const jlm::rvsdg::output * operand2) + const noexcept override + { + auto n1 = jlm::rvsdg::TryGetOwnerNode(*operand1); + auto n2 = jlm::rvsdg::TryGetOwnerNode(*operand2); + + if (jlm::rvsdg::is(n1) && jlm::rvsdg::is(n2)) + { + return 1; + } + + return 0; + } + + jlm::rvsdg::output * + reduce_operand_pair( + jlm::rvsdg::unop_reduction_path_t path, + jlm::rvsdg::output * op1, + jlm::rvsdg::output * op2) const override + { + + if (path == 1) + { + return op2; + } + + return nullptr; + } + + [[nodiscard]] enum jlm::rvsdg::binary_op::flags + flags() const noexcept override + { + return Flags_; + } + + bool + operator==(const Operation & other) const noexcept override + { + JLM_UNREACHABLE("Not implemented."); + } + + [[nodiscard]] std::string + debug_string() const override + { + return "BinaryOperation"; + } + + [[nodiscard]] std::unique_ptr + copy() const override + { + return std::make_unique(this->argument(0), this->result(0), Flags_); + } + +private: + enum jlm::rvsdg::binary_op::flags Flags_; +}; + +static int +FlattenedBinaryReduction() { using namespace jlm::rvsdg; @@ -84,14 +154,201 @@ test_flattened_binary_reduction() auto node2 = output::GetNode(*node1->input(0)->origin()); assert(is(node2)); } + + return 0; +} + +JLM_UNIT_TEST_REGISTER("jlm/rvsdg/test-binary-FlattenedBinaryReduction", FlattenedBinaryReduction) + +static int +FlattenAssociativeBinaryOperation_NotAssociativeBinary() +{ + using namespace jlm::rvsdg; + + // Arrange + auto valueType = jlm::tests::valuetype::Create(); + + Graph graph; + auto i0 = &jlm::tests::GraphImport::Create(graph, valueType, "i0"); + auto i1 = &jlm::tests::GraphImport::Create(graph, valueType, "i1"); + auto i2 = &jlm::tests::GraphImport::Create(graph, valueType, "i2"); + + jlm::tests::binary_op binaryOperation(valueType, valueType, binary_op::flags::none); + auto o1 = SimpleNode::create(graph.root(), binaryOperation, { i0, i1 }); + auto o2 = SimpleNode::create(graph.root(), binaryOperation, { o1->output(0), i2 }); + + auto & ex = jlm::tests::GraphExport::Create(*o2->output(0), "o2"); + + jlm::rvsdg::view(graph, stdout); + + // Act + auto node = TryGetOwnerNode(*ex.origin()); + auto success = ReduceNode(FlattenAssociativeBinaryOperation, *node); + + jlm::rvsdg::view(graph, stdout); + + // Assert + assert(success == false); + assert(TryGetOwnerNode(*ex.origin()) == node); + + return 0; +} + +JLM_UNIT_TEST_REGISTER( + "jlm/rvsdg/test-binary-FlattenAssociatedBinaryOperation_NotAssociativeBinary", + FlattenAssociativeBinaryOperation_NotAssociativeBinary) + +static int +FlattenAssociativeBinaryOperation_NoNewOperands() +{ + using namespace jlm::rvsdg; + + // Arrange + auto valueType = jlm::tests::valuetype::Create(); + + Graph graph; + auto i0 = &jlm::tests::GraphImport::Create(graph, valueType, "i0"); + auto i1 = &jlm::tests::GraphImport::Create(graph, valueType, "i1"); + + jlm::tests::unary_op unaryOperation(valueType, valueType); + jlm::tests::binary_op binaryOperation(valueType, valueType, binary_op::flags::associative); + auto u1 = SimpleNode::create(graph.root(), unaryOperation, { i0 }); + auto u2 = SimpleNode::create(graph.root(), unaryOperation, { i1 }); + auto b2 = SimpleNode::create(graph.root(), binaryOperation, { u1->output(0), u2->output(0) }); + + auto & ex = jlm::tests::GraphExport::Create(*b2->output(0), "o2"); + + jlm::rvsdg::view(graph, stdout); + + // Act + auto node = TryGetOwnerNode(*ex.origin()); + auto success = ReduceNode(FlattenAssociativeBinaryOperation, *node); + + jlm::rvsdg::view(graph, stdout); + + // Assert + assert(success == false); + assert(TryGetOwnerNode(*ex.origin()) == node); + + return 0; +} + +JLM_UNIT_TEST_REGISTER( + "jlm/rvsdg/test-binary-FlattenAssociatedBinaryOperation_NoNewOperands", + FlattenAssociativeBinaryOperation_NoNewOperands) + +static int +FlattenAssociativeBinaryOperation_Success() +{ + using namespace jlm::rvsdg; + + // Arrange + auto valueType = jlm::tests::valuetype::Create(); + + Graph graph; + auto i0 = &jlm::tests::GraphImport::Create(graph, valueType, "i0"); + auto i1 = &jlm::tests::GraphImport::Create(graph, valueType, "i1"); + auto i2 = &jlm::tests::GraphImport::Create(graph, valueType, "i2"); + + jlm::tests::binary_op binaryOperation(valueType, valueType, binary_op::flags::associative); + auto o1 = SimpleNode::create(graph.root(), binaryOperation, { i0, i1 }); + auto o2 = SimpleNode::create(graph.root(), binaryOperation, { o1->output(0), i2 }); + + auto & ex = jlm::tests::GraphExport::Create(*o2->output(0), "o2"); + + jlm::rvsdg::view(graph, stdout); + + // Act + auto node = TryGetOwnerNode(*ex.origin()); + auto success = ReduceNode(FlattenAssociativeBinaryOperation, *node); + + jlm::rvsdg::view(graph, stdout); + + // Assert + assert(success); + auto flattenedBinaryNode = TryGetOwnerNode(*ex.origin()); + assert(is(flattenedBinaryNode)); + assert(flattenedBinaryNode->ninputs() == 3); + + return 0; +} + +JLM_UNIT_TEST_REGISTER( + "jlm/rvsdg/test-binary-FlattenAssociatedBinaryOperation_Success", + FlattenAssociativeBinaryOperation_Success) + +static int +NormalizeBinaryOperation_NoNewOperands() +{ + using namespace jlm::rvsdg; + + // Arrange + auto valueType = jlm::tests::valuetype::Create(); + + Graph graph; + auto i0 = &jlm::tests::GraphImport::Create(graph, valueType, "i0"); + auto i1 = &jlm::tests::GraphImport::Create(graph, valueType, "i1"); + + jlm::tests::binary_op binaryOperation(valueType, valueType, binary_op::flags::associative); + auto o1 = SimpleNode::create(graph.root(), binaryOperation, { i0, i1 }); + + auto & ex = jlm::tests::GraphExport::Create(*o1->output(0), "o2"); + + jlm::rvsdg::view(graph, stdout); + + // Act + auto node = TryGetOwnerNode(*ex.origin()); + auto success = ReduceNode(NormalizeBinaryOperation, *node); + + jlm::rvsdg::view(graph, stdout); + + // Assert + assert(success == false); + + return 0; } +JLM_UNIT_TEST_REGISTER( + "jlm/rvsdg/test-binary-NormalizeBinaryOperation_NoNewOperands", + NormalizeBinaryOperation_NoNewOperands) + static int -test_main() +NormalizeBinaryOperation_SingleOperand() { - test_flattened_binary_reduction(); + using namespace jlm::rvsdg; + + // Arrange + auto valueType = jlm::tests::valuetype::Create(); + + jlm::tests::unary_op unaryOperation(valueType, valueType); + BinaryOperation binaryOperation(valueType, valueType, binary_op::flags::none); + + Graph graph; + auto s0 = &jlm::tests::GraphImport::Create(graph, valueType, "s0"); + auto s1 = &jlm::tests::GraphImport::Create(graph, valueType, "s1"); + + auto u1 = SimpleNode::create(graph.root(), unaryOperation, { s0 }); + auto u2 = SimpleNode::create(graph.root(), unaryOperation, { s1 }); + + auto o1 = SimpleNode::create(graph.root(), binaryOperation, { u1->output(0), u2->output(0) }); + + auto & ex = jlm::tests::GraphExport::Create(*o1->output(0), "ex"); + + jlm::rvsdg::view(graph, stdout); + + // Act + auto node = TryGetOwnerNode(*ex.origin()); + auto success = ReduceNode(NormalizeBinaryOperation, *node); + + jlm::rvsdg::view(graph, stdout); + + // Assert + assert(success == true); + assert(ex.origin() == u2->output(0)); return 0; } -JLM_UNIT_TEST_REGISTER("jlm/rvsdg/test-binary", test_main) +JLM_UNIT_TEST_REGISTER( + "jlm/rvsdg/test-binary-NormalizeBinaryOperation_SingleOperand", + NormalizeBinaryOperation_SingleOperand) diff --git a/tests/jlm/rvsdg/test-gamma.cpp b/tests/jlm/rvsdg/test-gamma.cpp index 1edfd31e6..40c9aa9c8 100644 --- a/tests/jlm/rvsdg/test-gamma.cpp +++ b/tests/jlm/rvsdg/test-gamma.cpp @@ -12,7 +12,7 @@ #include static void -test_gamma(void) +test_gamma() { using namespace jlm::rvsdg; @@ -49,7 +49,7 @@ test_gamma(void) } static void -test_predicate_reduction(void) +test_predicate_reduction() { using namespace jlm::rvsdg; @@ -81,7 +81,7 @@ test_predicate_reduction(void) } static void -test_invariant_reduction(void) +test_invariant_reduction() { using namespace jlm::rvsdg; diff --git a/tests/jlm/rvsdg/test-graph.cpp b/tests/jlm/rvsdg/test-graph.cpp index 6f8c206e7..c959a5d6e 100644 --- a/tests/jlm/rvsdg/test-graph.cpp +++ b/tests/jlm/rvsdg/test-graph.cpp @@ -66,7 +66,7 @@ test_recursive_prune() JLM_UNIT_TEST_REGISTER("rvsdg/test-graph_prune", test_recursive_prune) static int -test_empty_graph_pruning(void) +test_empty_graph_pruning() { jlm::rvsdg::Graph graph; @@ -84,7 +84,7 @@ test_empty_graph_pruning(void) JLM_UNIT_TEST_REGISTER("rvsdg/test-empty_graph_pruning", test_empty_graph_pruning) static int -test_prune_replace(void) +test_prune_replace() { using namespace jlm::rvsdg; @@ -113,7 +113,7 @@ test_prune_replace(void) JLM_UNIT_TEST_REGISTER("rvsdg/test-prune-replace", test_prune_replace) static int -test_graph(void) +test_graph() { using namespace jlm::rvsdg; diff --git a/tests/jlm/rvsdg/test-nodes.cpp b/tests/jlm/rvsdg/test-nodes.cpp index 2da66e3da..859cce484 100644 --- a/tests/jlm/rvsdg/test-nodes.cpp +++ b/tests/jlm/rvsdg/test-nodes.cpp @@ -10,7 +10,7 @@ #include static void -test_node_copy(void) +test_node_copy() { using namespace jlm::rvsdg; using namespace jlm::tests; diff --git a/tests/jlm/rvsdg/test-statemux.cpp b/tests/jlm/rvsdg/test-statemux.cpp index 82ee7da42..3ab31de1b 100644 --- a/tests/jlm/rvsdg/test-statemux.cpp +++ b/tests/jlm/rvsdg/test-statemux.cpp @@ -81,7 +81,7 @@ test_multiple_origin_reduction() } static int -test_main(void) +test_main() { test_mux_mux_reduction(); test_multiple_origin_reduction(); diff --git a/tests/jlm/rvsdg/test-topdown.cpp b/tests/jlm/rvsdg/test-topdown.cpp index d69c2ba22..64575f88a 100644 --- a/tests/jlm/rvsdg/test-topdown.cpp +++ b/tests/jlm/rvsdg/test-topdown.cpp @@ -190,7 +190,7 @@ test_mutable_traverse() } static int -test_main(void) +test_main() { test_initialization(); test_basic_traversal(); diff --git a/tests/jlm/rvsdg/test-typemismatch.cpp b/tests/jlm/rvsdg/test-typemismatch.cpp index ab55cb267..db6d79101 100644 --- a/tests/jlm/rvsdg/test-typemismatch.cpp +++ b/tests/jlm/rvsdg/test-typemismatch.cpp @@ -9,7 +9,7 @@ #include "test-types.hpp" static int -test_main(void) +test_main() { using namespace jlm::rvsdg; diff --git a/tests/jlm/util/test-intrusive-hash.cpp b/tests/jlm/util/test-intrusive-hash.cpp index d1f90a9b5..fa1a470ca 100644 --- a/tests/jlm/util/test-intrusive-hash.cpp +++ b/tests/jlm/util/test-intrusive-hash.cpp @@ -82,7 +82,7 @@ struct my_stritem typedef jlm::util::intrusive_hash my_strhash; static void -test_int_hash(void) +test_int_hash() { my_hash m; @@ -118,7 +118,7 @@ test_int_hash(void) } static void -test_str_hash(void) +test_str_hash() { my_strhash m; @@ -154,7 +154,7 @@ test_str_hash(void) } static int -test_main(void) +test_main() { test_int_hash(); test_str_hash(); diff --git a/tests/jlm/util/test-intrusive-list.cpp b/tests/jlm/util/test-intrusive-list.cpp index cb8ebb9ff..c41c8617c 100644 --- a/tests/jlm/util/test-intrusive-list.cpp +++ b/tests/jlm/util/test-intrusive-list.cpp @@ -39,7 +39,7 @@ typedef jlm::util::intrusive_list my_list; typedef jlm::util::owner_intrusive_list my_owner_list; static void -test_simple_list(void) +test_simple_list() { my_list l; @@ -80,7 +80,7 @@ test_simple_list(void) } static void -test_owner_list(void) +test_owner_list() { int v1 = 1; int v2 = 2; @@ -143,7 +143,7 @@ test_owner_list(void) } static int -test_main(void) +test_main() { test_simple_list(); test_owner_list();