[ir] Change base class for terminators.
This CL moves the FunctionTerminator and RootTerminator nodes to be blocks instead of FlowNodes. Bug: tint:1718 Change-Id: Iee7830bccd99e4587b95b22b53268d1d2921e82f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134222 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
e9a4adeff9
commit
0089d5e6e2
|
@ -56,6 +56,9 @@ std::string Debug::AsDotGraph(const Module* mod) {
|
||||||
|
|
||||||
tint::Switch(
|
tint::Switch(
|
||||||
node,
|
node,
|
||||||
|
[&](const ir::FunctionTerminator*) {
|
||||||
|
// Already done
|
||||||
|
},
|
||||||
[&](const ir::Block* b) {
|
[&](const ir::Block* b) {
|
||||||
if (node_to_name.count(b) == 0) {
|
if (node_to_name.count(b) == 0) {
|
||||||
out << name_for(b) << R"( [label="block"])" << std::endl;
|
out << name_for(b) << R"( [label="block"])" << std::endl;
|
||||||
|
@ -69,9 +72,6 @@ std::string Debug::AsDotGraph(const Module* mod) {
|
||||||
|
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
Graph(b->Branch()->To());
|
Graph(b->Branch()->To());
|
||||||
},
|
|
||||||
[&](const ir::FunctionTerminator*) {
|
|
||||||
// Already done
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,15 @@ void Disassembler::Walk() {
|
||||||
out_ << " -> %fn" << IdOf(f->StartTarget()) << std::endl;
|
out_ << " -> %fn" << IdOf(f->StartTarget()) << std::endl;
|
||||||
walk_list_.push_back(f->StartTarget());
|
walk_list_.push_back(f->StartTarget());
|
||||||
},
|
},
|
||||||
|
[&](const ir::FunctionTerminator* t) {
|
||||||
|
TINT_ASSERT(IR, in_function_);
|
||||||
|
Indent() << "%fn" << IdOf(t) << " = func_terminator" << std::endl << std::endl;
|
||||||
|
in_function_ = false;
|
||||||
|
},
|
||||||
|
[&](const ir::RootTerminator* t) {
|
||||||
|
TINT_ASSERT(IR, !in_function_);
|
||||||
|
Indent() << "%fn" << IdOf(t) << " = root_terminator" << std::endl << std::endl;
|
||||||
|
},
|
||||||
[&](const ir::Block* b) {
|
[&](const ir::Block* b) {
|
||||||
// If this block is dead, nothing to do
|
// If this block is dead, nothing to do
|
||||||
if (!b->HasBranchTarget()) {
|
if (!b->HasBranchTarget()) {
|
||||||
|
@ -183,15 +192,6 @@ void Disassembler::Walk() {
|
||||||
}
|
}
|
||||||
|
|
||||||
walk_list_.push_back(b->Branch()->To());
|
walk_list_.push_back(b->Branch()->To());
|
||||||
},
|
|
||||||
[&](const ir::FunctionTerminator* t) {
|
|
||||||
TINT_ASSERT(IR, in_function_);
|
|
||||||
Indent() << "%fn" << IdOf(t) << " = func_terminator" << std::endl << std::endl;
|
|
||||||
in_function_ = false;
|
|
||||||
},
|
|
||||||
[&](const ir::RootTerminator* t) {
|
|
||||||
TINT_ASSERT(IR, !in_function_);
|
|
||||||
Indent() << "%fn" << IdOf(t) << " = root_terminator" << std::endl << std::endl;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@
|
||||||
#ifndef SRC_TINT_IR_FUNCTION_TERMINATOR_H_
|
#ifndef SRC_TINT_IR_FUNCTION_TERMINATOR_H_
|
||||||
#define SRC_TINT_IR_FUNCTION_TERMINATOR_H_
|
#define SRC_TINT_IR_FUNCTION_TERMINATOR_H_
|
||||||
|
|
||||||
#include "src/tint/ir/flow_node.h"
|
#include "src/tint/ir/block.h"
|
||||||
|
|
||||||
namespace tint::ir {
|
namespace tint::ir {
|
||||||
|
|
||||||
/// Flow node used as the end of a function. Must only be used as the `end_target` in a function
|
/// Block used as the end of a function. Must only be used as the `end_target` in a function. There
|
||||||
/// flow node. There are no instructions and no branches from this node.
|
/// are no instructions in this block.
|
||||||
class FunctionTerminator : public utils::Castable<FunctionTerminator, FlowNode> {
|
class FunctionTerminator : public utils::Castable<FunctionTerminator, Block> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
FunctionTerminator();
|
FunctionTerminator();
|
||||||
|
|
|
@ -15,13 +15,12 @@
|
||||||
#ifndef SRC_TINT_IR_ROOT_TERMINATOR_H_
|
#ifndef SRC_TINT_IR_ROOT_TERMINATOR_H_
|
||||||
#define SRC_TINT_IR_ROOT_TERMINATOR_H_
|
#define SRC_TINT_IR_ROOT_TERMINATOR_H_
|
||||||
|
|
||||||
#include "src/tint/ir/flow_node.h"
|
#include "src/tint/ir/block.h"
|
||||||
|
|
||||||
namespace tint::ir {
|
namespace tint::ir {
|
||||||
|
|
||||||
/// Flow node used as the end of a function. Must only be used as the `end_target` in a function
|
/// Block used as the end of a root block. There are no instructions in this block.
|
||||||
/// flow node. There are no instructions and no branches from this node.
|
class RootTerminator : public utils::Castable<RootTerminator, Block> {
|
||||||
class RootTerminator : public utils::Castable<RootTerminator, FlowNode> {
|
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
RootTerminator();
|
RootTerminator();
|
||||||
|
|
|
@ -126,6 +126,8 @@ class State {
|
||||||
Status status = tint::Switch(
|
Status status = tint::Switch(
|
||||||
block,
|
block,
|
||||||
|
|
||||||
|
[&](const ir::FunctionTerminator*) { return kStop; },
|
||||||
|
|
||||||
[&](const ir::Block* blk) {
|
[&](const ir::Block* blk) {
|
||||||
for (auto* inst : blk->Instructions()) {
|
for (auto* inst : blk->Instructions()) {
|
||||||
auto stmt = Stmt(inst);
|
auto stmt = Stmt(inst);
|
||||||
|
@ -150,8 +152,6 @@ class State {
|
||||||
return kStop;
|
return kStop;
|
||||||
},
|
},
|
||||||
|
|
||||||
[&](const ir::FunctionTerminator*) { return kStop; },
|
|
||||||
|
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
UNHANDLED_CASE(block);
|
UNHANDLED_CASE(block);
|
||||||
return kError;
|
return kError;
|
||||||
|
|
|
@ -355,7 +355,6 @@ void GeneratorImplIr::EmitBlock(const ir::Block* block) {
|
||||||
void GeneratorImplIr::EmitBranch(const ir::Branch* b) {
|
void GeneratorImplIr::EmitBranch(const ir::Branch* b) {
|
||||||
Switch(
|
Switch(
|
||||||
b->To(),
|
b->To(),
|
||||||
[&](const ir::Block* blk) { current_function_.push_inst(spv::Op::OpBranch, {Label(blk)}); },
|
|
||||||
[&](const ir::FunctionTerminator*) {
|
[&](const ir::FunctionTerminator*) {
|
||||||
if (!b->Args().IsEmpty()) {
|
if (!b->Args().IsEmpty()) {
|
||||||
TINT_ASSERT(Writer, b->Args().Length() == 1u);
|
TINT_ASSERT(Writer, b->Args().Length() == 1u);
|
||||||
|
@ -366,6 +365,7 @@ void GeneratorImplIr::EmitBranch(const ir::Branch* b) {
|
||||||
current_function_.push_inst(spv::Op::OpReturn, {});
|
current_function_.push_inst(spv::Op::OpReturn, {});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
[&](const ir::Block* blk) { current_function_.push_inst(spv::Op::OpBranch, {Label(blk)}); },
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
// A block may not have an outward branch (e.g. an unreachable merge
|
// A block may not have an outward branch (e.g. an unreachable merge
|
||||||
// block).
|
// block).
|
||||||
|
|
Loading…
Reference in New Issue