From 735ce0a85df11f82b8836e47dc755bda9f1e07c7 Mon Sep 17 00:00:00 2001 From: caleridas <36173465+caleridas@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:36:42 +0200 Subject: [PATCH 1/4] Introduce accessor and convenience API for node type matching (#654) Introduce input::GetOwner and output::GetOwner as the canonical and type-generic way to determine what "kind" an output/input is (either output/input to a node or region argument/result). Introduce TryGetOwnerNode and TryGetRegionParentNode as convenience API to easily match different node kinds. --- jlm/rvsdg/node.cpp | 79 ++++++++++++++++++++ jlm/rvsdg/node.hpp | 171 +++++++++++++++++++++++++++++++++++++++++++ jlm/rvsdg/region.cpp | 12 +++ jlm/rvsdg/region.hpp | 140 +++++++++++++++++++++++++++++++++++ 4 files changed, 402 insertions(+) diff --git a/jlm/rvsdg/node.cpp b/jlm/rvsdg/node.cpp index 427bb30d5..ccf7b3e30 100644 --- a/jlm/rvsdg/node.cpp +++ b/jlm/rvsdg/node.cpp @@ -167,6 +167,12 @@ node_input::node_input( node_(node) {} +[[nodiscard]] std::variant +node_input::GetOwner() const noexcept +{ + return node_; +} + /* node_output class */ node_output::node_output(jlm::rvsdg::node * node, std::shared_ptr type) @@ -174,6 +180,12 @@ node_output::node_output(jlm::rvsdg::node * node, std::shared_ptr +node_output::GetOwner() const noexcept +{ + return node_; +} + /* node class */ node::node(std::unique_ptr op, rvsdg::Region * region) @@ -341,4 +353,71 @@ normalize(jlm::rvsdg::node * node) return nf->normalize_node(node); } +/** + \page def_use_inspection Inspecting the graph and matching against different operations + + When inspecting the graph for analysis it is necessary to identify + different nodes/operations and structures. Depending on the direction, + the two fundamental questions of interest are: + + - what is the origin of a value, what operation is computing it? + - what are the users of a particular value, what operations depend on it? + + This requires resolving the type of operation a specific \ref rvsdg::input + or \ref rvsdg::output belong to. Every \ref rvsdg::output is one of the following: + + - the output of a node representing an operation + - the entry argument into a region + + Likewise, every \ref rvsdg::input is one of the following: + + - the input of a node representing an operation + - the exit result of a region + + Analysis code can determine which of the two is the case using + \ref rvsdg::output::GetOwner and \ref rvsdg::input::GetOwner, respectively, + and then branch deeper based on its results. For convenience, code + can more directly match against the specific kinds of nodes using + the following convenience functions: + + - \ref rvsdg::TryGetOwnerNode checks if the owner of an output/input + is a graph node of the requested kind + - \ref rvsdg::TryGetRegionParentNode checks if the output/input is + a region entry argument / exit result, and if the parent node + of the region is of the requested kind + + Example: + \code + if (auto lambda = rvsdg::TryGetOwnerNode(def)) + { + // This is an output of a lambda node -- so this must + // be a function definition. + } + else if (auto gamma = rvsdg::TryGetOwnerNode(def)) + { + // This is an output of a gamma node -- so it is potentially + // dependent on evaluating a condition. + } + else if (auto gamma = rvsdg::TryGetRegionParentNode(def)) + { + // This is an entry argument to a region inside a gamma node. + } + \endcode + + Similarly, the following variants of the accessor functions + assert that the nodes are of requested type and will throw + an exception otherwise: + + - \ref rvsdg::AssertGetOwnerNode asserts that the owner of an + output/input is a graph node of the requested kind and + returns it. + - \ref rvsdg::AssertGetRegionParentNode asserts that the + output/input is a region entry argument / exit result, + and that the parent node of the region is of the requested + kind + + These are mostly suitable for unit tests rather, or for the + rare circumstances that the type of node can be assumed to + be known statically. +*/ } diff --git a/jlm/rvsdg/node.hpp b/jlm/rvsdg/node.hpp index 962d59a7c..81f4dd8d1 100644 --- a/jlm/rvsdg/node.hpp +++ b/jlm/rvsdg/node.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -101,6 +102,9 @@ class input [[nodiscard]] static rvsdg::node * GetNode(const rvsdg::input & input) noexcept; + [[nodiscard]] virtual std::variant + GetOwner() const noexcept = 0; + template class iterator { @@ -374,6 +378,9 @@ class output virtual std::string debug_string() const; + [[nodiscard]] virtual std::variant + GetOwner() const noexcept = 0; + /** * Retrieve the associated node from \p output if \p output is derived from * jlm::rvsdg::node_output. @@ -585,6 +592,9 @@ class node_input : public jlm::rvsdg::input return node_; } + [[nodiscard]] std::variant + GetOwner() const noexcept override; + private: jlm::rvsdg::node * node_; }; @@ -609,6 +619,9 @@ class node_output : public jlm::rvsdg::output return no != nullptr ? no->node() : nullptr; } + [[nodiscard]] std::variant + GetOwner() const noexcept override; + private: jlm::rvsdg::node * node_; }; @@ -878,6 +891,164 @@ class node std::vector> outputs_; }; +/** + * \brief Checks if this is an input to a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param input + * Input to be checked. + * + * \returns + * Owning node of requested type or nullptr. + * + * Checks if the specified input belongs to a node of requested type. + * If this is the case, returns a pointer to the node of matched type. + * If this is not the case (because either this as a region exit + * result or its owning node is not of the requested type), returns + * nullptr. + * + * See \ref def_use_inspection. + */ +template +inline NodeType * +TryGetOwnerNode(const rvsdg::input & input) noexcept +{ + auto owner = input.GetOwner(); + if (auto node = std::get_if(&owner)) + { + return dynamic_cast(*node); + } + else + { + return nullptr; + } +} + +/** + * \brief Checks if this is an output to a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param output + * Output to be checked. + * + * \returns + * Owning node of requested type or nullptr. + * + * Checks if the specified output belongs to a node of requested type. + * If this is the case, returns a pointer to the node of matched type. + * If this is not the case (because either this as a region entry + * argument or its owning node is not of the requested type), returns + * nullptr. + * + * See \ref def_use_inspection. + */ +template +inline NodeType * +TryGetOwnerNode(const rvsdg::output & output) noexcept +{ + auto owner = output.GetOwner(); + if (auto node = std::get_if(&owner)) + { + return dynamic_cast(*node); + } + else + { + return nullptr; + } +} + +/** + * \brief Asserts that this is an input to a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param input + * Input to be checked. + * + * \returns + * Owning node of requested type. + * + * Checks if the specified input belongs to a node of requested type. + * If this is the case, returns a reference to the node of matched type, + * otherwise throws std::logic_error. + * + * See \ref def_use_inspection. + */ +template +inline NodeType & +AssertGetOwnerNode(const rvsdg::input & input) +{ + auto node = TryGetOwnerNode(input); + if (!node) + { + throw std::logic_error(std::string("expected node of type ") + typeid(NodeType).name()); + } + return *node; +} + +/** + * \brief Asserts that this is an output of a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param output + * Output to be checked. + * + * \returns + * Owning node of requested type. + * + * Checks if the specified output belongs to a node of requested type. + * If this is the case, returns a reference to the node of matched type, + * otherwise throws std::logic_error. + * + * See \ref def_use_inspection. + */ +template +inline NodeType & +AssertGetOwnerNode(const rvsdg::output & output) +{ + auto node = TryGetOwnerNode(output); + if (!node) + { + throw std::logic_error(std::string("expected node of type ") + typeid(NodeType).name()); + } + return *node; +} + +inline Region * +TryGetOwnerRegion(const rvsdg::input & input) noexcept +{ + auto owner = input.GetOwner(); + if (auto region = std::get_if(&owner)) + { + return *region; + } + else + { + return nullptr; + } +} + +inline Region * +TryGetOwnerRegion(const rvsdg::output & output) noexcept +{ + auto owner = output.GetOwner(); + if (auto region = std::get_if(&owner)) + { + return *region; + } + else + { + return nullptr; + } +} + static inline std::vector operands(const jlm::rvsdg::node * node) { diff --git a/jlm/rvsdg/region.cpp b/jlm/rvsdg/region.cpp index 14f461fbd..0fe95526c 100644 --- a/jlm/rvsdg/region.cpp +++ b/jlm/rvsdg/region.cpp @@ -43,6 +43,12 @@ RegionArgument::RegionArgument( } } +[[nodiscard]] std::variant +RegionArgument::GetOwner() const noexcept +{ + return region(); +} + RegionResult::~RegionResult() noexcept { on_input_destroy(this); @@ -73,6 +79,12 @@ RegionResult::RegionResult( } } +[[nodiscard]] std::variant +RegionResult::GetOwner() const noexcept +{ + return region(); +} + Region::~Region() noexcept { on_region_destroy(this); diff --git a/jlm/rvsdg/region.hpp b/jlm/rvsdg/region.hpp index fd4a41a4a..939fc4457 100644 --- a/jlm/rvsdg/region.hpp +++ b/jlm/rvsdg/region.hpp @@ -84,6 +84,9 @@ class RegionArgument : public output virtual RegionArgument & Copy(rvsdg::Region & region, structural_input * input) = 0; + [[nodiscard]] std::variant + GetOwner() const noexcept override; + private: structural_input * input_; }; @@ -143,6 +146,9 @@ class RegionResult : public input virtual RegionResult & Copy(rvsdg::output & origin, structural_output * output) = 0; + [[nodiscard]] std::variant + GetOwner() const noexcept override; + private: structural_output * output_; }; @@ -648,6 +654,140 @@ nsimpnodes(const rvsdg::Region * region) noexcept; size_t ninputs(const rvsdg::Region * region) noexcept; +/** + * \brief Checks if this is a result of a region inside a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param input + * Input to be checked. + * + * \returns + * Node of requested type to which the region belongs. + * + * Checks if the specified input is a region exit result belonging + * to a node of specified type. + * If this is the case, returns a pointer to the node of matched type. + * If this is not the case (because either this is an input to a node + * or or because the node owning the region is of a different kind, + * or because this is the root region), returns nullptr. + * + * See \ref def_use_inspection. + */ +template +inline NodeType * +TryGetRegionParentNode(const rvsdg::input & input) noexcept +{ + auto region = TryGetOwnerRegion(input); + if (region) + { + return dynamic_cast(region->node()); + } + else + { + return nullptr; + } +} + +/** + * \brief Checks if this is an argument of a region inside a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param output + * Output to be checked. + * + * \returns + * Node of requested type to which the region belongs. + * + * Checks if the specified input is a region entry argument belonging + * to a node of specified type. + * If this is the case, returns a pointer to the node of matched type. + * If this is not the case (because either this is an input to a node + * or or because the node owning the region is of a different kind, + * or because this is the root region), returns nullptr. + * + * See \ref def_use_inspection. + */ +template +inline NodeType * +TryGetRegionParentNode(const rvsdg::output & output) noexcept +{ + auto region = TryGetOwnerRegion(output); + if (region) + { + return dynamic_cast(region->node()); + } + else + { + return nullptr; + } +} + +/** + * \brief Asserts that this is a result of a region inside a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param input + * Input to be checked. + * + * \returns + * Node of requested type to which the region belongs. + * + * Checks if the specified input is a region exit result belonging + * to a node of specified type. + * If this is the case, returns a reference to the node of matched type, + * otherwise throws an exception. + * + * See \ref def_use_inspection. + */ +template +inline NodeType & +AssertGetRegionParentNode(const rvsdg::input & input) +{ + auto node = TryGetRegionParentNode(input); + if (!node) + { + throw std::logic_error(std::string("expected node of type ") + typeid(NodeType).name()); + } + return *node; +} + +/** + * \brief Asserts that this is an argument of a region inside a node of specified type. + * + * \tparam NodeType + * The node type to be matched against. + * + * \param output + * Output to be checked. + * + * \returns + * Node of requested type to which the region belongs. + * + * Checks if the specified input is a region entry argument belonging + * to a node of specified type. + * If this is the case, returns a reference to the node of matched type, + * otherwise throws an exception. + * + * See \ref def_use_inspection. + */ +template +inline NodeType & +AssertGetRegionParentNode(const rvsdg::output & output) +{ + auto node = TryGetRegionParentNode(output); + if (!node) + { + throw std::logic_error(std::string("expected node of type ") + typeid(NodeType).name()); + } + return *node; +} + } // namespace #endif From b8f81a0b69d3c3212f0708800352cc792b586596 Mon Sep 17 00:00:00 2001 From: caleridas <36173465+caleridas@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:00:33 +0200 Subject: [PATCH 2/4] Make RegionArgument and RegionResult instantiable (#656) Make both RegionArgument and RegionResult non-abstract and provide "Create" functions. This allows slowly phasing out the derived argument and result classes, replacing them with just RegionArgument and RegionResult. This allows to remove a lot of boilerplate code as the number of classes to be implemented and matched shrinks noticably. Later refactoring should rename the input/output classes and also allow to clean them up so they do not even need to be virtual anymore. --- jlm/rvsdg/region.cpp | 36 ++++++++++++++++++++++++++ jlm/rvsdg/region.hpp | 60 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/jlm/rvsdg/region.cpp b/jlm/rvsdg/region.cpp index 0fe95526c..2fd3c34ff 100644 --- a/jlm/rvsdg/region.cpp +++ b/jlm/rvsdg/region.cpp @@ -49,6 +49,23 @@ RegionArgument::GetOwner() const noexcept return region(); } +RegionArgument & +RegionArgument::Copy(rvsdg::Region & region, structural_input * input) +{ + return RegionArgument::Create(region, input, Type()); +} + +RegionArgument & +RegionArgument::Create( + rvsdg::Region & region, + rvsdg::structural_input * input, + std::shared_ptr type) +{ + auto argument = new RegionArgument(®ion, input, std::move(type)); + region.append_argument(argument); + return *argument; +} + RegionResult::~RegionResult() noexcept { on_input_destroy(this); @@ -85,6 +102,25 @@ RegionResult::GetOwner() const noexcept return region(); } +RegionResult & +RegionResult::Copy(rvsdg::output & origin, structural_output * output) +{ + return RegionResult::Create(*origin.region(), origin, output, origin.Type()); +} + +RegionResult & +RegionResult::Create( + rvsdg::Region & region, + rvsdg::output & origin, + structural_output * output, + std::shared_ptr type) +{ + JLM_ASSERT(origin.region() == ®ion); + auto result = new RegionResult(®ion, &origin, output, std::move(type)); + region.append_result(result); + return *result; +} + Region::~Region() noexcept { on_region_destroy(this); diff --git a/jlm/rvsdg/region.hpp b/jlm/rvsdg/region.hpp index 939fc4457..5e9af4ea0 100644 --- a/jlm/rvsdg/region.hpp +++ b/jlm/rvsdg/region.hpp @@ -50,13 +50,11 @@ class RegionArgument : public output ~RegionArgument() noexcept override; -protected: RegionArgument( rvsdg::Region * region, structural_input * input, std::shared_ptr type); -public: RegionArgument(const RegionArgument &) = delete; RegionArgument(RegionArgument &&) = delete; @@ -82,11 +80,35 @@ class RegionArgument : public output * @return A reference to the copied argument. */ virtual RegionArgument & - Copy(rvsdg::Region & region, structural_input * input) = 0; + Copy(rvsdg::Region & region, structural_input * input); [[nodiscard]] std::variant GetOwner() const noexcept override; + /** + * \brief Creates region entry argument. + * + * \param region + * Region to create argument for. + * + * \param input + * (optional) input of parent node associated with this + * argument (deprecated, will be removed soon). + * + * \param type + * Result type. + * + * \returns + * Reference to the created argument. + * + * Creates an argument and registers it with the given region. + */ + static RegionArgument & + Create( + rvsdg::Region & region, + rvsdg::structural_input * input, + std::shared_ptr type); + private: structural_input * input_; }; @@ -110,14 +132,12 @@ class RegionResult : public input ~RegionResult() noexcept override; -protected: RegionResult( rvsdg::Region * region, rvsdg::output * origin, structural_output * output, std::shared_ptr type); -public: RegionResult(const RegionResult &) = delete; RegionResult(RegionResult &&) = delete; @@ -144,11 +164,39 @@ class RegionResult : public input * @return A reference to the copied result. */ virtual RegionResult & - Copy(rvsdg::output & origin, structural_output * output) = 0; + Copy(rvsdg::output & origin, structural_output * output); [[nodiscard]] std::variant GetOwner() const noexcept override; + /** + * \brief Create region exit result. + * + * \param region + * Region to create result for. + * + * \param origin + * Assigned result value. + * + * \param output + * (optional) output of parent node associated with this + * result (deprecated, will be removed soon). + * + * \param type + * Result type + * + * \returns + * Reference to the created result. + * + * Creates a result and registers it with the given region. + */ + static RegionResult & + Create( + rvsdg::Region & region, + rvsdg::output & origin, + structural_output * output, + std::shared_ptr type); + private: structural_output * output_; }; From d5a6f0a95213f569fa7af9df7daa468566cfeb46 Mon Sep 17 00:00:00 2001 From: Nico Reissmann Date: Sun, 13 Oct 2024 00:00:12 +0200 Subject: [PATCH 3/4] Rename structural_node class to StructuralNode (#657) --- .../rhls2firrtl/RhlsToFirrtlConverter.cpp | 2 +- .../backend/rvsdg2rhls/GammaConversion.cpp | 4 +- .../backend/rvsdg2rhls/ThetaConversion.cpp | 4 +- .../backend/rvsdg2rhls/UnusedStateRemoval.cpp | 4 +- jlm/hls/backend/rvsdg2rhls/add-buffers.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/add-forks.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/add-prints.cpp | 4 +- jlm/hls/backend/rvsdg2rhls/add-sinks.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/add-triggers.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/alloca-conv.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/check-rhls.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/dae-conv.cpp | 4 +- .../rvsdg2rhls/distribute-constants.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/instrument-ref.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/mem-conv.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/mem-sep.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/memstate-conv.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/merge-gamma.cpp | 2 +- .../rvsdg2rhls/remove-redundant-buf.cpp | 2 +- .../rvsdg2rhls/remove-unused-state.cpp | 2 +- jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.cpp | 4 +- jlm/hls/ir/hls.hpp | 6 +-- jlm/hls/opt/cne.cpp | 49 +++++++++---------- jlm/hls/util/view.cpp | 4 +- jlm/llvm/backend/dot/DotWriter.cpp | 2 +- jlm/llvm/backend/rvsdg2jlm/rvsdg2jlm.cpp | 6 +-- jlm/llvm/ir/operators/Phi.cpp | 4 +- jlm/llvm/ir/operators/Phi.hpp | 6 +-- jlm/llvm/ir/operators/delta.cpp | 4 +- jlm/llvm/ir/operators/delta.hpp | 8 +-- jlm/llvm/ir/operators/lambda.cpp | 4 +- jlm/llvm/ir/operators/lambda.hpp | 8 +-- jlm/llvm/opt/DeadNodeElimination.cpp | 6 +-- jlm/llvm/opt/DeadNodeElimination.hpp | 2 +- jlm/llvm/opt/InvariantValueRedirection.cpp | 2 +- jlm/llvm/opt/InvariantValueRedirection.hpp | 2 +- jlm/llvm/opt/RvsdgTreePrinter.cpp | 4 +- jlm/llvm/opt/alias-analyses/Andersen.cpp | 4 +- jlm/llvm/opt/alias-analyses/Andersen.hpp | 2 +- .../opt/alias-analyses/MemoryStateEncoder.cpp | 4 +- .../opt/alias-analyses/MemoryStateEncoder.hpp | 2 +- .../RegionAwareMemoryNodeProvider.cpp | 12 ++--- .../RegionAwareMemoryNodeProvider.hpp | 2 +- jlm/llvm/opt/alias-analyses/Steensgaard.cpp | 4 +- jlm/llvm/opt/alias-analyses/Steensgaard.hpp | 2 +- .../TopDownMemoryNodeEliminator.cpp | 4 +- .../TopDownMemoryNodeEliminator.hpp | 4 +- jlm/llvm/opt/cne.cpp | 43 ++++++++-------- jlm/llvm/opt/inversion.cpp | 4 +- jlm/llvm/opt/pull.cpp | 2 +- jlm/llvm/opt/push.cpp | 2 +- jlm/llvm/opt/unroll.cpp | 2 +- jlm/rvsdg/binary.cpp | 2 +- jlm/rvsdg/gamma.hpp | 6 +-- jlm/rvsdg/region.cpp | 18 +++---- jlm/rvsdg/region.hpp | 12 ++--- jlm/rvsdg/structural-node.cpp | 14 +++--- jlm/rvsdg/structural-node.hpp | 32 ++++++------ jlm/rvsdg/theta.cpp | 2 +- jlm/rvsdg/theta.hpp | 4 +- jlm/rvsdg/view.cpp | 6 +-- tests/jlm/rvsdg/test-gamma.cpp | 2 +- tests/jlm/rvsdg/test-theta.cpp | 2 +- tests/test-operation.cpp | 2 - tests/test-operation.hpp | 4 +- 65 files changed, 182 insertions(+), 188 deletions(-) diff --git a/jlm/hls/backend/rhls2firrtl/RhlsToFirrtlConverter.cpp b/jlm/hls/backend/rhls2firrtl/RhlsToFirrtlConverter.cpp index 8f9f55703..3520d76d6 100644 --- a/jlm/hls/backend/rhls2firrtl/RhlsToFirrtlConverter.cpp +++ b/jlm/hls/backend/rhls2firrtl/RhlsToFirrtlConverter.cpp @@ -2517,7 +2517,7 @@ RhlsToFirrtlConverter::TraceArgument(rvsdg::RegionArgument * arg) else if (auto o = dynamic_cast(origin)) { // Check if we the input of one loop_node is connected to the output of another - // structural_node, i.e., if the input is connected to the output of another loop_node + // StructuralNode, i.e., if the input is connected to the output of another loop_node return TraceStructuralOutput(o); } // Else we have reached the source diff --git a/jlm/hls/backend/rvsdg2rhls/GammaConversion.cpp b/jlm/hls/backend/rvsdg2rhls/GammaConversion.cpp index 82440d20d..6df9bcfa4 100644 --- a/jlm/hls/backend/rvsdg2rhls/GammaConversion.cpp +++ b/jlm/hls/backend/rvsdg2rhls/GammaConversion.cpp @@ -134,7 +134,7 @@ static void ConvertGammaNodesInRegion(rvsdg::Region & region); static void -ConvertGammaNodesInStructuralNode(rvsdg::structural_node & structuralNode) +ConvertGammaNodesInStructuralNode(rvsdg::StructuralNode & structuralNode) { for (size_t n = 0; n < structuralNode.nsubregions(); n++) { @@ -159,7 +159,7 @@ ConvertGammaNodesInRegion(rvsdg::Region & region) { for (auto & node : rvsdg::topdown_traverser(®ion)) { - if (auto structuralNode = dynamic_cast(node)) + if (auto structuralNode = dynamic_cast(node)) { ConvertGammaNodesInStructuralNode(*structuralNode); } diff --git a/jlm/hls/backend/rvsdg2rhls/ThetaConversion.cpp b/jlm/hls/backend/rvsdg2rhls/ThetaConversion.cpp index c01ec0f83..18aa7e259 100644 --- a/jlm/hls/backend/rvsdg2rhls/ThetaConversion.cpp +++ b/jlm/hls/backend/rvsdg2rhls/ThetaConversion.cpp @@ -47,7 +47,7 @@ static void ConvertThetaNodesInRegion(rvsdg::Region & region); static void -ConvertThetaNodesInStructuralNode(jlm::rvsdg::structural_node & structuralNode) +ConvertThetaNodesInStructuralNode(rvsdg::StructuralNode & structuralNode) { for (size_t n = 0; n < structuralNode.nsubregions(); n++) { @@ -65,7 +65,7 @@ ConvertThetaNodesInRegion(rvsdg::Region & region) { for (auto & node : jlm::rvsdg::topdown_traverser(®ion)) { - if (auto structuralNode = dynamic_cast(node)) + if (auto structuralNode = dynamic_cast(node)) { ConvertThetaNodesInStructuralNode(*structuralNode); } diff --git a/jlm/hls/backend/rvsdg2rhls/UnusedStateRemoval.cpp b/jlm/hls/backend/rvsdg2rhls/UnusedStateRemoval.cpp index 0505b22fc..b4fc8dc12 100644 --- a/jlm/hls/backend/rvsdg2rhls/UnusedStateRemoval.cpp +++ b/jlm/hls/backend/rvsdg2rhls/UnusedStateRemoval.cpp @@ -191,7 +191,7 @@ static void RemoveUnusedStatesInRegion(rvsdg::Region & region); static void -RemoveUnusedStatesInStructuralNode(rvsdg::structural_node & structuralNode) +RemoveUnusedStatesInStructuralNode(rvsdg::StructuralNode & structuralNode) { // Remove unused states from innermost regions first for (size_t n = 0; n < structuralNode.nsubregions(); n++) @@ -218,7 +218,7 @@ RemoveUnusedStatesInRegion(rvsdg::Region & region) { for (auto & node : rvsdg::topdown_traverser(®ion)) { - if (auto structuralNode = dynamic_cast(node)) + if (auto structuralNode = dynamic_cast(node)) { RemoveUnusedStatesInStructuralNode(*structuralNode); } diff --git a/jlm/hls/backend/rvsdg2rhls/add-buffers.cpp b/jlm/hls/backend/rvsdg2rhls/add-buffers.cpp index 25dfff69b..a139c5a40 100644 --- a/jlm/hls/backend/rvsdg2rhls/add-buffers.cpp +++ b/jlm/hls/backend/rvsdg2rhls/add-buffers.cpp @@ -16,7 +16,7 @@ add_buffers(rvsdg::Region * region, bool pass_through) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/add-forks.cpp b/jlm/hls/backend/rvsdg2rhls/add-forks.cpp index 8996bcdda..8266c7ab3 100644 --- a/jlm/hls/backend/rvsdg2rhls/add-forks.cpp +++ b/jlm/hls/backend/rvsdg2rhls/add-forks.cpp @@ -30,7 +30,7 @@ add_forks(rvsdg::Region * region) } for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/add-prints.cpp b/jlm/hls/backend/rvsdg2rhls/add-prints.cpp index 0b41139c7..d3723485b 100644 --- a/jlm/hls/backend/rvsdg2rhls/add-prints.cpp +++ b/jlm/hls/backend/rvsdg2rhls/add-prints.cpp @@ -18,7 +18,7 @@ add_prints(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { @@ -106,7 +106,7 @@ convert_prints( { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/add-sinks.cpp b/jlm/hls/backend/rvsdg2rhls/add-sinks.cpp index b4afc740e..ffce1f6e0 100644 --- a/jlm/hls/backend/rvsdg2rhls/add-sinks.cpp +++ b/jlm/hls/backend/rvsdg2rhls/add-sinks.cpp @@ -23,7 +23,7 @@ add_sinks(rvsdg::Region * region) } for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/add-triggers.cpp b/jlm/hls/backend/rvsdg2rhls/add-triggers.cpp index a964486ad..a00b27390 100644 --- a/jlm/hls/backend/rvsdg2rhls/add-triggers.cpp +++ b/jlm/hls/backend/rvsdg2rhls/add-triggers.cpp @@ -89,7 +89,7 @@ add_triggers(rvsdg::Region * region) auto trigger = get_trigger(region); for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (dynamic_cast(node)) + if (rvsdg::is(node)) { if (auto ln = dynamic_cast(node)) { diff --git a/jlm/hls/backend/rvsdg2rhls/alloca-conv.cpp b/jlm/hls/backend/rvsdg2rhls/alloca-conv.cpp index 80c4c8a60..4f38650d6 100644 --- a/jlm/hls/backend/rvsdg2rhls/alloca-conv.cpp +++ b/jlm/hls/backend/rvsdg2rhls/alloca-conv.cpp @@ -120,7 +120,7 @@ alloca_conv(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/check-rhls.cpp b/jlm/hls/backend/rvsdg2rhls/check-rhls.cpp index b5018e5a9..a0d2d4992 100644 --- a/jlm/hls/backend/rvsdg2rhls/check-rhls.cpp +++ b/jlm/hls/backend/rvsdg2rhls/check-rhls.cpp @@ -17,7 +17,7 @@ check_rhls(rvsdg::Region * sr) { for (auto & node : jlm::rvsdg::topdown_traverser(sr)) { - if (dynamic_cast(node)) + if (rvsdg::is(node)) { if (auto ln = dynamic_cast(node)) { diff --git a/jlm/hls/backend/rvsdg2rhls/dae-conv.cpp b/jlm/hls/backend/rvsdg2rhls/dae-conv.cpp index b51418343..8d072be98 100644 --- a/jlm/hls/backend/rvsdg2rhls/dae-conv.cpp +++ b/jlm/hls/backend/rvsdg2rhls/dae-conv.cpp @@ -392,7 +392,7 @@ process_loopnode(loop_node * loopNode) bool can_decouple = true; for (auto sn : data_slice) { - if (dynamic_cast(sn)) + if (rvsdg::is(sn)) { // data slice may not contain loops can_decouple = false; @@ -420,7 +420,7 @@ process_loopnode(loop_node * loopNode) JLM_ASSERT(!can_decouple || !data_slice.count(simplenode)); for (auto sn : state_slice) { - if (dynamic_cast(sn)) + if (rvsdg::is(sn)) { // state slice may not contain loops can_decouple = false; diff --git a/jlm/hls/backend/rvsdg2rhls/distribute-constants.cpp b/jlm/hls/backend/rvsdg2rhls/distribute-constants.cpp index ba80c7b84..065aef600 100644 --- a/jlm/hls/backend/rvsdg2rhls/distribute-constants.cpp +++ b/jlm/hls/backend/rvsdg2rhls/distribute-constants.cpp @@ -77,7 +77,7 @@ hls::distribute_constants(rvsdg::Region * region) // buffers for them for (auto & node : rvsdg::topdown_traverser(region)) { - if (dynamic_cast(node)) + if (rvsdg::is(node)) { if (auto ln = dynamic_cast(node)) { diff --git a/jlm/hls/backend/rvsdg2rhls/instrument-ref.cpp b/jlm/hls/backend/rvsdg2rhls/instrument-ref.cpp index 9103b12a8..020c6071a 100644 --- a/jlm/hls/backend/rvsdg2rhls/instrument-ref.cpp +++ b/jlm/hls/backend/rvsdg2rhls/instrument-ref.cpp @@ -153,7 +153,7 @@ instrument_ref( auto void_ptr = jlm::llvm::PointerType::Create(); for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/mem-conv.cpp b/jlm/hls/backend/rvsdg2rhls/mem-conv.cpp index 6458dbed0..4f8caad69 100644 --- a/jlm/hls/backend/rvsdg2rhls/mem-conv.cpp +++ b/jlm/hls/backend/rvsdg2rhls/mem-conv.cpp @@ -332,7 +332,7 @@ gather_mem_nodes( { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) gather_mem_nodes( diff --git a/jlm/hls/backend/rvsdg2rhls/mem-sep.cpp b/jlm/hls/backend/rvsdg2rhls/mem-sep.cpp index cc5896362..18e761aee 100644 --- a/jlm/hls/backend/rvsdg2rhls/mem-sep.cpp +++ b/jlm/hls/backend/rvsdg2rhls/mem-sep.cpp @@ -71,7 +71,7 @@ gather_mem_nodes(rvsdg::Region * region, std::vector { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) gather_mem_nodes(structnode->subregion(n), mem_nodes); diff --git a/jlm/hls/backend/rvsdg2rhls/memstate-conv.cpp b/jlm/hls/backend/rvsdg2rhls/memstate-conv.cpp index 9abe4a5bc..7feada423 100644 --- a/jlm/hls/backend/rvsdg2rhls/memstate-conv.cpp +++ b/jlm/hls/backend/rvsdg2rhls/memstate-conv.cpp @@ -29,7 +29,7 @@ memstate_conv(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) memstate_conv(structnode->subregion(n)); diff --git a/jlm/hls/backend/rvsdg2rhls/merge-gamma.cpp b/jlm/hls/backend/rvsdg2rhls/merge-gamma.cpp index 16148a55f..c0beebcbb 100644 --- a/jlm/hls/backend/rvsdg2rhls/merge-gamma.cpp +++ b/jlm/hls/backend/rvsdg2rhls/merge-gamma.cpp @@ -201,7 +201,7 @@ merge_gamma(rvsdg::Region * region) changed = false; for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) merge_gamma(structnode->subregion(n)); diff --git a/jlm/hls/backend/rvsdg2rhls/remove-redundant-buf.cpp b/jlm/hls/backend/rvsdg2rhls/remove-redundant-buf.cpp index fa096103d..85f49215f 100644 --- a/jlm/hls/backend/rvsdg2rhls/remove-redundant-buf.cpp +++ b/jlm/hls/backend/rvsdg2rhls/remove-redundant-buf.cpp @@ -37,7 +37,7 @@ remove_redundant_buf(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/backend/rvsdg2rhls/remove-unused-state.cpp b/jlm/hls/backend/rvsdg2rhls/remove-unused-state.cpp index aaba59a54..09dbf890b 100644 --- a/jlm/hls/backend/rvsdg2rhls/remove-unused-state.cpp +++ b/jlm/hls/backend/rvsdg2rhls/remove-unused-state.cpp @@ -18,7 +18,7 @@ remove_unused_state(rvsdg::Region * region, bool can_remove_arguments) // process children first so that unnecessary users get removed for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { if (auto gn = dynamic_cast(node)) { diff --git a/jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.cpp b/jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.cpp index f2fd3d2f1..325e7c235 100644 --- a/jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.cpp +++ b/jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.cpp @@ -138,7 +138,7 @@ inline_calls(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { @@ -180,7 +180,7 @@ convert_alloca(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) { diff --git a/jlm/hls/ir/hls.hpp b/jlm/hls/ir/hls.hpp index a5930f36a..480d2b384 100644 --- a/jlm/hls/ir/hls.hpp +++ b/jlm/hls/ir/hls.hpp @@ -743,7 +743,7 @@ class ExitResult final : public rvsdg::RegionResult } }; -class loop_node final : public jlm::rvsdg::structural_node +class loop_node final : public rvsdg::StructuralNode { public: virtual ~loop_node() @@ -751,7 +751,7 @@ class loop_node final : public jlm::rvsdg::structural_node private: inline loop_node(rvsdg::Region * parent) - : structural_node(loop_op(), parent, 1) + : StructuralNode(loop_op(), parent, 1) {} jlm::rvsdg::node_output * _predicate_buffer; @@ -763,7 +763,7 @@ class loop_node final : public jlm::rvsdg::structural_node rvsdg::Region * subregion() const noexcept { - return structural_node::subregion(0); + return StructuralNode::subregion(0); } [[nodiscard]] rvsdg::RegionResult * diff --git a/jlm/hls/opt/cne.cpp b/jlm/hls/opt/cne.cpp index c63ca01cc..b660c5522 100644 --- a/jlm/hls/opt/cne.cpp +++ b/jlm/hls/opt/cne.cpp @@ -290,7 +290,7 @@ static void mark(jlm::rvsdg::Region *, cnectx &); static void -mark_gamma(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_gamma(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(rvsdg::is(node->operation())); @@ -316,7 +316,7 @@ mark_gamma(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_theta(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_theta(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); auto theta = static_cast(node); @@ -340,7 +340,7 @@ mark_theta(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_loop(const rvsdg::structural_node * node, cnectx & ctx) +mark_loop(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(rvsdg::is(node)); auto loop = static_cast(node); @@ -362,7 +362,7 @@ mark_loop(const rvsdg::structural_node * node, cnectx & ctx) } static void -mark_lambda(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_lambda(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); @@ -382,7 +382,7 @@ mark_lambda(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_phi(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_phi(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); @@ -402,22 +402,21 @@ mark_phi(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_delta(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_delta(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); } static void -mark(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark(const rvsdg::StructuralNode * node, cnectx & ctx) { - static std:: - unordered_map - map({ { std::type_index(typeid(rvsdg::GammaOperation)), mark_gamma }, - { std::type_index(typeid(ThetaOperation)), mark_theta }, - { std::type_index(typeid(jlm::hls::loop_op)), mark_loop }, - { typeid(llvm::lambda::operation), mark_lambda }, - { typeid(llvm::phi::operation), mark_phi }, - { typeid(llvm::delta::operation), mark_delta } }); + static std::unordered_map map( + { { std::type_index(typeid(rvsdg::GammaOperation)), mark_gamma }, + { std::type_index(typeid(ThetaOperation)), mark_theta }, + { std::type_index(typeid(jlm::hls::loop_op)), mark_loop }, + { typeid(llvm::lambda::operation), mark_lambda }, + { typeid(llvm::phi::operation), mark_phi }, + { typeid(llvm::delta::operation), mark_delta } }); auto & op = node->operation(); JLM_ASSERT(map.find(typeid(op)) != map.end()); @@ -471,7 +470,7 @@ mark(rvsdg::Region * region, cnectx & ctx) if (auto simple = dynamic_cast(node)) mark(simple, ctx); else - mark(static_cast(node), ctx); + mark(static_cast(node), ctx); } } @@ -504,7 +503,7 @@ static void divert(rvsdg::Region *, cnectx &); static void -divert_gamma(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_gamma(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(rvsdg::is(node)); auto gamma = static_cast(node); @@ -522,7 +521,7 @@ divert_gamma(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_theta(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_theta(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); auto theta = static_cast(node); @@ -539,7 +538,7 @@ divert_theta(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_loop(rvsdg::structural_node * node, cnectx & ctx) +divert_loop(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(rvsdg::is(node)); auto subregion = node->subregion(0); @@ -547,7 +546,7 @@ divert_loop(rvsdg::structural_node * node, cnectx & ctx) } static void -divert_lambda(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_lambda(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); @@ -556,7 +555,7 @@ divert_lambda(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_phi(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_phi(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); @@ -565,15 +564,15 @@ divert_phi(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_delta(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_delta(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); } static void -divert(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert(rvsdg::StructuralNode * node, cnectx & ctx) { - static std::unordered_map map( + static std::unordered_map map( { { std::type_index(typeid(rvsdg::GammaOperation)), divert_gamma }, { std::type_index(typeid(ThetaOperation)), divert_theta }, { std::type_index(typeid(jlm::hls::loop_op)), divert_loop }, @@ -594,7 +593,7 @@ divert(rvsdg::Region * region, cnectx & ctx) if (auto simple = dynamic_cast(node)) divert_outputs(simple, ctx); else - divert(static_cast(node), ctx); + divert(static_cast(node), ctx); } } diff --git a/jlm/hls/util/view.cpp b/jlm/hls/util/view.cpp index 62ab85cfe..7107813f5 100644 --- a/jlm/hls/util/view.cpp +++ b/jlm/hls/util/view.cpp @@ -161,7 +161,7 @@ isForbiddenChar(char c) } std::string -structural_node_to_dot(jlm::rvsdg::structural_node * structuralNode) +structural_node_to_dot(rvsdg::StructuralNode * structuralNode) { std::ostringstream dot; @@ -346,7 +346,7 @@ region_to_dot(rvsdg::Region * region) auto node_dot = simple_node_to_dot(simpleNode); dot << node_dot; } - else if (auto structuralNode = dynamic_cast(node)) + else if (auto structuralNode = dynamic_cast(node)) { auto node_dot = structural_node_to_dot(structuralNode); dot << node_dot; diff --git a/jlm/llvm/backend/dot/DotWriter.cpp b/jlm/llvm/backend/dot/DotWriter.cpp index f3fede3b2..2993ea5dd 100644 --- a/jlm/llvm/backend/dot/DotWriter.cpp +++ b/jlm/llvm/backend/dot/DotWriter.cpp @@ -172,7 +172,7 @@ CreateGraphNodes(util::Graph & graph, rvsdg::Region & region, util::Graph * type AttachNodeOutput(node.GetOutputPort(i), *rvsdgNode->output(i), typeGraph); // Structural nodes also have subgraphs - if (auto structuralNode = dynamic_cast(rvsdgNode)) + if (auto structuralNode = dynamic_cast(rvsdgNode)) { for (size_t i = 0; i < structuralNode->nsubregions(); i++) { diff --git a/jlm/llvm/backend/rvsdg2jlm/rvsdg2jlm.cpp b/jlm/llvm/backend/rvsdg2jlm/rvsdg2jlm.cpp index deea34f56..b5541ea25 100644 --- a/jlm/llvm/backend/rvsdg2jlm/rvsdg2jlm.cpp +++ b/jlm/llvm/backend/rvsdg2jlm/rvsdg2jlm.cpp @@ -332,7 +332,7 @@ phi_needed(const rvsdg::input * i, const llvm::variable * v) { auto node = rvsdg::input::GetNode(*i); JLM_ASSERT(is(node)); - auto theta = static_cast(node); + auto theta = static_cast(node); auto input = static_cast(i); auto output = theta->output(input->index()); @@ -353,7 +353,7 @@ static inline void convert_theta_node(const rvsdg::node & node, context & ctx) { JLM_ASSERT(is(&node)); - auto subregion = static_cast(&node)->subregion(0); + auto subregion = static_cast(&node)->subregion(0); auto predicate = subregion->result(0)->origin(); auto pre_entry = ctx.lpbb(); @@ -428,7 +428,7 @@ static inline void convert_phi_node(const rvsdg::node & node, context & ctx) { JLM_ASSERT(rvsdg::is(&node)); - auto phi = static_cast(&node); + auto phi = static_cast(&node); auto subregion = phi->subregion(0); auto & module = ctx.module(); auto & ipg = module.ipgraph(); diff --git a/jlm/llvm/ir/operators/Phi.cpp b/jlm/llvm/ir/operators/Phi.cpp index dc58eab70..789b034d9 100644 --- a/jlm/llvm/ir/operators/Phi.cpp +++ b/jlm/llvm/ir/operators/Phi.cpp @@ -38,13 +38,13 @@ node::~node() cvinput * node::input(size_t n) const noexcept { - return static_cast(structural_node::input(n)); + return static_cast(StructuralNode::input(n)); } rvoutput * node::output(size_t n) const noexcept { - return static_cast(structural_node::output(n)); + return static_cast(StructuralNode::output(n)); } cvargument * diff --git a/jlm/llvm/ir/operators/Phi.hpp b/jlm/llvm/ir/operators/Phi.hpp index cd40a0c24..568a81e0c 100644 --- a/jlm/llvm/ir/operators/Phi.hpp +++ b/jlm/llvm/ir/operators/Phi.hpp @@ -45,7 +45,7 @@ class cvargument; class cvinput; class rvoutput; -class node final : public jlm::rvsdg::structural_node +class node final : public rvsdg::StructuralNode { friend class phi::builder; @@ -305,7 +305,7 @@ class node final : public jlm::rvsdg::structural_node private: node(rvsdg::Region * parent, const phi::operation & op) - : structural_node(op, parent, 1) + : StructuralNode(op, parent, 1) {} static phi::node * @@ -378,7 +378,7 @@ class node final : public jlm::rvsdg::structural_node rvsdg::Region * subregion() const noexcept { - return structural_node::subregion(0); + return StructuralNode::subregion(0); } const phi::operation & diff --git a/jlm/llvm/ir/operators/delta.cpp b/jlm/llvm/ir/operators/delta.cpp index a7766840d..8480cb384 100644 --- a/jlm/llvm/ir/operators/delta.cpp +++ b/jlm/llvm/ir/operators/delta.cpp @@ -107,7 +107,7 @@ node::add_ctxvar(jlm::rvsdg::output * origin) cvinput * node::input(size_t n) const noexcept { - return static_cast(structural_node::input(n)); + return static_cast(StructuralNode::input(n)); } cvargument * @@ -119,7 +119,7 @@ node::cvargument(size_t n) const noexcept delta::output * node::output() const noexcept { - return static_cast(structural_node::output(0)); + return static_cast(StructuralNode::output(0)); } delta::result * diff --git a/jlm/llvm/ir/operators/delta.hpp b/jlm/llvm/ir/operators/delta.hpp index ff88f914a..70f1f324d 100644 --- a/jlm/llvm/ir/operators/delta.hpp +++ b/jlm/llvm/ir/operators/delta.hpp @@ -127,7 +127,7 @@ class result; * auto output = delta->finalize(...); * \endcode */ -class node final : public rvsdg::structural_node +class node final : public rvsdg::StructuralNode { class cviterator; class cvconstiterator; @@ -140,7 +140,7 @@ class node final : public rvsdg::structural_node private: node(rvsdg::Region * parent, delta::operation && op) - : structural_node(op, parent, 1) + : StructuralNode(op, parent, 1) {} public: @@ -153,13 +153,13 @@ class node final : public rvsdg::structural_node rvsdg::Region * subregion() const noexcept { - return structural_node::subregion(0); + return StructuralNode::subregion(0); } const delta::operation & operation() const noexcept { - return *static_cast(&structural_node::operation()); + return *static_cast(&StructuralNode::operation()); } [[nodiscard]] const rvsdg::ValueType & diff --git a/jlm/llvm/ir/operators/lambda.cpp b/jlm/llvm/ir/operators/lambda.cpp index 00f98479e..7a138b680 100644 --- a/jlm/llvm/ir/operators/lambda.cpp +++ b/jlm/llvm/ir/operators/lambda.cpp @@ -116,13 +116,13 @@ node::fctresults() const cvinput * node::input(size_t n) const noexcept { - return util::AssertedCast(structural_node::input(n)); + return util::AssertedCast(StructuralNode::input(n)); } lambda::output * node::output() const noexcept { - return util::AssertedCast(structural_node::output(0)); + return util::AssertedCast(StructuralNode::output(0)); } lambda::fctargument * diff --git a/jlm/llvm/ir/operators/lambda.hpp b/jlm/llvm/ir/operators/lambda.hpp index 31ba510d5..3d67d22c8 100644 --- a/jlm/llvm/ir/operators/lambda.hpp +++ b/jlm/llvm/ir/operators/lambda.hpp @@ -128,7 +128,7 @@ class result; * auto output = lambda->finalize(...); * \endcode */ -class node final : public jlm::rvsdg::structural_node +class node final : public rvsdg::StructuralNode { public: class CallSummary; @@ -157,7 +157,7 @@ class node final : public jlm::rvsdg::structural_node private: node(rvsdg::Region * parent, lambda::operation && op) - : structural_node(op, parent, 1) + : StructuralNode(op, parent, 1) {} public: @@ -182,13 +182,13 @@ class node final : public jlm::rvsdg::structural_node [[nodiscard]] rvsdg::Region * subregion() const noexcept { - return structural_node::subregion(0); + return StructuralNode::subregion(0); } [[nodiscard]] const lambda::operation & operation() const noexcept { - return *jlm::util::AssertedCast(&structural_node::operation()); + return *jlm::util::AssertedCast(&StructuralNode::operation()); } [[nodiscard]] const jlm::llvm::FunctionType & diff --git a/jlm/llvm/opt/DeadNodeElimination.cpp b/jlm/llvm/opt/DeadNodeElimination.cpp index 80dc5d2a3..40fb6cb82 100644 --- a/jlm/llvm/opt/DeadNodeElimination.cpp +++ b/jlm/llvm/opt/DeadNodeElimination.cpp @@ -329,7 +329,7 @@ DeadNodeElimination::SweepRegion(rvsdg::Region & region) const continue; } - if (auto structuralNode = dynamic_cast(node)) + if (auto structuralNode = dynamic_cast(node)) { SweepStructuralNode(*structuralNode); } @@ -340,7 +340,7 @@ DeadNodeElimination::SweepRegion(rvsdg::Region & region) const } void -DeadNodeElimination::SweepStructuralNode(jlm::rvsdg::structural_node & node) const +DeadNodeElimination::SweepStructuralNode(rvsdg::StructuralNode & node) const { auto sweepGamma = [](auto & d, auto & n) { @@ -365,7 +365,7 @@ DeadNodeElimination::SweepStructuralNode(jlm::rvsdg::structural_node & node) con static std::unordered_map< std::type_index, - std::function> + std::function> map({ { typeid(rvsdg::GammaOperation), sweepGamma }, { typeid(rvsdg::ThetaOperation), sweepTheta }, { typeid(lambda::operation), sweepLambda }, diff --git a/jlm/llvm/opt/DeadNodeElimination.hpp b/jlm/llvm/opt/DeadNodeElimination.hpp index 388c939b3..d64fe280e 100644 --- a/jlm/llvm/opt/DeadNodeElimination.hpp +++ b/jlm/llvm/opt/DeadNodeElimination.hpp @@ -91,7 +91,7 @@ class DeadNodeElimination final : public optimization SweepRegion(rvsdg::Region & region) const; void - SweepStructuralNode(jlm::rvsdg::structural_node & node) const; + SweepStructuralNode(rvsdg::StructuralNode & node) const; void SweepGamma(rvsdg::GammaNode & gammaNode) const; diff --git a/jlm/llvm/opt/InvariantValueRedirection.cpp b/jlm/llvm/opt/InvariantValueRedirection.cpp index 93ca2e768..c1f790061 100644 --- a/jlm/llvm/opt/InvariantValueRedirection.cpp +++ b/jlm/llvm/opt/InvariantValueRedirection.cpp @@ -125,7 +125,7 @@ InvariantValueRedirection::RedirectInRegion(rvsdg::Region & region) } void -InvariantValueRedirection::RedirectInSubregions(rvsdg::structural_node & structuralNode) +InvariantValueRedirection::RedirectInSubregions(rvsdg::StructuralNode & structuralNode) { auto isGammaNode = is(&structuralNode); auto isThetaNode = is(&structuralNode); diff --git a/jlm/llvm/opt/InvariantValueRedirection.hpp b/jlm/llvm/opt/InvariantValueRedirection.hpp index 73e56767a..3830775cc 100644 --- a/jlm/llvm/opt/InvariantValueRedirection.hpp +++ b/jlm/llvm/opt/InvariantValueRedirection.hpp @@ -64,7 +64,7 @@ class InvariantValueRedirection final : public optimization RedirectInRegion(rvsdg::Region & region); static void - RedirectInSubregions(rvsdg::structural_node & structuralNode); + RedirectInSubregions(rvsdg::StructuralNode & structuralNode); static void RedirectGammaOutputs(rvsdg::GammaNode & gammaNode); diff --git a/jlm/llvm/opt/RvsdgTreePrinter.cpp b/jlm/llvm/opt/RvsdgTreePrinter.cpp index 5a88bde83..87788f01c 100644 --- a/jlm/llvm/opt/RvsdgTreePrinter.cpp +++ b/jlm/llvm/opt/RvsdgTreePrinter.cpp @@ -96,7 +96,7 @@ RvsdgTreePrinter::AnnotateNumRvsdgNodes( { for (auto & node : region.nodes) { - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { size_t numSubregionNodes = 0; for (size_t n = 0; n < structuralNode->nsubregions(); n++) @@ -142,7 +142,7 @@ RvsdgTreePrinter::AnnotateNumMemoryStateInputsOutputs( for (auto & node : region.nodes) { - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { size_t numMemoryStateInputs = 0; for (size_t n = 0; n < structuralNode->ninputs(); n++) diff --git a/jlm/llvm/opt/alias-analyses/Andersen.cpp b/jlm/llvm/opt/alias-analyses/Andersen.cpp index 1c13a7ed9..83a8179ba 100644 --- a/jlm/llvm/opt/alias-analyses/Andersen.cpp +++ b/jlm/llvm/opt/alias-analyses/Andersen.cpp @@ -924,7 +924,7 @@ Andersen::AnalyzeValist(const rvsdg::simple_node & node) } void -Andersen::AnalyzeStructuralNode(const rvsdg::structural_node & node) +Andersen::AnalyzeStructuralNode(const rvsdg::StructuralNode & node) { if (const auto lambdaNode = dynamic_cast(&node)) AnalyzeLambda(*lambdaNode); @@ -1158,7 +1158,7 @@ Andersen::AnalyzeRegion(rvsdg::Region & region) { if (auto simpleNode = dynamic_cast(node)) AnalyzeSimpleNode(*simpleNode); - else if (auto structuralNode = dynamic_cast(node)) + else if (auto structuralNode = dynamic_cast(node)) AnalyzeStructuralNode(*structuralNode); else JLM_UNREACHABLE("Unknown node type"); diff --git a/jlm/llvm/opt/alias-analyses/Andersen.hpp b/jlm/llvm/opt/alias-analyses/Andersen.hpp index c2ced42cf..bc59f805e 100644 --- a/jlm/llvm/opt/alias-analyses/Andersen.hpp +++ b/jlm/llvm/opt/alias-analyses/Andersen.hpp @@ -395,7 +395,7 @@ class Andersen final : public AliasAnalysis AnalyzeValist(const rvsdg::simple_node & node); void - AnalyzeStructuralNode(const rvsdg::structural_node & node); + AnalyzeStructuralNode(const rvsdg::StructuralNode & node); void AnalyzeLambda(const lambda::node & node); diff --git a/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.cpp b/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.cpp index cfe5bade4..60b8f16a0 100644 --- a/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.cpp +++ b/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.cpp @@ -496,7 +496,7 @@ MemoryStateEncoder::EncodeRegion(rvsdg::Region & region) { EncodeSimpleNode(*simpleNode); } - else if (auto structuralNode = dynamic_cast(node)) + else if (auto structuralNode = dynamic_cast(node)) { EncodeStructuralNode(*structuralNode); } @@ -508,7 +508,7 @@ MemoryStateEncoder::EncodeRegion(rvsdg::Region & region) } void -MemoryStateEncoder::EncodeStructuralNode(rvsdg::structural_node & structuralNode) +MemoryStateEncoder::EncodeStructuralNode(rvsdg::StructuralNode & structuralNode) { if (auto lambdaNode = dynamic_cast(&structuralNode)) { diff --git a/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.hpp b/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.hpp index f4d3df1b2..f3f2bff37 100644 --- a/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.hpp +++ b/jlm/llvm/opt/alias-analyses/MemoryStateEncoder.hpp @@ -86,7 +86,7 @@ class MemoryStateEncoder final EncodeRegion(rvsdg::Region & region); void - EncodeStructuralNode(rvsdg::structural_node & structuralNode); + EncodeStructuralNode(rvsdg::StructuralNode & structuralNode); void EncodeSimpleNode(const rvsdg::simple_node & simpleNode); diff --git a/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.cpp b/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.cpp index 1978f945f..e52b940d0 100644 --- a/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.cpp +++ b/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.cpp @@ -186,7 +186,7 @@ class RegionSummary final return RecursiveCalls_; } - const util::HashSet & + const util::HashSet & GetStructuralNodes() const { return StructuralNodes_; @@ -223,7 +223,7 @@ class RegionSummary final } void - AddStructuralNode(const rvsdg::structural_node & structuralNode) + AddStructuralNode(const rvsdg::StructuralNode & structuralNode) { StructuralNodes_.Insert(&structuralNode); } @@ -254,7 +254,7 @@ class RegionSummary final util::HashSet RecursiveCalls_; util::HashSet NonRecursiveCalls_; - util::HashSet StructuralNodes_; + util::HashSet StructuralNodes_; }; /** \brief Memory node provisioning of region-aware memory node provider @@ -677,7 +677,7 @@ RegionAwareMemoryNodeProvider::AnnotateRegion(rvsdg::Region & region) for (auto & node : region.nodes) { - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { AnnotateStructuralNode(*structuralNode); } @@ -830,7 +830,7 @@ RegionAwareMemoryNodeProvider::AnnotateMemcpy(const rvsdg::simple_node & memcpyN } void -RegionAwareMemoryNodeProvider::AnnotateStructuralNode(const rvsdg::structural_node & structuralNode) +RegionAwareMemoryNodeProvider::AnnotateStructuralNode(const rvsdg::StructuralNode & structuralNode) { if (is(&structuralNode)) { @@ -1046,7 +1046,7 @@ RegionAwareMemoryNodeProvider::ToRegionTree( for (const auto & node : region->nodes) { - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { subtree += util::strfmt(indent(depth), structuralNode->operation().debug_string(), "\n"); for (size_t n = 0; n < structuralNode->nsubregions(); n++) diff --git a/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.hpp b/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.hpp index 65b6a1644..08fac9106 100644 --- a/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.hpp +++ b/jlm/llvm/opt/alias-analyses/RegionAwareMemoryNodeProvider.hpp @@ -110,7 +110,7 @@ class RegionAwareMemoryNodeProvider final : public MemoryNodeProvider AnnotateSimpleNode(const rvsdg::simple_node & provider); void - AnnotateStructuralNode(const rvsdg::structural_node & structuralNode); + AnnotateStructuralNode(const rvsdg::StructuralNode & structuralNode); void AnnotateLoad(const LoadNode & loadNode); diff --git a/jlm/llvm/opt/alias-analyses/Steensgaard.cpp b/jlm/llvm/opt/alias-analyses/Steensgaard.cpp index 51dd6589d..558bd1463 100644 --- a/jlm/llvm/opt/alias-analyses/Steensgaard.cpp +++ b/jlm/llvm/opt/alias-analyses/Steensgaard.cpp @@ -1682,7 +1682,7 @@ Steensgaard::AnalyzeTheta(const rvsdg::ThetaNode & theta) } void -Steensgaard::AnalyzeStructuralNode(const jlm::rvsdg::structural_node & node) +Steensgaard::AnalyzeStructuralNode(const rvsdg::StructuralNode & node) { if (auto lambdaNode = dynamic_cast(&node)) { @@ -1732,7 +1732,7 @@ Steensgaard::AnalyzeRegion(rvsdg::Region & region) { AnalyzeSimpleNode(*simpleNode); } - else if (auto structuralNode = dynamic_cast(node)) + else if (auto structuralNode = dynamic_cast(node)) { AnalyzeStructuralNode(*structuralNode); } diff --git a/jlm/llvm/opt/alias-analyses/Steensgaard.hpp b/jlm/llvm/opt/alias-analyses/Steensgaard.hpp index f2ce6f9c3..bd561bc93 100644 --- a/jlm/llvm/opt/alias-analyses/Steensgaard.hpp +++ b/jlm/llvm/opt/alias-analyses/Steensgaard.hpp @@ -94,7 +94,7 @@ class Steensgaard final : public AliasAnalysis AnalyzeSimpleNode(const rvsdg::simple_node & node); void - AnalyzeStructuralNode(const rvsdg::structural_node & node); + AnalyzeStructuralNode(const rvsdg::StructuralNode & node); void AnalyzeAlloca(const rvsdg::simple_node & node); diff --git a/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.cpp b/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.cpp index f2aeae8f3..0691e3d4e 100644 --- a/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.cpp +++ b/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.cpp @@ -515,7 +515,7 @@ TopDownMemoryNodeEliminator::EliminateTopDownRegion(rvsdg::Region & region) { EliminateTopDownSimpleNode(*simpleNode); } - else if (auto structuralNode = dynamic_cast(node)) + else if (auto structuralNode = dynamic_cast(node)) { EliminateTopDownStructuralNode(*structuralNode); } @@ -528,7 +528,7 @@ TopDownMemoryNodeEliminator::EliminateTopDownRegion(rvsdg::Region & region) void TopDownMemoryNodeEliminator::EliminateTopDownStructuralNode( - const rvsdg::structural_node & structuralNode) + const rvsdg::StructuralNode & structuralNode) { if (auto gammaNode = dynamic_cast(&structuralNode)) { diff --git a/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.hpp b/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.hpp index aaf3b93f5..65707a0f7 100644 --- a/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.hpp +++ b/jlm/llvm/opt/alias-analyses/TopDownMemoryNodeEliminator.hpp @@ -31,7 +31,7 @@ class GammaNode; class node; class Region; class simple_node; -class structural_node; +class StructuralNode; class ThetaNode; } @@ -134,7 +134,7 @@ class TopDownMemoryNodeEliminator final : public MemoryNodeEliminator EliminateTopDownRegion(rvsdg::Region & region); void - EliminateTopDownStructuralNode(const rvsdg::structural_node & structuralNode); + EliminateTopDownStructuralNode(const rvsdg::StructuralNode & structuralNode); void EliminateTopDownLambda(const lambda::node & lambdaNode); diff --git a/jlm/llvm/opt/cne.cpp b/jlm/llvm/opt/cne.cpp index 8edcea23c..5527f69a1 100644 --- a/jlm/llvm/opt/cne.cpp +++ b/jlm/llvm/opt/cne.cpp @@ -274,7 +274,7 @@ static void mark(rvsdg::Region *, cnectx &); static void -mark_gamma(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_gamma(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(rvsdg::is(node->operation())); @@ -300,7 +300,7 @@ mark_gamma(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_theta(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_theta(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); auto theta = static_cast(node); @@ -324,7 +324,7 @@ mark_theta(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_lambda(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_lambda(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); @@ -344,7 +344,7 @@ mark_lambda(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_phi(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_phi(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); @@ -364,21 +364,20 @@ mark_phi(const jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -mark_delta(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark_delta(const rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); } static void -mark(const jlm::rvsdg::structural_node * node, cnectx & ctx) +mark(const rvsdg::StructuralNode * node, cnectx & ctx) { - static std:: - unordered_map - map({ { std::type_index(typeid(rvsdg::GammaOperation)), mark_gamma }, - { std::type_index(typeid(rvsdg::ThetaOperation)), mark_theta }, - { typeid(lambda::operation), mark_lambda }, - { typeid(phi::operation), mark_phi }, - { typeid(delta::operation), mark_delta } }); + static std::unordered_map map( + { { std::type_index(typeid(rvsdg::GammaOperation)), mark_gamma }, + { std::type_index(typeid(rvsdg::ThetaOperation)), mark_theta }, + { typeid(lambda::operation), mark_lambda }, + { typeid(phi::operation), mark_phi }, + { typeid(delta::operation), mark_delta } }); auto & op = node->operation(); JLM_ASSERT(map.find(typeid(op)) != map.end()); @@ -432,7 +431,7 @@ mark(rvsdg::Region * region, cnectx & ctx) if (auto simple = dynamic_cast(node)) mark(simple, ctx); else - mark(static_cast(node), ctx); + mark(static_cast(node), ctx); } } @@ -465,7 +464,7 @@ static void divert(rvsdg::Region *, cnectx &); static void -divert_gamma(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_gamma(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(rvsdg::is(node)); auto gamma = static_cast(node); @@ -483,7 +482,7 @@ divert_gamma(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_theta(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_theta(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); auto theta = static_cast(node); @@ -500,7 +499,7 @@ divert_theta(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_lambda(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_lambda(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); @@ -509,7 +508,7 @@ divert_lambda(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_phi(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_phi(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(is(node)); @@ -518,15 +517,15 @@ divert_phi(jlm::rvsdg::structural_node * node, cnectx & ctx) } static void -divert_delta(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert_delta(rvsdg::StructuralNode * node, cnectx & ctx) { JLM_ASSERT(jlm::rvsdg::is(node)); } static void -divert(jlm::rvsdg::structural_node * node, cnectx & ctx) +divert(rvsdg::StructuralNode * node, cnectx & ctx) { - static std::unordered_map map( + static std::unordered_map map( { { std::type_index(typeid(rvsdg::GammaOperation)), divert_gamma }, { std::type_index(typeid(rvsdg::ThetaOperation)), divert_theta }, { typeid(lambda::operation), divert_lambda }, @@ -546,7 +545,7 @@ divert(rvsdg::Region * region, cnectx & ctx) if (auto simple = dynamic_cast(node)) divert_outputs(simple, ctx); else - divert(static_cast(node), ctx); + divert(static_cast(node), ctx); } } diff --git a/jlm/llvm/opt/inversion.cpp b/jlm/llvm/opt/inversion.cpp index 36f0a19b6..5e2185c71 100644 --- a/jlm/llvm/opt/inversion.cpp +++ b/jlm/llvm/opt/inversion.cpp @@ -91,7 +91,7 @@ pullin(rvsdg::GammaNode * gamma, rvsdg::ThetaNode * theta) } static std::vector> -collect_condition_nodes(jlm::rvsdg::structural_node * tnode, jlm::rvsdg::structural_node * gnode) +collect_condition_nodes(rvsdg::StructuralNode * tnode, jlm::rvsdg::StructuralNode * gnode) { JLM_ASSERT(is(tnode)); JLM_ASSERT(rvsdg::is(gnode)); @@ -291,7 +291,7 @@ invert(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t r = 0; r < structnode->nsubregions(); r++) invert(structnode->subregion(r)); diff --git a/jlm/llvm/opt/pull.cpp b/jlm/llvm/opt/pull.cpp index a7166450f..59d2fd8e9 100644 --- a/jlm/llvm/opt/pull.cpp +++ b/jlm/llvm/opt/pull.cpp @@ -286,7 +286,7 @@ pull(rvsdg::Region * region) { for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { if (auto gamma = dynamic_cast(node)) pull(gamma); diff --git a/jlm/llvm/opt/push.cpp b/jlm/llvm/opt/push.cpp index 1faf44aab..ea814c538 100644 --- a/jlm/llvm/opt/push.cpp +++ b/jlm/llvm/opt/push.cpp @@ -399,7 +399,7 @@ push(rvsdg::Region * region) { for (auto node : jlm::rvsdg::topdown_traverser(region)) { - if (auto strnode = dynamic_cast(node)) + if (auto strnode = dynamic_cast(node)) { for (size_t n = 0; n < strnode->nsubregions(); n++) push(strnode->subregion(n)); diff --git a/jlm/llvm/opt/unroll.cpp b/jlm/llvm/opt/unroll.cpp index 2af878550..caf014e44 100644 --- a/jlm/llvm/opt/unroll.cpp +++ b/jlm/llvm/opt/unroll.cpp @@ -487,7 +487,7 @@ unroll(rvsdg::Region * region, size_t factor) bool unrolled = false; for (auto & node : jlm::rvsdg::topdown_traverser(region)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) unrolled = unroll(structnode->subregion(n), factor); diff --git a/jlm/rvsdg/binary.cpp b/jlm/rvsdg/binary.cpp index 18578e24f..0c783346c 100644 --- a/jlm/rvsdg/binary.cpp +++ b/jlm/rvsdg/binary.cpp @@ -429,7 +429,7 @@ flattened_binary_op::reduce( node->output(0)->divert_users(output); remove(node); } - else if (auto structnode = dynamic_cast(node)) + else if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) reduce(structnode->subregion(n), reduction); diff --git a/jlm/rvsdg/gamma.hpp b/jlm/rvsdg/gamma.hpp index 049380e9b..9e3c362e2 100644 --- a/jlm/rvsdg/gamma.hpp +++ b/jlm/rvsdg/gamma.hpp @@ -109,7 +109,7 @@ class GammaOperation final : public structural_op class GammaInput; class GammaOutput; -class GammaNode : public structural_node +class GammaNode : public StructuralNode { public: ~GammaNode() noexcept override; @@ -451,7 +451,7 @@ class GammaOutput final : public structural_output /* gamma node method definitions */ inline GammaNode::GammaNode(rvsdg::output * predicate, size_t nalternatives) - : structural_node(GammaOperation(nalternatives), predicate->region(), nalternatives) + : StructuralNode(GammaOperation(nalternatives), predicate->region(), nalternatives) { node::add_input(std::unique_ptr( new GammaInput(this, predicate, ControlType::Create(nalternatives)))); @@ -514,7 +514,7 @@ class GammaResult final : public RegionResult inline GammaInput * GammaNode::predicate() const noexcept { - return util::AssertedCast(structural_node::input(0)); + return util::AssertedCast(StructuralNode::input(0)); } inline GammaInput * diff --git a/jlm/rvsdg/region.cpp b/jlm/rvsdg/region.cpp index 2fd3c34ff..da1c21ce1 100644 --- a/jlm/rvsdg/region.cpp +++ b/jlm/rvsdg/region.cpp @@ -145,7 +145,7 @@ Region::Region(rvsdg::Region * parent, jlm::rvsdg::graph * graph) on_region_create(this); } -Region::Region(jlm::rvsdg::structural_node * node, size_t index) +Region::Region(rvsdg::StructuralNode * node, size_t index) : index_(index), graph_(node->graph()), node_(node) @@ -306,7 +306,7 @@ Region::prune(bool recursive) for (const auto & node : nodes) { - if (auto snode = dynamic_cast(&node)) + if (auto snode = dynamic_cast(&node)) { for (size_t n = 0; n < snode->nsubregions(); n++) snode->subregion(n)->prune(recursive); @@ -319,7 +319,7 @@ Region::normalize(bool recursive) { for (auto node : jlm::rvsdg::topdown_traverser(this)) { - if (auto structnode = dynamic_cast(node)) + if (auto structnode = dynamic_cast(node)) { for (size_t n = 0; n < structnode->nsubregions(); n++) structnode->subregion(n)->normalize(recursive); @@ -342,7 +342,7 @@ Region::NumRegions(const rvsdg::Region & region) noexcept size_t numRegions = 1; for (auto & node : region.nodes) { - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { for (size_t n = 0; n < structuralNode->nsubregions(); n++) { @@ -396,7 +396,7 @@ Region::ToTree( indentationString = std::string(indentationDepth, indentationChar); for (auto & node : region.nodes) { - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { auto nodeString = structuralNode->operation().debug_string(); auto annotationString = GetAnnotationString( @@ -478,7 +478,7 @@ nnodes(const jlm::rvsdg::Region * region) noexcept size_t n = region->nnodes(); for (const auto & node : region->nodes) { - if (auto snode = dynamic_cast(&node)) + if (auto snode = dynamic_cast(&node)) { for (size_t r = 0; r < snode->nsubregions(); r++) n += nnodes(snode->subregion(r)); @@ -494,7 +494,7 @@ nstructnodes(const rvsdg::Region * region) noexcept size_t n = 0; for (const auto & node : region->nodes) { - if (auto snode = dynamic_cast(&node)) + if (auto snode = dynamic_cast(&node)) { for (size_t r = 0; r < snode->nsubregions(); r++) n += nstructnodes(snode->subregion(r)); @@ -511,7 +511,7 @@ nsimpnodes(const rvsdg::Region * region) noexcept size_t n = 0; for (const auto & node : region->nodes) { - if (auto snode = dynamic_cast(&node)) + if (auto snode = dynamic_cast(&node)) { for (size_t r = 0; r < snode->nsubregions(); r++) n += nsimpnodes(snode->subregion(r)); @@ -531,7 +531,7 @@ ninputs(const rvsdg::Region * region) noexcept size_t n = region->nresults(); for (const auto & node : region->nodes) { - if (auto snode = dynamic_cast(&node)) + if (auto snode = dynamic_cast(&node)) { for (size_t r = 0; r < snode->nsubregions(); r++) n += ninputs(snode->subregion(r)); diff --git a/jlm/rvsdg/region.hpp b/jlm/rvsdg/region.hpp index 5e9af4ea0..da44f532b 100644 --- a/jlm/rvsdg/region.hpp +++ b/jlm/rvsdg/region.hpp @@ -27,7 +27,7 @@ class node; class simple_node; class simple_op; class structural_input; -class structural_node; +class StructuralNode; class structural_op; class structural_output; class SubstitutionMap; @@ -205,7 +205,7 @@ class RegionResult : public input * \brief Represent acyclic RVSDG subgraphs * * Regions represent acyclic RVSDG subgraphs and are instantiated with an index in \ref - * structural_node%s. Each region has \ref RegionArgument%s and \ref RegionResult%s that represent + * StructuralNode%s. Each region has \ref RegionArgument%s and \ref RegionResult%s that represent * the values at the beginning and end of the acyclic graph, respectively. In addition, each region * keeps track of the following properties: * @@ -258,7 +258,7 @@ class Region Region(rvsdg::Region * parent, jlm::rvsdg::graph * graph); - Region(rvsdg::structural_node * node, size_t index); + Region(rvsdg::StructuralNode * node, size_t index); /** * @return Returns an iterator range for iterating through the arguments of the region. @@ -357,7 +357,7 @@ class Region return graph_; } - inline jlm::rvsdg::structural_node * + inline rvsdg::StructuralNode * node() const noexcept { return node_; @@ -619,7 +619,7 @@ class Region * * @param region The top-level region that is converted * @param annotationMap A map with annotations for instances of \ref Region%s or - * structural_node%s. + * StructuralNode%s. * @return A string containing the ASCII tree of \p region. */ [[nodiscard]] static std::string @@ -678,7 +678,7 @@ class Region size_t index_; jlm::rvsdg::graph * graph_; - jlm::rvsdg::structural_node * node_; + rvsdg::StructuralNode * node_; std::vector results_; std::vector arguments_; region_bottom_node_list BottomNodes_; diff --git a/jlm/rvsdg/structural-node.cpp b/jlm/rvsdg/structural-node.cpp index 99913151f..3b68fb61a 100644 --- a/jlm/rvsdg/structural-node.cpp +++ b/jlm/rvsdg/structural-node.cpp @@ -21,7 +21,7 @@ structural_input::~structural_input() noexcept } structural_input::structural_input( - jlm::rvsdg::structural_node * node, + rvsdg::StructuralNode * node, jlm::rvsdg::output * origin, std::shared_ptr type) : node_input(origin, node, std::move(type)) @@ -38,9 +38,7 @@ structural_output::~structural_output() noexcept on_output_destroy(this); } -structural_output::structural_output( - jlm::rvsdg::structural_node * node, - std::shared_ptr type) +structural_output::structural_output(StructuralNode * node, std::shared_ptr type) : node_output(node, std::move(type)) { on_output_create(this); @@ -48,14 +46,14 @@ structural_output::structural_output( /* structural node */ -structural_node::~structural_node() +StructuralNode::~StructuralNode() noexcept { on_node_destroy(this); subregions_.clear(); } -structural_node::structural_node( +StructuralNode::StructuralNode( const jlm::rvsdg::structural_op & op, rvsdg::Region * region, size_t nsubregions) @@ -71,7 +69,7 @@ structural_node::structural_node( } structural_input * -structural_node::append_input(std::unique_ptr input) +StructuralNode::append_input(std::unique_ptr input) { if (input->node() != this) throw jlm::util::error("Appending input to wrong node."); @@ -86,7 +84,7 @@ structural_node::append_input(std::unique_ptr input) } structural_output * -structural_node::append_output(std::unique_ptr output) +StructuralNode::append_output(std::unique_ptr output) { if (output->node() != this) throw jlm::util::error("Appending output to wrong node."); diff --git a/jlm/rvsdg/structural-node.hpp b/jlm/rvsdg/structural-node.hpp index 77c0c8fa3..21496de4c 100644 --- a/jlm/rvsdg/structural-node.hpp +++ b/jlm/rvsdg/structural-node.hpp @@ -18,13 +18,13 @@ class structural_input; class structural_op; class structural_output; -class structural_node : public node +class StructuralNode : public node { public: - virtual ~structural_node(); + ~StructuralNode() noexcept override; protected: - structural_node( + StructuralNode( /* FIXME: use move semantics instead of copy semantics for op */ const jlm::rvsdg::structural_op & op, rvsdg::Region * region, @@ -71,19 +71,19 @@ typedef jlm::util::intrusive_list type); static structural_input * create( - structural_node * node, + StructuralNode * node, jlm::rvsdg::output * origin, std::shared_ptr type) { @@ -91,10 +91,10 @@ class structural_input : public node_input return node->append_input(std::move(input)); } - structural_node * + StructuralNode * node() const noexcept { - return static_cast(node_input::node()); + return static_cast(node_input::node()); } argument_list arguments; @@ -107,24 +107,24 @@ typedef jlm::util::intrusive_list type); + structural_output(StructuralNode * node, std::shared_ptr type); static structural_output * - create(structural_node * node, std::shared_ptr type) + create(StructuralNode * node, std::shared_ptr type) { auto output = std::make_unique(node, std::move(type)); return node->append_output(std::move(output)); } - structural_node * + StructuralNode * node() const noexcept { - return static_cast(node_output::node()); + return static_cast(node_output::node()); } result_list results; @@ -133,13 +133,13 @@ class structural_output : public node_output /* structural node method definitions */ inline jlm::rvsdg::structural_input * -structural_node::input(size_t index) const noexcept +StructuralNode::input(size_t index) const noexcept { return static_cast(node::input(index)); } inline jlm::rvsdg::structural_output * -structural_node::output(size_t index) const noexcept +StructuralNode::output(size_t index) const noexcept { return static_cast(node::output(index)); } @@ -160,7 +160,7 @@ Region::Contains(const rvsdg::Region & region, bool checkSubregions) continue; } - if (auto structuralNode = dynamic_cast(&node)) + if (auto structuralNode = dynamic_cast(&node)) { for (size_t n = 0; n < structuralNode->nsubregions(); n++) { diff --git a/jlm/rvsdg/theta.cpp b/jlm/rvsdg/theta.cpp index c1667d26e..f940963d8 100644 --- a/jlm/rvsdg/theta.cpp +++ b/jlm/rvsdg/theta.cpp @@ -27,7 +27,7 @@ ThetaOperation::copy() const } ThetaNode::ThetaNode(rvsdg::Region & parent) - : structural_node(ThetaOperation(), &parent, 1) + : StructuralNode(ThetaOperation(), &parent, 1) { auto predicate = control_false(subregion()); ThetaPredicateResult::Create(*predicate); diff --git a/jlm/rvsdg/theta.hpp b/jlm/rvsdg/theta.hpp index cea84185e..33348be3f 100644 --- a/jlm/rvsdg/theta.hpp +++ b/jlm/rvsdg/theta.hpp @@ -30,7 +30,7 @@ class ThetaOperation final : public structural_op class ThetaInput; class ThetaOutput; -class ThetaNode final : public structural_node +class ThetaNode final : public StructuralNode { public: class loopvar_iterator @@ -100,7 +100,7 @@ class ThetaNode final : public structural_node [[nodiscard]] rvsdg::Region * subregion() const noexcept { - return structural_node::subregion(0); + return StructuralNode::subregion(0); } [[nodiscard]] RegionResult * diff --git a/jlm/rvsdg/view.cpp b/jlm/rvsdg/view.cpp index 5cf0dbb94..6bcba5568 100644 --- a/jlm/rvsdg/view.cpp +++ b/jlm/rvsdg/view.cpp @@ -57,7 +57,7 @@ node_to_string( } s += "\n"; - if (auto snode = dynamic_cast(node)) + if (auto snode = dynamic_cast(node)) { for (size_t n = 0; n < snode->nsubregions(); n++) s += region_to_string(snode->subregion(n), depth + 1, map); @@ -297,7 +297,7 @@ convert_simple_node(const jlm::rvsdg::simple_node * node) } static inline std::string -convert_structural_node(const jlm::rvsdg::structural_node * node) +convert_structural_node(const rvsdg::StructuralNode * node) { std::string s; s += node_starttag(id(node), "", type(node)); @@ -327,7 +327,7 @@ convert_node(const jlm::rvsdg::node * node) if (auto n = dynamic_cast(node)) return convert_simple_node(n); - if (auto n = dynamic_cast(node)) + if (auto n = dynamic_cast(node)) return convert_structural_node(n); JLM_ASSERT(0); diff --git a/tests/jlm/rvsdg/test-gamma.cpp b/tests/jlm/rvsdg/test-gamma.cpp index 9a4a4e2e5..3e812a861 100644 --- a/tests/jlm/rvsdg/test-gamma.cpp +++ b/tests/jlm/rvsdg/test-gamma.cpp @@ -37,7 +37,7 @@ test_gamma(void) /* test gamma copy */ - auto gamma2 = static_cast(gamma)->copy(graph.root(), { pred, v0, v1, v2 }); + auto gamma2 = static_cast(gamma)->copy(graph.root(), { pred, v0, v1, v2 }); view(graph.root(), stdout); assert(is(gamma2)); diff --git a/tests/jlm/rvsdg/test-theta.cpp b/tests/jlm/rvsdg/test-theta.cpp index 8e50f3fed..d63ed264c 100644 --- a/tests/jlm/rvsdg/test-theta.cpp +++ b/tests/jlm/rvsdg/test-theta.cpp @@ -34,7 +34,7 @@ TestThetaCreation() jlm::tests::GraphExport::Create(*theta->output(0), "exp"); auto theta2 = - static_cast(theta)->copy(graph.root(), { imp1, imp2, imp3 }); + static_cast(theta)->copy(graph.root(), { imp1, imp2, imp3 }); jlm::rvsdg::view(graph.root(), stdout); assert(lv1->node() == theta); diff --git a/tests/test-operation.cpp b/tests/test-operation.cpp index 7ff50a3b3..df8a4b0d1 100644 --- a/tests/test-operation.cpp +++ b/tests/test-operation.cpp @@ -160,8 +160,6 @@ structural_op::copy() const return std::unique_ptr(new structural_op(*this)); } -/* structural_node class */ - structural_node::~structural_node() {} diff --git a/tests/test-operation.hpp b/tests/test-operation.hpp index 6a031f5e3..517dfdbdb 100644 --- a/tests/test-operation.hpp +++ b/tests/test-operation.hpp @@ -209,14 +209,14 @@ class StructuralNodeArgument; class StructuralNodeInput; class StructuralNodeOutput; -class structural_node final : public rvsdg::structural_node +class structural_node final : public rvsdg::StructuralNode { public: ~structural_node() override; private: structural_node(rvsdg::Region * parent, size_t nsubregions) - : rvsdg::structural_node(structural_op(), parent, nsubregions) + : rvsdg::StructuralNode(structural_op(), parent, nsubregions) {} public: From 91b98db77453df0110d5382ed811f19626acbf57 Mon Sep 17 00:00:00 2001 From: halvorlinder <56249210+halvorlinder@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:41:52 +0200 Subject: [PATCH 4/4] Theta node conversion to and from MLIR (#655) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds conversion of theta nodes from JLM to MLIR and from MLIR to JLM --------- Co-authored-by: HÃ¥vard Krogstie Co-authored-by: Magnus Sjalander --- jlm/mlir/backend/JlmToMlirConverter.cpp | 36 ++++ jlm/mlir/backend/JlmToMlirConverter.hpp | 7 + jlm/mlir/frontend/MlirToJlmConverter.cpp | 19 ++- jlm/mlir/frontend/MlirToJlmConverter.hpp | 1 + .../mlir/backend/TestJlmToMlirConverter.cpp | 103 ++++++++++++ .../mlir/frontend/TestMlirToJlmConverter.cpp | 157 ++++++++++++++++++ 6 files changed, 322 insertions(+), 1 deletion(-) diff --git a/jlm/mlir/backend/JlmToMlirConverter.cpp b/jlm/mlir/backend/JlmToMlirConverter.cpp index 5b68714ca..51d59ad26 100644 --- a/jlm/mlir/backend/JlmToMlirConverter.cpp +++ b/jlm/mlir/backend/JlmToMlirConverter.cpp @@ -164,6 +164,10 @@ JlmToMlirConverter::ConvertNode( { return ConvertGamma(*gamma, block, inputs); } + else if (auto theta = dynamic_cast(&node)) + { + return ConvertTheta(*theta, block, inputs); + } else { auto message = util::strfmt("Unimplemented structural node: ", node.operation().debug_string()); @@ -464,6 +468,38 @@ JlmToMlirConverter::ConvertGamma( return gamma; } +::mlir::Operation * +JlmToMlirConverter::ConvertTheta( + const rvsdg::ThetaNode & thetaNode, + ::mlir::Block & block, + const ::llvm::SmallVector<::mlir::Value> & inputs) +{ + ::llvm::SmallVector<::mlir::Type> outputTypeRange; + for (size_t i = 0; i < thetaNode.noutputs(); ++i) + { + outputTypeRange.push_back(ConvertType(thetaNode.output(i)->type())); + } + + ::llvm::SmallVector<::mlir::NamedAttribute> attributes; + + auto theta = Builder_->create<::mlir::rvsdg::ThetaNode>( + Builder_->getUnknownLoc(), + ::mlir::TypeRange(::llvm::ArrayRef(outputTypeRange)), + ::mlir::ValueRange(::llvm::ArrayRef(inputs)), + attributes); + + block.push_back(theta); + auto & thetaBlock = theta.getRegion().emplaceBlock(); + auto regionResults = ConvertRegion(*thetaNode.subregion(), thetaBlock); + auto results = ::mlir::ValueRange({ std::next(regionResults.begin()), regionResults.end() }); + auto thetaResult = Builder_->create<::mlir::rvsdg::ThetaResult>( + Builder_->getUnknownLoc(), + regionResults[0], + results); + thetaBlock.push_back(thetaResult); + return theta; +} + ::mlir::Type JlmToMlirConverter::ConvertType(const rvsdg::Type & type) { diff --git a/jlm/mlir/backend/JlmToMlirConverter.hpp b/jlm/mlir/backend/JlmToMlirConverter.hpp index c4c0d6f7a..cc2e13b9a 100644 --- a/jlm/mlir/backend/JlmToMlirConverter.hpp +++ b/jlm/mlir/backend/JlmToMlirConverter.hpp @@ -11,6 +11,7 @@ #include #include #include +#include // MLIR RVSDG dialects #include @@ -164,6 +165,12 @@ class JlmToMlirConverter final ::mlir::Block & block, const ::llvm::SmallVector<::mlir::Value> & inputs); + ::mlir::Operation * + ConvertTheta( + const rvsdg::ThetaNode & thetaNode, + ::mlir::Block & block, + const ::llvm::SmallVector<::mlir::Value> & inputs); + /** * Converts an RVSDG type to an MLIR RVSDG type. * \param type The RVSDG type to be converted. diff --git a/jlm/mlir/frontend/MlirToJlmConverter.cpp b/jlm/mlir/frontend/MlirToJlmConverter.cpp index 7280b3bc3..e911ef3a9 100644 --- a/jlm/mlir/frontend/MlirToJlmConverter.cpp +++ b/jlm/mlir/frontend/MlirToJlmConverter.cpp @@ -352,6 +352,22 @@ MlirToJlmConverter::ConvertOperation( return rvsdgGammaNode; } + else if (auto mlirThetaNode = ::mlir::dyn_cast<::mlir::rvsdg::ThetaNode>(&mlirOperation)) + { + auto rvsdgThetaNode = rvsdg::ThetaNode::create(&rvsdgRegion); + + // Add loop vars to the theta node + for (size_t i = 0; i < inputs.size(); i++) + { + rvsdgThetaNode->add_loopvar(inputs[i]); + } + + auto regionResults = ConvertRegion(mlirThetaNode.getRegion(), *rvsdgThetaNode->subregion()); + + rvsdgThetaNode->set_predicate(regionResults[0]); + + return rvsdgThetaNode; + } else if (auto mlirMatch = ::mlir::dyn_cast<::mlir::rvsdg::Match>(&mlirOperation)) { std::unordered_map mapping; @@ -381,7 +397,8 @@ MlirToJlmConverter::ConvertOperation( else if ( ::mlir::isa<::mlir::rvsdg::LambdaResult>(&mlirOperation) || ::mlir::isa<::mlir::rvsdg::OmegaResult>(&mlirOperation) - || ::mlir::isa<::mlir::rvsdg::GammaResult>(&mlirOperation)) + || ::mlir::isa<::mlir::rvsdg::GammaResult>(&mlirOperation) + || ::mlir::isa<::mlir::rvsdg::ThetaResult>(&mlirOperation)) { // This is a terminating operation that doesn't have a corresponding RVSDG node return nullptr; diff --git a/jlm/mlir/frontend/MlirToJlmConverter.hpp b/jlm/mlir/frontend/MlirToJlmConverter.hpp index c4a9b6fa7..49cd37118 100644 --- a/jlm/mlir/frontend/MlirToJlmConverter.hpp +++ b/jlm/mlir/frontend/MlirToJlmConverter.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/tests/jlm/mlir/backend/TestJlmToMlirConverter.cpp b/tests/jlm/mlir/backend/TestJlmToMlirConverter.cpp index 93ec90f8d..0c08be6ee 100644 --- a/tests/jlm/mlir/backend/TestJlmToMlirConverter.cpp +++ b/tests/jlm/mlir/backend/TestJlmToMlirConverter.cpp @@ -9,6 +9,7 @@ #include #include +#include #include static int @@ -599,8 +600,110 @@ TestGamma() return 0; } +/** \brief TestTheta + * + * This test is similar to previous tests, but uses a theta operation + */ +static int +TestTheta() +{ + using namespace jlm::llvm; + using namespace mlir::rvsdg; + + auto rvsdgModule = RvsdgModule::Create(jlm::util::filepath(""), "", ""); + auto graph = &rvsdgModule->Rvsdg(); + + auto nf = graph->node_normal_form(typeid(jlm::rvsdg::operation)); + nf->set_mutable(false); + { + // Create a theta operation + std::cout << "Theta Operation" << std::endl; + auto entryvar1 = jlm::rvsdg::create_bitconstant(graph->root(), 32, 5); + auto entryvar2 = jlm::rvsdg::create_bitconstant(graph->root(), 32, 6); + jlm::rvsdg::ThetaNode * rvsdgThetaNode = jlm::rvsdg::ThetaNode::create(graph->root()); + + auto predicate = jlm::rvsdg::control_constant(rvsdgThetaNode->subregion(), 2, 0); + + rvsdgThetaNode->add_loopvar(entryvar1); + rvsdgThetaNode->add_loopvar(entryvar2); + rvsdgThetaNode->set_predicate(predicate); + + // Convert the RVSDG to MLIR + std::cout << "Convert to MLIR" << std::endl; + jlm::mlir::JlmToMlirConverter mlirgen; + auto omega = mlirgen.ConvertModule(*rvsdgModule); + + // Checking blocks and operations count + std::cout << "Checking blocks and operations count" << std::endl; + auto & omegaRegion = omega.getRegion(); + assert(omegaRegion.getBlocks().size() == 1); + auto & omegaBlock = omegaRegion.front(); + // 1 theta + 1 predicate + 2 constants + assert(omegaBlock.getOperations().size() == 4); + + bool thetaFound = false; + for (auto & operation : omegaBlock.getOperations()) + { + if (mlir::isa(operation)) + { + thetaFound = true; + std::cout << "Checking theta operation" << std::endl; + auto thetaOp = mlir::cast(operation); + // 2 loop vars + assert(thetaOp.getNumOperands() == 2); + assert(thetaOp.getNumResults() == 2); + + auto & thetaBlock = thetaOp.getRegion().front(); + auto thetaResult = thetaBlock.getTerminator(); + + assert(mlir::isa(thetaResult)); + auto thetaResultOp = mlir::cast(thetaResult); + + std::cout << "Checking theta predicate" << std::endl; + + assert(mlir::isa(thetaResultOp.getPredicate().getDefiningOp())); + auto controlConstant = + mlir::cast(thetaResultOp.getPredicate().getDefiningOp()); + + assert(controlConstant.getValue() == 0); + + assert(mlir::isa(controlConstant.getType())); + auto ctrlType = mlir::cast(controlConstant.getType()); + assert(ctrlType.getNumOptions() == 2); + + std::cout << "Checking theta loop vars" << std::endl; + //! getInputs() corresponds to the loop vars + auto loopVars = thetaOp.getInputs(); + assert(loopVars.size() == 2); + assert(mlir::isa(loopVars[0].getDefiningOp())); + assert(mlir::isa(loopVars[1].getDefiningOp())); + auto loopVar1 = mlir::cast(loopVars[0].getDefiningOp()); + auto loopVar2 = mlir::cast(loopVars[1].getDefiningOp()); + assert(loopVar1.value() == 5); + assert(loopVar2.value() == 6); + + // Theta result, constant control predicate + assert(thetaBlock.getOperations().size() == 2); + + std::cout << "Checking loop exitVars" << std::endl; + std::cout << thetaResultOp.getNumOperands() << std::endl; + + std::cout << "Checking theta subregion" << std::endl; + + // Two arguments and predicate + assert(thetaResultOp.getNumOperands() == 3); + } + } + // } + assert(thetaFound); + omega->destroy(); + } + return 0; +} + JLM_UNIT_TEST_REGISTER("jlm/mlir/backend/TestMlirLambdaGen", TestLambda) JLM_UNIT_TEST_REGISTER("jlm/mlir/backend/TestMlirAddOperationGen", TestAddOperation) JLM_UNIT_TEST_REGISTER("jlm/mlir/backend/TestMlirComZeroExtGen", TestComZeroExt) JLM_UNIT_TEST_REGISTER("jlm/mlir/backend/TestMlirMatchGen", TestMatch) JLM_UNIT_TEST_REGISTER("jlm/mlir/backend/TestMlirGammaGen", TestGamma) +JLM_UNIT_TEST_REGISTER("jlm/mlir/backend/TestMlirThetaGen", TestTheta) diff --git a/tests/jlm/mlir/frontend/TestMlirToJlmConverter.cpp b/tests/jlm/mlir/frontend/TestMlirToJlmConverter.cpp index ec1b8e4a6..174040d57 100644 --- a/tests/jlm/mlir/frontend/TestMlirToJlmConverter.cpp +++ b/tests/jlm/mlir/frontend/TestMlirToJlmConverter.cpp @@ -856,8 +856,165 @@ TestGammaOp() return 0; } +/** \brief TestThetaOp + * + * This function tests the Theta operation. It creates a lambda block with a Theta operation. + * + */ +static int +TestThetaOp() +{ + { + using namespace mlir::rvsdg; + using namespace mlir::jlm; + + // Setup MLIR Context and load dialects + std::cout << "Creating MLIR context" << std::endl; + auto context = std::make_unique(); + context->getOrLoadDialect(); + context->getOrLoadDialect(); + context->getOrLoadDialect(); + auto Builder_ = std::make_unique(context.get()); + + auto omega = Builder_->create(Builder_->getUnknownLoc()); + auto & omegaRegion = omega.getRegion(); + auto * omegaBlock = new mlir::Block; + omegaRegion.push_back(omegaBlock); + + // Handle function arguments + std::cout << "Creating function arguments" << std::endl; + ::llvm::SmallVector arguments; + arguments.push_back(Builder_->getType()); + arguments.push_back(Builder_->getType()); + ::llvm::ArrayRef argumentsArray(arguments); + + // Handle function results + std::cout << "Creating function results" << std::endl; + ::llvm::SmallVector results; + results.push_back(Builder_->getType()); + results.push_back(Builder_->getType()); + ::llvm::ArrayRef resultsArray(results); + + // LambdaNodes return a LambdaRefType + std::cout << "Creating LambdaRefType" << std::endl; + ::llvm::SmallVector lambdaRef; + auto refType = Builder_->getType(argumentsArray, resultsArray); + lambdaRef.push_back(refType); + + // Add function attributes + std::cout << "Creating function attributes" << std::endl; + ::llvm::SmallVector attributes; + auto attributeName = Builder_->getStringAttr("sym_name"); + auto attributeValue = Builder_->getStringAttr("test"); + auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); + attributes.push_back(symbolName); + ::llvm::ArrayRef<::mlir::NamedAttribute> attributesRef(attributes); + + // Add inputs to the function + ::llvm::SmallVector inputs; + + // Create the lambda node and add it to the region/block it resides in + std::cout << "Creating LambdaNode" << std::endl; + auto lambda = + Builder_->create(Builder_->getUnknownLoc(), lambdaRef, inputs, attributesRef); + omegaBlock->push_back(lambda); + auto & lambdaRegion = lambda.getRegion(); + auto * lambdaBlock = new mlir::Block; + lambdaRegion.push_back(lambdaBlock); + + // Add arguments to the region + std::cout << "Adding arguments to the region" << std::endl; + lambdaBlock->addArgument(Builder_->getType(), Builder_->getUnknownLoc()); + lambdaBlock->addArgument(Builder_->getType(), Builder_->getUnknownLoc()); + + ::llvm::SmallVector<::mlir::NamedAttribute> thetaAttributes; + ::llvm::SmallVector<::mlir::Type> typeRangeOuput; + typeRangeOuput.push_back(Builder_->getType()); + typeRangeOuput.push_back(Builder_->getType()); + ::mlir::rvsdg::ThetaNode theta = Builder_->create<::mlir::rvsdg::ThetaNode>( + Builder_->getUnknownLoc(), + ::mlir::TypeRange(::llvm::ArrayRef(typeRangeOuput)), // Ouputs types + ::mlir::ValueRange(::llvm::ArrayRef<::mlir::Value>( + { lambdaBlock->getArgument(0), lambdaBlock->getArgument(1) })), // Inputs + thetaAttributes); + lambdaBlock->push_back(theta); + + auto & thetaBlock = theta.getRegion().emplaceBlock(); + auto predicate = Builder_->create( + Builder_->getUnknownLoc(), + Builder_->getType<::mlir::rvsdg::RVSDG_CTRLType>(2), + 0); + thetaBlock.push_back(predicate); + + auto thetaResult = Builder_->create<::mlir::rvsdg::ThetaResult>( + Builder_->getUnknownLoc(), + predicate, + ::llvm::SmallVector(theta.getInputs())); + thetaBlock.push_back(thetaResult); + + // Handle the result of the lambda + ::llvm::SmallVector regionResults; + regionResults.push_back(theta->getResult(0)); + regionResults.push_back(theta->getResult(1)); + std::cout << "Creating LambdaResult" << std::endl; + auto lambdaResult = Builder_->create(Builder_->getUnknownLoc(), regionResults); + lambdaBlock->push_back(lambdaResult); + + // Handle the result of the omega + std::cout << "Creating OmegaResult" << std::endl; + ::llvm::SmallVector omegaRegionResults; + omegaRegionResults.push_back(lambda); + auto omegaResult = Builder_->create(Builder_->getUnknownLoc(), omegaRegionResults); + omegaBlock->push_back(omegaResult); + + // Convert the MLIR to RVSDG and check the result + std::cout << "Converting MLIR to RVSDG" << std::endl; + std::unique_ptr rootBlock = std::make_unique(); + rootBlock->push_back(omega); + auto rvsdgModule = jlm::mlir::MlirToJlmConverter::CreateAndConvert(rootBlock); + auto region = rvsdgModule->Rvsdg().root(); + + { + using namespace jlm::rvsdg; + + assert(region->nnodes() == 1); + + // Get the lambda block + auto convertedLambda = + jlm::util::AssertedCast(region->nodes.first()); + assert(is(convertedLambda)); + + auto lambdaRegion = convertedLambda->subregion(); + + // Just the theta node + assert(lambdaRegion->nnodes() == 1); + + jlm::rvsdg::node_output * thetaOutput; + assert( + thetaOutput = dynamic_cast(lambdaRegion->result(0)->origin())); + jlm::rvsdg::node * node = thetaOutput->node(); + assert(is(node->operation())); + auto thetaNode = dynamic_cast(node); + + std::cout << "Checking theta node" << std::endl; + assert(thetaNode->ninputs() == 2); + assert(thetaNode->nloopvars() == 2); + assert(thetaNode->noutputs() == 2); + assert(thetaNode->nsubregions() == 1); + assert(is(thetaNode->predicate()->type())); + auto predicateType = + dynamic_cast(&thetaNode->predicate()->type()); + assert(predicateType->nalternatives() == 2); + std::cout << predicate.getValue() << std::endl; + } + } + + return 0; +} + JLM_UNIT_TEST_REGISTER("jlm/mlir/frontend/TestRvsdgLambdaGen", TestLambda) JLM_UNIT_TEST_REGISTER("jlm/mlir/frontend/TestRvsdgDivOperationGen", TestDivOperation) JLM_UNIT_TEST_REGISTER("jlm/mlir/frontend/TestRvsdgCompZeroExtGen", TestCompZeroExt) JLM_UNIT_TEST_REGISTER("jlm/mlir/frontend/TestMatchGen", TestMatchOp) JLM_UNIT_TEST_REGISTER("jlm/mlir/frontend/TestGammaGen", TestGammaOp) +JLM_UNIT_TEST_REGISTER("jlm/mlir/frontend/TestThetaGen", TestThetaOp)