Skip to content

Commit

Permalink
Merge branch 'master' into mem-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
sjalander authored Dec 22, 2024
2 parents 7250777 + 4821290 commit 89527cf
Show file tree
Hide file tree
Showing 23 changed files with 428 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
Checks: '-*,
modernize-deprecated-headers,
modernize-redundant-void-arg,
'

WarningsAsErrors: '
modernize-deprecated-headers,
modernize-redundant-void-arg,
'
65 changes: 64 additions & 1 deletion jlm/rvsdg/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,69 @@ binary_op::flags() const noexcept
return jlm::rvsdg::binary_op::flags::none;
}

std::optional<std::vector<rvsdg::output *>>
FlattenAssociativeBinaryOperation(
const binary_op & operation,
const std::vector<rvsdg::output *> & 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<Node>(*operand);
if (node == nullptr)
return false;

auto flattenedBinaryOperation =
dynamic_cast<const flattened_binary_op *>(&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<flattened_binary_op>(operation, newOperands.size());
return outputs(SimpleNode::create(region, *flattenedBinaryOperation, newOperands));
}

std::optional<std::vector<rvsdg::output *>>
NormalizeBinaryOperation(const binary_op & operation, const std::vector<rvsdg::output *> & 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
Expand Down Expand Up @@ -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),
Expand Down
39 changes: 39 additions & 0 deletions jlm/rvsdg/binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <jlm/rvsdg/simple-normal-form.hpp>
#include <jlm/util/common.hpp>

#include <optional>

namespace jlm::rvsdg
{

Expand Down Expand Up @@ -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<std::vector<rvsdg::output *>>
FlattenAssociativeBinaryOperation(
const binary_op & operation,
const std::vector<rvsdg::output *> & 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<std::vector<rvsdg::output *>>
NormalizeBinaryOperation(
const binary_op & operation,
const std::vector<rvsdg::output *> & operands);

class flattened_binary_op final : public SimpleOperation
{
public:
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/bitstring/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/gamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/nullary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/simple-normal-form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/statemux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/structural-normal-form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion jlm/rvsdg/unary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions jlm/util/intrusive-hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions jlm/util/intrusive-list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class intrusive_list
{}

inline const iterator &
operator++(void) noexcept
operator++() noexcept
{
element_ = list_->accessor_.get_next(element_);
return *this;
Expand All @@ -131,7 +131,7 @@ class intrusive_list
}

inline const iterator &
operator--(void) noexcept
operator--() noexcept
{
if (element_)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ class intrusive_list
{}

inline const const_iterator &
operator++(void) noexcept
operator++() noexcept
{
element_ = list_->accessor_.get_next(element_);
return *this;
Expand All @@ -231,7 +231,7 @@ class intrusive_list
}

inline const const_iterator &
operator--(void) noexcept
operator--() noexcept
{
if (element_)
{
Expand Down
Loading

0 comments on commit 89527cf

Please sign in to comment.