[ir] Convert tests to use disassembler.
This Cl updates the flow node tests to compare against a disassembled output instead of explicit expect statements. This makes it easier to see the structure of the IR and to determine any changes. Bug: tint:1718 Change-Id: I5b8ab42ada4ba902e8937099c7058a39533f2010 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116548 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
e3992f2408
commit
97b98619e8
|
@ -31,6 +31,10 @@ class Block : public Castable<Block, FlowNode> {
|
|||
Block();
|
||||
~Block() override;
|
||||
|
||||
/// @returns true if this is a dead block. This can happen in the case like a loop merge block
|
||||
/// which is never reached.
|
||||
bool IsDead() const { return branch.target == nullptr; }
|
||||
|
||||
/// The node this block branches too.
|
||||
Branch branch = {};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -68,6 +68,8 @@ void Disassembler::EmitBlockInstructions(const Block* b) {
|
|||
}
|
||||
|
||||
size_t Disassembler::GetIdForNode(const FlowNode* node) {
|
||||
TINT_ASSERT(IR, node);
|
||||
|
||||
auto it = flow_node_to_id_.find(node);
|
||||
if (it != flow_node_to_id_.end()) {
|
||||
return it->second;
|
||||
|
@ -97,6 +99,12 @@ void Disassembler::Walk(const FlowNode* node) {
|
|||
Walk(f->end_target);
|
||||
},
|
||||
[&](const ir::Block* b) {
|
||||
// If this block is dead, nothing to do
|
||||
if (b->IsDead()) {
|
||||
Indent() << "# Dead" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Indent() << "%bb" << GetIdForNode(b) << " = Block" << std::endl;
|
||||
EmitBlockInstructions(b);
|
||||
|
||||
|
@ -113,7 +121,11 @@ void Disassembler::Walk(const FlowNode* node) {
|
|||
}
|
||||
v->ToString(out_, mod_.symbols);
|
||||
}
|
||||
out_ << ")" << std::endl << std::endl;
|
||||
out_ << ")" << std::endl;
|
||||
|
||||
if (!b->branch.target->Is<Terminator>()) {
|
||||
out_ << std::endl;
|
||||
}
|
||||
|
||||
Walk(b->branch.target);
|
||||
},
|
||||
|
@ -128,14 +140,17 @@ void Disassembler::Walk(const FlowNode* node) {
|
|||
for (const auto& c : s->cases) {
|
||||
Indent() << "# Case ";
|
||||
for (const auto& selector : c.selectors) {
|
||||
if (&selector != &c.selectors.Front()) {
|
||||
out_ << " ";
|
||||
}
|
||||
|
||||
if (selector.IsDefault()) {
|
||||
out_ << "default ";
|
||||
out_ << "default";
|
||||
} else {
|
||||
selector.val->ToString(out_, mod_.symbols);
|
||||
}
|
||||
}
|
||||
out_ << std::endl;
|
||||
ScopedIndent case_indent(&indent_size_);
|
||||
Walk(c.start.target);
|
||||
}
|
||||
}
|
||||
|
@ -159,8 +174,10 @@ void Disassembler::Walk(const FlowNode* node) {
|
|||
Walk(i->false_.target);
|
||||
}
|
||||
|
||||
Indent() << "# if merge" << std::endl;
|
||||
Walk(i->merge.target);
|
||||
if (!i->merge.target->IsDisconnected()) {
|
||||
Indent() << "# if merge" << std::endl;
|
||||
Walk(i->merge.target);
|
||||
}
|
||||
},
|
||||
[&](const ir::Loop* l) {
|
||||
Indent() << "%bb" << GetIdForNode(l) << " = loop" << std::endl;
|
||||
|
@ -174,7 +191,6 @@ void Disassembler::Walk(const FlowNode* node) {
|
|||
}
|
||||
|
||||
Indent() << "# loop continuing" << std::endl;
|
||||
ScopedIndent continuing_indent(&indent_size_);
|
||||
Walk(l->continuing.target);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@ class FlowNode : public Castable<FlowNode> {
|
|||
/// - Node is a continue target outside control flow (loop that returns)
|
||||
utils::Vector<FlowNode*, 2> inbound_branches;
|
||||
|
||||
/// @returns true if this node has no inbound branches
|
||||
bool IsDisconnected() const { return inbound_branches.IsEmpty(); }
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
FlowNode();
|
||||
|
|
|
@ -37,7 +37,7 @@ class If : public Castable<If, FlowNode> {
|
|||
Branch true_ = {};
|
||||
/// The false branch block
|
||||
Branch false_ = {};
|
||||
/// An block to reconvert the true/false barnches. The block always exists, but there maybe no
|
||||
/// An block to converge the true/false branches. The block always exists, but there maybe no
|
||||
/// branches into it. (e.g. if both branches `return`)
|
||||
Branch merge = {};
|
||||
/// Value holding the condition result
|
||||
|
|
|
@ -92,6 +92,13 @@ class TestHelperBase : public BASE, public ProgramBuilder {
|
|||
return gen_->FlowNodeForAstNode(node);
|
||||
}
|
||||
|
||||
/// @param mod the module
|
||||
/// @returns the disassembly string of the module
|
||||
std::string Disassemble(Module& mod) const {
|
||||
Disassembler d(mod);
|
||||
return d.Disassemble();
|
||||
}
|
||||
|
||||
/// @returns the error generated during build, if any
|
||||
std::string Error() const { return error_; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue