[ir] Remove FlowNode.
The `Block` is now the basis, there is no need for `FlowNode` anymore.
Bug: tint:1718
Change-Id: I4834c442e2b1dd24a708822fc04e68e88f13d7a5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134302
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index c4e323d..7e2444c 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -1232,8 +1232,6 @@
"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 1f7ed9d..ffb4d9d 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -742,8 +742,6 @@
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 7c3b530..dc0f596 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<Block, FlowNode> {
+/// 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<Block> {
public:
/// Constructor
Block();
@@ -81,7 +80,7 @@
/// @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<ir::Branch*> InboundBranches() const { return inbound_branches_; }
/// Adds the given node to the inbound branches
@@ -92,7 +91,7 @@
utils::Vector<const Instruction*, 16> instructions_;
utils::Vector<const BlockParam*, 0> 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 603f305..77c56c8 100644
--- a/src/tint/ir/builder.cc
+++ b/src/tint/ir/builder.cc
@@ -34,15 +34,15 @@
}
Block* Builder::CreateBlock() {
- return ir.flow_nodes.Create<Block>();
+ return ir.blocks.Create<Block>();
}
RootTerminator* Builder::CreateRootTerminator() {
- return ir.flow_nodes.Create<RootTerminator>();
+ return ir.blocks.Create<RootTerminator>();
}
FunctionTerminator* Builder::CreateFunctionTerminator() {
- return ir.flow_nodes.Create<FunctionTerminator>();
+ return ir.blocks.Create<FunctionTerminator>();
}
Function* Builder::CreateFunction(std::string_view name,
diff --git a/src/tint/ir/debug.cc b/src/tint/ir/debug.cc
index 337671d..ea6363e 100644
--- a/src/tint/ir/debug.cc
+++ b/src/tint/ir/debug.cc
@@ -29,44 +29,44 @@
// static
std::string Debug::AsDotGraph(const Module* mod) {
- size_t node_count = 0;
+ size_t block_count = 0;
std::unordered_set<const Block*> visited;
- std::unordered_set<const Block*> merge_nodes;
- std::unordered_map<const FlowNode*, std::string> node_to_name;
+ std::unordered_set<const Block*> merge_blocks;
+ std::unordered_map<const Block*, std::string> 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<void(const Block*)> Graph = [&](const Block* node) {
- if (visited.count(node) > 0) {
+ std::function<void(const Block*)> 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 847a031..3001258 100644
--- a/src/tint/ir/disassembler.cc
+++ b/src/tint/ir/disassembler.cc
@@ -72,9 +72,9 @@
}
}
-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 ff89ad3..f171031 100644
--- a/src/tint/ir/disassembler.h
+++ b/src/tint/ir/disassembler.h
@@ -18,8 +18,8 @@
#include <string>
#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 @@
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 @@
const Module& mod_;
utils::StringStream out_;
utils::Hashset<const Block*, 32> visited_;
- utils::Hashmap<const FlowNode*, size_t, 32> flow_node_ids_;
+ utils::Hashmap<const Block*, size_t, 32> block_ids_;
utils::Hashmap<const Value*, std::string, 32> 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 bbbd78b..0000000
--- 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 1b5aabe..0000000
--- 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<FlowNode> {
- 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 cabbf11..1520888 100644
--- a/src/tint/ir/module.h
+++ b/src/tint/ir/module.h
@@ -18,8 +18,8 @@
#include <string>
#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 @@
/// @return the type manager for the module
type::Manager& Types() { return constant_values.types; }
- /// The flow node allocator
- utils::BlockAllocator<FlowNode> flow_nodes;
+ /// The block allocator
+ utils::BlockAllocator<Block> blocks;
/// The constant value manager
constant::Manager constant_values;