Jlm
Loading...
Searching...
No Matches
NodeNormalization.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_RVSDG_NODENORMALIZATION_HPP
7#define JLM_RVSDG_NODENORMALIZATION_HPP
8
9#include <jlm/rvsdg/node.hpp>
10#include <jlm/rvsdg/region.hpp>
12#include <jlm/util/common.hpp>
13
14#include <functional>
15#include <optional>
16#include <vector>
17
18namespace jlm::rvsdg
19{
20
21class Output;
22
23template<class TOperation>
24using NodeNormalization = std::function<
25 std::optional<std::vector<Output *>>(const TOperation &, const std::vector<Output *> &)>;
26
27template<class TOperation>
28std::optional<std::vector<Output *>>
31 const TOperation & operation,
32 const std::vector<Output *> & operands)
33{
35 {
36 if (auto results = nodeNormalization(operation, operands))
37 {
38 return results;
39 }
40 }
41
42 return std::nullopt;
43}
44
45template<class TOperation>
46bool
48{
49 auto operation = util::assertedCast<const TOperation>(&node.GetOperation());
50 auto operands = rvsdg::operands(&node);
51
52 if (auto results = nodeNormalization(*operation, operands))
53 {
54 divert_users(&node, *results);
55 remove(&node);
56 return true;
57 }
58
59 return false;
60}
61
62}
63
64#endif
const SimpleOperation & GetOperation() const noexcept override
bool ReduceNode(const NodeNormalization< TOperation > &nodeNormalization, SimpleNode &node)
static void remove(Node *node)
Definition region.hpp:1035
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Definition node.hpp:1049
std::optional< std::vector< Output * > > NormalizeSequence(const std::vector< NodeNormalization< TOperation > > &nodeNormalizations, const TOperation &operation, const std::vector< Output * > &operands)
static void divert_users(Node *node, const std::vector< Output * > &outputs)
Definition node.hpp:1090
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
std::function< std::optional< std::vector< Output * > >(const TOperation &, const std::vector< Output * > &)> NodeNormalization