[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>
This commit is contained in:
dan sinclair 2023-05-25 04:56:11 +00:00 committed by Dawn LUCI CQ
parent 9083f431b8
commit a00fe39f3e
10 changed files with 32 additions and 101 deletions

View File

@ -1232,8 +1232,6 @@ if (tint_build_ir) {
"ir/disassembler.h", "ir/disassembler.h",
"ir/discard.cc", "ir/discard.cc",
"ir/discard.h", "ir/discard.h",
"ir/flow_node.cc",
"ir/flow_node.h",
"ir/function.cc", "ir/function.cc",
"ir/function.h", "ir/function.h",
"ir/function_param.cc", "ir/function_param.cc",

View File

@ -742,8 +742,6 @@ if(${TINT_BUILD_IR})
ir/discard.h ir/discard.h
ir/from_program.cc ir/from_program.cc
ir/from_program.h ir/from_program.h
ir/flow_node.cc
ir/flow_node.h
ir/function.cc ir/function.cc
ir/function.h ir/function.h
ir/function_param.cc ir/function_param.cc

View File

@ -19,16 +19,15 @@
#include "src/tint/ir/block_param.h" #include "src/tint/ir/block_param.h"
#include "src/tint/ir/branch.h" #include "src/tint/ir/branch.h"
#include "src/tint/ir/flow_node.h"
#include "src/tint/ir/instruction.h" #include "src/tint/ir/instruction.h"
#include "src/tint/utils/vector.h" #include "src/tint/utils/vector.h"
namespace tint::ir { namespace tint::ir {
/// A flow node comprising a block of statements. The instructions in the block are a linear list of /// A block of statements. The instructions in the block are a linear list of instructions to
/// instructions to execute. The block will branch at the end. The only blocks which do not branch /// execute. The block will branch at the end. The only blocks which do not branch are the end
/// are the end blocks of functions. /// blocks of functions.
class Block : public utils::Castable<Block, FlowNode> { class Block : public utils::Castable<Block> {
public: public:
/// Constructor /// Constructor
Block(); Block();
@ -81,7 +80,7 @@ class Block : public utils::Castable<Block, FlowNode> {
/// @returns true if this node has inbound branches and branches out /// @returns true if this node has inbound branches and branches out
bool IsConnected() const { return HasBranchTarget(); } 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_; } utils::VectorRef<ir::Branch*> InboundBranches() const { return inbound_branches_; }
/// Adds the given node to the inbound branches /// Adds the given node to the inbound branches
@ -92,7 +91,7 @@ class Block : public utils::Castable<Block, FlowNode> {
utils::Vector<const Instruction*, 16> instructions_; utils::Vector<const Instruction*, 16> instructions_;
utils::Vector<const BlockParam*, 0> params_; 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: /// reasons:
/// - Node is a start node /// - Node is a start node
/// - Node is a merge target outside control flow (e.g. an if that returns in both branches) /// - Node is a merge target outside control flow (e.g. an if that returns in both branches)

View File

@ -34,15 +34,15 @@ ir::Block* Builder::CreateRootBlockIfNeeded() {
} }
Block* Builder::CreateBlock() { Block* Builder::CreateBlock() {
return ir.flow_nodes.Create<Block>(); return ir.blocks.Create<Block>();
} }
RootTerminator* Builder::CreateRootTerminator() { RootTerminator* Builder::CreateRootTerminator() {
return ir.flow_nodes.Create<RootTerminator>(); return ir.blocks.Create<RootTerminator>();
} }
FunctionTerminator* Builder::CreateFunctionTerminator() { FunctionTerminator* Builder::CreateFunctionTerminator() {
return ir.flow_nodes.Create<FunctionTerminator>(); return ir.blocks.Create<FunctionTerminator>();
} }
Function* Builder::CreateFunction(std::string_view name, Function* Builder::CreateFunction(std::string_view name,

View File

@ -29,44 +29,44 @@ namespace tint::ir {
// static // static
std::string Debug::AsDotGraph(const Module* mod) { 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*> visited;
std::unordered_set<const Block*> merge_nodes; std::unordered_set<const Block*> merge_blocks;
std::unordered_map<const FlowNode*, std::string> node_to_name; std::unordered_map<const Block*, std::string> block_to_name;
utils::StringStream out; utils::StringStream out;
auto name_for = [&](const FlowNode* node) -> std::string { auto name_for = [&](const Block* blk) -> std::string {
if (node_to_name.count(node) > 0) { if (block_to_name.count(blk) > 0) {
return node_to_name[node]; return block_to_name[blk];
} }
std::string name = "node_" + std::to_string(node_count); std::string name = "blk_" + std::to_string(block_count);
node_count += 1; block_count += 1;
node_to_name[node] = name; block_to_name[blk] = name;
return name; return name;
}; };
std::function<void(const Block*)> Graph = [&](const Block* node) { std::function<void(const Block*)> Graph = [&](const Block* blk) {
if (visited.count(node) > 0) { if (visited.count(blk) > 0) {
return; return;
} }
visited.insert(node); visited.insert(blk);
tint::Switch( tint::Switch(
node, blk,
[&](const ir::FunctionTerminator*) { [&](const ir::FunctionTerminator*) {
// Already done // Already done
}, },
[&](const ir::Block* b) { [&](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) << R"( [label="block"])" << std::endl;
} }
out << name_for(b) << " -> " << name_for(b->Branch()->To()); out << name_for(b) << " -> " << name_for(b->Branch()->To());
// Dashed lines to merge blocks // Dashed lines to merge blocks
if (merge_nodes.count(b->Branch()->To()) != 0) { if (merge_blocks.count(b->Branch()->To()) != 0) {
out << " [style=dashed]"; out << " [style=dashed]";
} }

View File

@ -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); 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) { std::string_view Disassembler::IdOf(const Value* value) {

View File

@ -18,8 +18,8 @@
#include <string> #include <string>
#include "src/tint/ir/binary.h" #include "src/tint/ir/binary.h"
#include "src/tint/ir/block.h"
#include "src/tint/ir/call.h" #include "src/tint/ir/call.h"
#include "src/tint/ir/flow_node.h"
#include "src/tint/ir/if.h" #include "src/tint/ir/if.h"
#include "src/tint/ir/loop.h" #include "src/tint/ir/loop.h"
#include "src/tint/ir/module.h" #include "src/tint/ir/module.h"
@ -53,7 +53,7 @@ class Disassembler {
private: private:
utils::StringStream& Indent(); utils::StringStream& Indent();
size_t IdOf(const FlowNode* node); size_t IdOf(const Block* blk);
std::string_view IdOf(const Value* node); std::string_view IdOf(const Value* node);
void Walk(const Block* blk); void Walk(const Block* blk);
@ -72,7 +72,7 @@ class Disassembler {
const Module& mod_; const Module& mod_;
utils::StringStream out_; utils::StringStream out_;
utils::Hashset<const Block*, 32> visited_; 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_; utils::Hashmap<const Value*, std::string, 32> value_ids_;
uint32_t indent_size_ = 0; uint32_t indent_size_ = 0;
bool in_function_ = false; bool in_function_ = false;

View File

@ -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

View File

@ -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_

View File

@ -18,8 +18,8 @@
#include <string> #include <string>
#include "src/tint/constant/manager.h" #include "src/tint/constant/manager.h"
#include "src/tint/ir/block.h"
#include "src/tint/ir/constant.h" #include "src/tint/ir/constant.h"
#include "src/tint/ir/flow_node.h"
#include "src/tint/ir/function.h" #include "src/tint/ir/function.h"
#include "src/tint/ir/instruction.h" #include "src/tint/ir/instruction.h"
#include "src/tint/ir/value.h" #include "src/tint/ir/value.h"
@ -69,8 +69,8 @@ class Module {
/// @return the type manager for the module /// @return the type manager for the module
type::Manager& Types() { return constant_values.types; } type::Manager& Types() { return constant_values.types; }
/// The flow node allocator /// The block allocator
utils::BlockAllocator<FlowNode> flow_nodes; utils::BlockAllocator<Block> blocks;
/// The constant value manager /// The constant value manager
constant::Manager constant_values; constant::Manager constant_values;