diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index c4e323d652..7e2444ceaf 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -1232,8 +1232,6 @@ if (tint_build_ir) { "ir/disassembler.h", "ir/discard.cc", "ir/discard.h", - "ir/flow_node.cc", - "ir/flow_node.h", "ir/function.cc", "ir/function.h", "ir/function_param.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 1f7ed9df8a..ffb4d9d403 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -742,8 +742,6 @@ if(${TINT_BUILD_IR}) ir/discard.h ir/from_program.cc ir/from_program.h - ir/flow_node.cc - ir/flow_node.h ir/function.cc ir/function.h ir/function_param.cc diff --git a/src/tint/ir/block.h b/src/tint/ir/block.h index 7c3b530dbd..dc0f59649f 100644 --- a/src/tint/ir/block.h +++ b/src/tint/ir/block.h @@ -19,16 +19,15 @@ #include "src/tint/ir/block_param.h" #include "src/tint/ir/branch.h" -#include "src/tint/ir/flow_node.h" #include "src/tint/ir/instruction.h" #include "src/tint/utils/vector.h" namespace tint::ir { -/// A flow node comprising a block of statements. The instructions in the block are a linear list of -/// instructions to execute. The block will branch at the end. The only blocks which do not branch -/// are the end blocks of functions. -class Block : public utils::Castable { +/// A block of statements. The instructions in the block are a linear list of instructions to +/// execute. The block will branch at the end. The only blocks which do not branch are the end +/// blocks of functions. +class Block : public utils::Castable { public: /// Constructor Block(); @@ -81,7 +80,7 @@ class Block : public utils::Castable { /// @returns true if this node has inbound branches and branches out bool IsConnected() const { return HasBranchTarget(); } - /// @returns the inbound branch list for the flow node + /// @returns the inbound branch list for the block utils::VectorRef InboundBranches() const { return inbound_branches_; } /// Adds the given node to the inbound branches @@ -92,7 +91,7 @@ class Block : public utils::Castable { utils::Vector instructions_; utils::Vector params_; - /// The list of flow nodes which branch into this node. This list maybe empty for several + /// The list of branches into this node. This list maybe empty for several /// reasons: /// - Node is a start node /// - Node is a merge target outside control flow (e.g. an if that returns in both branches) diff --git a/src/tint/ir/builder.cc b/src/tint/ir/builder.cc index 603f305717..77c56c8202 100644 --- a/src/tint/ir/builder.cc +++ b/src/tint/ir/builder.cc @@ -34,15 +34,15 @@ ir::Block* Builder::CreateRootBlockIfNeeded() { } Block* Builder::CreateBlock() { - return ir.flow_nodes.Create(); + return ir.blocks.Create(); } RootTerminator* Builder::CreateRootTerminator() { - return ir.flow_nodes.Create(); + return ir.blocks.Create(); } FunctionTerminator* Builder::CreateFunctionTerminator() { - return ir.flow_nodes.Create(); + return ir.blocks.Create(); } Function* Builder::CreateFunction(std::string_view name, diff --git a/src/tint/ir/debug.cc b/src/tint/ir/debug.cc index 337671d953..ea6363e05b 100644 --- a/src/tint/ir/debug.cc +++ b/src/tint/ir/debug.cc @@ -29,44 +29,44 @@ namespace tint::ir { // static std::string Debug::AsDotGraph(const Module* mod) { - size_t node_count = 0; + size_t block_count = 0; std::unordered_set visited; - std::unordered_set merge_nodes; - std::unordered_map node_to_name; + std::unordered_set merge_blocks; + std::unordered_map block_to_name; utils::StringStream out; - auto name_for = [&](const FlowNode* node) -> std::string { - if (node_to_name.count(node) > 0) { - return node_to_name[node]; + auto name_for = [&](const Block* blk) -> std::string { + if (block_to_name.count(blk) > 0) { + return block_to_name[blk]; } - std::string name = "node_" + std::to_string(node_count); - node_count += 1; + std::string name = "blk_" + std::to_string(block_count); + block_count += 1; - node_to_name[node] = name; + block_to_name[blk] = name; return name; }; - std::function Graph = [&](const Block* node) { - if (visited.count(node) > 0) { + std::function Graph = [&](const Block* blk) { + if (visited.count(blk) > 0) { return; } - visited.insert(node); + visited.insert(blk); tint::Switch( - node, + blk, [&](const ir::FunctionTerminator*) { // Already done }, [&](const ir::Block* b) { - if (node_to_name.count(b) == 0) { + if (block_to_name.count(b) == 0) { out << name_for(b) << R"( [label="block"])" << std::endl; } out << name_for(b) << " -> " << name_for(b->Branch()->To()); // Dashed lines to merge blocks - if (merge_nodes.count(b->Branch()->To()) != 0) { + if (merge_blocks.count(b->Branch()->To()) != 0) { out << " [style=dashed]"; } diff --git a/src/tint/ir/disassembler.cc b/src/tint/ir/disassembler.cc index 847a031776..3001258b34 100644 --- a/src/tint/ir/disassembler.cc +++ b/src/tint/ir/disassembler.cc @@ -72,9 +72,9 @@ void Disassembler::EmitBlockInstructions(const Block* b) { } } -size_t Disassembler::IdOf(const FlowNode* node) { +size_t Disassembler::IdOf(const Block* node) { TINT_ASSERT(IR, node); - return flow_node_ids_.GetOrCreate(node, [&] { return flow_node_ids_.Count(); }); + return block_ids_.GetOrCreate(node, [&] { return block_ids_.Count(); }); } std::string_view Disassembler::IdOf(const Value* value) { diff --git a/src/tint/ir/disassembler.h b/src/tint/ir/disassembler.h index ff89ad32f1..f17103145d 100644 --- a/src/tint/ir/disassembler.h +++ b/src/tint/ir/disassembler.h @@ -18,8 +18,8 @@ #include #include "src/tint/ir/binary.h" +#include "src/tint/ir/block.h" #include "src/tint/ir/call.h" -#include "src/tint/ir/flow_node.h" #include "src/tint/ir/if.h" #include "src/tint/ir/loop.h" #include "src/tint/ir/module.h" @@ -53,7 +53,7 @@ class Disassembler { private: utils::StringStream& Indent(); - size_t IdOf(const FlowNode* node); + size_t IdOf(const Block* blk); std::string_view IdOf(const Value* node); void Walk(const Block* blk); @@ -72,7 +72,7 @@ class Disassembler { const Module& mod_; utils::StringStream out_; utils::Hashset visited_; - utils::Hashmap flow_node_ids_; + utils::Hashmap block_ids_; utils::Hashmap value_ids_; uint32_t indent_size_ = 0; bool in_function_ = false; diff --git a/src/tint/ir/flow_node.cc b/src/tint/ir/flow_node.cc deleted file mode 100644 index bbbd78ba5f..0000000000 --- a/src/tint/ir/flow_node.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2022 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ir/flow_node.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ir::FlowNode); - -namespace tint::ir { - -FlowNode::FlowNode() = default; - -FlowNode::~FlowNode() = default; - -} // namespace tint::ir diff --git a/src/tint/ir/flow_node.h b/src/tint/ir/flow_node.h deleted file mode 100644 index 1b5aabe298..0000000000 --- a/src/tint/ir/flow_node.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2022 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_IR_FLOW_NODE_H_ -#define SRC_TINT_IR_FLOW_NODE_H_ - -#include "src/tint/utils/castable.h" - -// Forward Declarations -namespace tint::ir { -class Branch; -} // namespace tint::ir - -namespace tint::ir { - -/// Base class for flow nodes -class FlowNode : public utils::Castable { - public: - ~FlowNode() override; - - protected: - /// Constructor - FlowNode(); -}; - -} // namespace tint::ir - -#endif // SRC_TINT_IR_FLOW_NODE_H_ diff --git a/src/tint/ir/module.h b/src/tint/ir/module.h index cabbf11b45..15208889ee 100644 --- a/src/tint/ir/module.h +++ b/src/tint/ir/module.h @@ -18,8 +18,8 @@ #include #include "src/tint/constant/manager.h" +#include "src/tint/ir/block.h" #include "src/tint/ir/constant.h" -#include "src/tint/ir/flow_node.h" #include "src/tint/ir/function.h" #include "src/tint/ir/instruction.h" #include "src/tint/ir/value.h" @@ -69,8 +69,8 @@ class Module { /// @return the type manager for the module type::Manager& Types() { return constant_values.types; } - /// The flow node allocator - utils::BlockAllocator flow_nodes; + /// The block allocator + utils::BlockAllocator blocks; /// The constant value manager constant::Manager constant_values;