shader_recompiler: GCC fixes

Fixes members of unnamed union not being accessible, and one function
without a declaration.
This commit is contained in:
lat9nq 2021-05-16 17:06:13 -04:00 committed by ameerj
parent d4f9c798d6
commit f7a2340205
7 changed files with 55 additions and 58 deletions

View File

@ -212,14 +212,14 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) {
for (const IR::AbstractSyntaxNode& node : program.syntax_list) { for (const IR::AbstractSyntaxNode& node : program.syntax_list) {
switch (node.type) { switch (node.type) {
case IR::AbstractSyntaxNode::Type::Block: case IR::AbstractSyntaxNode::Type::Block:
for (IR::Inst& inst : node.block->Instructions()) { for (IR::Inst& inst : node.data.block->Instructions()) {
EmitInst(ctx, &inst); EmitInst(ctx, &inst);
} }
break; break;
case IR::AbstractSyntaxNode::Type::If: case IR::AbstractSyntaxNode::Type::If:
ctx.Add("MOV.S.CC RC,{};" ctx.Add("MOV.S.CC RC,{};"
"IF NE.x;", "IF NE.x;",
eval(node.if_node.cond)); eval(node.data.if_node.cond));
break; break;
case IR::AbstractSyntaxNode::Type::EndIf: case IR::AbstractSyntaxNode::Type::EndIf:
ctx.Add("ENDIF;"); ctx.Add("ENDIF;");
@ -228,8 +228,8 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) {
ctx.Add("REP;"); ctx.Add("REP;");
break; break;
case IR::AbstractSyntaxNode::Type::Repeat: case IR::AbstractSyntaxNode::Type::Repeat:
if (node.repeat.cond.IsImmediate()) { if (node.data.repeat.cond.IsImmediate()) {
if (node.repeat.cond.U1()) { if (node.data.repeat.cond.U1()) {
ctx.Add("ENDREP;"); ctx.Add("ENDREP;");
} else { } else {
ctx.Add("BRK;" ctx.Add("BRK;"
@ -239,18 +239,18 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) {
ctx.Add("MOV.S.CC RC,{};" ctx.Add("MOV.S.CC RC,{};"
"BRK (EQ.x);" "BRK (EQ.x);"
"ENDREP;", "ENDREP;",
eval(node.repeat.cond)); eval(node.data.repeat.cond));
} }
break; break;
case IR::AbstractSyntaxNode::Type::Break: case IR::AbstractSyntaxNode::Type::Break:
if (node.break_node.cond.IsImmediate()) { if (node.data.break_node.cond.IsImmediate()) {
if (node.break_node.cond.U1()) { if (node.data.break_node.cond.U1()) {
ctx.Add("BRK;"); ctx.Add("BRK;");
} }
} else { } else {
ctx.Add("MOV.S.CC RC,{};" ctx.Add("MOV.S.CC RC,{};"
"BRK (NE.x);", "BRK (NE.x);",
eval(node.break_node.cond)); eval(node.data.break_node.cond));
} }
break; break;
case IR::AbstractSyntaxNode::Type::Return: case IR::AbstractSyntaxNode::Type::Return:

View File

@ -105,7 +105,7 @@ void EmitBoundImageWrite(EmitContext&) {
throw LogicError("Unreachable instruction"); throw LogicError("Unreachable instruction");
} }
std::string Texture([[maybe_unused]] EmitContext& ctx, IR::TextureInstInfo info, static std::string Texture([[maybe_unused]] EmitContext& ctx, IR::TextureInstInfo info,
[[maybe_unused]] const IR::Value& index) { [[maybe_unused]] const IR::Value& index) {
// FIXME // FIXME
return fmt::format("texture[{}]", info.descriptor_index); return fmt::format("texture[{}]", info.descriptor_index);

View File

@ -112,48 +112,48 @@ void Traverse(EmitContext& ctx, IR::Program& program) {
for (const IR::AbstractSyntaxNode& node : program.syntax_list) { for (const IR::AbstractSyntaxNode& node : program.syntax_list) {
switch (node.type) { switch (node.type) {
case IR::AbstractSyntaxNode::Type::Block: { case IR::AbstractSyntaxNode::Type::Block: {
const Id label{node.block->Definition<Id>()}; const Id label{node.data.block->Definition<Id>()};
if (current_block) { if (current_block) {
ctx.OpBranch(label); ctx.OpBranch(label);
} }
current_block = node.block; current_block = node.data.block;
ctx.AddLabel(label); ctx.AddLabel(label);
for (IR::Inst& inst : node.block->Instructions()) { for (IR::Inst& inst : node.data.block->Instructions()) {
EmitInst(ctx, &inst); EmitInst(ctx, &inst);
} }
break; break;
} }
case IR::AbstractSyntaxNode::Type::If: { case IR::AbstractSyntaxNode::Type::If: {
const Id if_label{node.if_node.body->Definition<Id>()}; const Id if_label{node.data.if_node.body->Definition<Id>()};
const Id endif_label{node.if_node.merge->Definition<Id>()}; const Id endif_label{node.data.if_node.merge->Definition<Id>()};
ctx.OpSelectionMerge(endif_label, spv::SelectionControlMask::MaskNone); ctx.OpSelectionMerge(endif_label, spv::SelectionControlMask::MaskNone);
ctx.OpBranchConditional(ctx.Def(node.if_node.cond), if_label, endif_label); ctx.OpBranchConditional(ctx.Def(node.data.if_node.cond), if_label, endif_label);
break; break;
} }
case IR::AbstractSyntaxNode::Type::Loop: { case IR::AbstractSyntaxNode::Type::Loop: {
const Id body_label{node.loop.body->Definition<Id>()}; const Id body_label{node.data.loop.body->Definition<Id>()};
const Id continue_label{node.loop.continue_block->Definition<Id>()}; const Id continue_label{node.data.loop.continue_block->Definition<Id>()};
const Id endloop_label{node.loop.merge->Definition<Id>()}; const Id endloop_label{node.data.loop.merge->Definition<Id>()};
ctx.OpLoopMerge(endloop_label, continue_label, spv::LoopControlMask::MaskNone); ctx.OpLoopMerge(endloop_label, continue_label, spv::LoopControlMask::MaskNone);
ctx.OpBranch(body_label); ctx.OpBranch(body_label);
break; break;
} }
case IR::AbstractSyntaxNode::Type::Break: { case IR::AbstractSyntaxNode::Type::Break: {
const Id break_label{node.break_node.merge->Definition<Id>()}; const Id break_label{node.data.break_node.merge->Definition<Id>()};
const Id skip_label{node.break_node.skip->Definition<Id>()}; const Id skip_label{node.data.break_node.skip->Definition<Id>()};
ctx.OpBranchConditional(ctx.Def(node.break_node.cond), break_label, skip_label); ctx.OpBranchConditional(ctx.Def(node.data.break_node.cond), break_label, skip_label);
break; break;
} }
case IR::AbstractSyntaxNode::Type::EndIf: case IR::AbstractSyntaxNode::Type::EndIf:
if (current_block) { if (current_block) {
ctx.OpBranch(node.end_if.merge->Definition<Id>()); ctx.OpBranch(node.data.end_if.merge->Definition<Id>());
} }
break; break;
case IR::AbstractSyntaxNode::Type::Repeat: { case IR::AbstractSyntaxNode::Type::Repeat: {
const Id loop_header_label{node.repeat.loop_header->Definition<Id>()}; const Id loop_header_label{node.data.repeat.loop_header->Definition<Id>()};
const Id merge_label{node.repeat.merge->Definition<Id>()}; const Id merge_label{node.data.repeat.merge->Definition<Id>()};
ctx.OpBranchConditional(ctx.Def(node.repeat.cond), loop_header_label, merge_label); ctx.OpBranchConditional(ctx.Def(node.data.repeat.cond), loop_header_label, merge_label);
break; break;
} }
case IR::AbstractSyntaxNode::Type::Return: case IR::AbstractSyntaxNode::Type::Return:

View File

@ -13,10 +13,6 @@ namespace Shader::IR {
class Block; class Block;
struct AbstractSyntaxNode { struct AbstractSyntaxNode {
struct NonTrivialDummy {
NonTrivialDummy() {}
};
enum class Type { enum class Type {
Block, Block,
If, If,
@ -27,9 +23,7 @@ struct AbstractSyntaxNode {
Return, Return,
Unreachable, Unreachable,
}; };
Type type{}; union Data {
union {
NonTrivialDummy dummy{};
Block* block; Block* block;
struct { struct {
U1 cond; U1 cond;
@ -55,6 +49,9 @@ struct AbstractSyntaxNode {
Block* skip; Block* skip;
} break_node; } break_node;
}; };
Data data{};
Type type{};
}; };
using AbstractSyntaxList = std::vector<AbstractSyntaxNode>; using AbstractSyntaxList = std::vector<AbstractSyntaxNode>;

View File

@ -20,7 +20,7 @@ BlockList PostOrder(const AbstractSyntaxNode& root) {
if (root.type != AbstractSyntaxNode::Type::Block) { if (root.type != AbstractSyntaxNode::Type::Block) {
throw LogicError("First node in abstract syntax list root is not a block"); throw LogicError("First node in abstract syntax list root is not a block");
} }
Block* const first_block{root.block}; Block* const first_block{root.data.block};
visited.insert(first_block); visited.insert(first_block);
block_stack.push_back(first_block); block_stack.push_back(first_block);

View File

@ -22,7 +22,7 @@ IR::BlockList GenerateBlocks(const IR::AbstractSyntaxList& syntax_list) {
})}; })};
IR::BlockList blocks(std::ranges::distance(syntax_blocks)); IR::BlockList blocks(std::ranges::distance(syntax_blocks));
std::ranges::transform(syntax_blocks, blocks.begin(), std::ranges::transform(syntax_blocks, blocks.begin(),
[](const IR::AbstractSyntaxNode& node) { return node.block; }); [](const IR::AbstractSyntaxNode& node) { return node.data.block; });
return blocks; return blocks;
} }

View File

@ -655,8 +655,8 @@ public:
syntax_list{syntax_list_} { syntax_list{syntax_list_} {
Visit(root_stmt, nullptr, nullptr); Visit(root_stmt, nullptr, nullptr);
IR::Block& first_block{*syntax_list.front().block}; IR::Block& first_block{*syntax_list.front().data.block};
IR::IREmitter ir{first_block, first_block.begin()}; IR::IREmitter ir = IR::IREmitter(first_block, first_block.begin());
ir.Prologue(); ir.Prologue();
} }
@ -670,7 +670,7 @@ private:
current_block = block_pool.Create(inst_pool); current_block = block_pool.Create(inst_pool);
auto& node{syntax_list.emplace_back()}; auto& node{syntax_list.emplace_back()};
node.type = IR::AbstractSyntaxNode::Type::Block; node.type = IR::AbstractSyntaxNode::Type::Block;
node.block = current_block; node.data.block = current_block;
}}; }};
Tree& tree{parent.children}; Tree& tree{parent.children};
for (auto it = tree.begin(); it != tree.end(); ++it) { for (auto it = tree.begin(); it != tree.end(); ++it) {
@ -713,24 +713,24 @@ private:
const size_t then_block_index{syntax_list.size()}; const size_t then_block_index{syntax_list.size()};
Visit(stmt, break_block, merge_block); Visit(stmt, break_block, merge_block);
IR::Block* const then_block{syntax_list.at(then_block_index).block}; IR::Block* const then_block{syntax_list.at(then_block_index).data.block};
current_block->AddBranch(then_block); current_block->AddBranch(then_block);
current_block->AddBranch(merge_block); current_block->AddBranch(merge_block);
current_block = merge_block; current_block = merge_block;
auto& if_node{syntax_list[if_node_index]}; auto& if_node{syntax_list[if_node_index]};
if_node.type = IR::AbstractSyntaxNode::Type::If; if_node.type = IR::AbstractSyntaxNode::Type::If;
if_node.if_node.cond = cond; if_node.data.if_node.cond = cond;
if_node.if_node.body = then_block; if_node.data.if_node.body = then_block;
if_node.if_node.merge = merge_block; if_node.data.if_node.merge = merge_block;
auto& endif_node{syntax_list.emplace_back()}; auto& endif_node{syntax_list.emplace_back()};
endif_node.type = IR::AbstractSyntaxNode::Type::EndIf; endif_node.type = IR::AbstractSyntaxNode::Type::EndIf;
endif_node.end_if.merge = merge_block; endif_node.data.end_if.merge = merge_block;
auto& merge{syntax_list.emplace_back()}; auto& merge{syntax_list.emplace_back()};
merge.type = IR::AbstractSyntaxNode::Type::Block; merge.type = IR::AbstractSyntaxNode::Type::Block;
merge.block = merge_block; merge.data.block = merge_block;
break; break;
} }
case StatementType::Loop: { case StatementType::Loop: {
@ -740,7 +740,7 @@ private:
} }
auto& header_node{syntax_list.emplace_back()}; auto& header_node{syntax_list.emplace_back()};
header_node.type = IR::AbstractSyntaxNode::Type::Block; header_node.type = IR::AbstractSyntaxNode::Type::Block;
header_node.block = loop_header_block; header_node.data.block = loop_header_block;
IR::Block* const continue_block{block_pool.Create(inst_pool)}; IR::Block* const continue_block{block_pool.Create(inst_pool)};
IR::Block* const merge_block{MergeBlock(parent, stmt)}; IR::Block* const merge_block{MergeBlock(parent, stmt)};
@ -757,7 +757,7 @@ private:
const IR::U1 cond{VisitExpr(ir, *stmt.cond)}; const IR::U1 cond{VisitExpr(ir, *stmt.cond)};
ir.DummyReference(cond); ir.DummyReference(cond);
IR::Block* const body_block{syntax_list.at(body_block_index).block}; IR::Block* const body_block{syntax_list.at(body_block_index).data.block};
loop_header_block->AddBranch(body_block); loop_header_block->AddBranch(body_block);
continue_block->AddBranch(loop_header_block); continue_block->AddBranch(loop_header_block);
@ -767,23 +767,23 @@ private:
auto& loop{syntax_list[loop_node_index]}; auto& loop{syntax_list[loop_node_index]};
loop.type = IR::AbstractSyntaxNode::Type::Loop; loop.type = IR::AbstractSyntaxNode::Type::Loop;
loop.loop.body = body_block; loop.data.loop.body = body_block;
loop.loop.continue_block = continue_block; loop.data.loop.continue_block = continue_block;
loop.loop.merge = merge_block; loop.data.loop.merge = merge_block;
auto& continue_block_node{syntax_list.emplace_back()}; auto& continue_block_node{syntax_list.emplace_back()};
continue_block_node.type = IR::AbstractSyntaxNode::Type::Block; continue_block_node.type = IR::AbstractSyntaxNode::Type::Block;
continue_block_node.block = continue_block; continue_block_node.data.block = continue_block;
auto& repeat{syntax_list.emplace_back()}; auto& repeat{syntax_list.emplace_back()};
repeat.type = IR::AbstractSyntaxNode::Type::Repeat; repeat.type = IR::AbstractSyntaxNode::Type::Repeat;
repeat.repeat.cond = cond; repeat.data.repeat.cond = cond;
repeat.repeat.loop_header = loop_header_block; repeat.data.repeat.loop_header = loop_header_block;
repeat.repeat.merge = merge_block; repeat.data.repeat.merge = merge_block;
auto& merge{syntax_list.emplace_back()}; auto& merge{syntax_list.emplace_back()};
merge.type = IR::AbstractSyntaxNode::Type::Block; merge.type = IR::AbstractSyntaxNode::Type::Block;
merge.block = merge_block; merge.data.block = merge_block;
break; break;
} }
case StatementType::Break: { case StatementType::Break: {
@ -799,13 +799,13 @@ private:
auto& break_node{syntax_list.emplace_back()}; auto& break_node{syntax_list.emplace_back()};
break_node.type = IR::AbstractSyntaxNode::Type::Break; break_node.type = IR::AbstractSyntaxNode::Type::Break;
break_node.break_node.cond = cond; break_node.data.break_node.cond = cond;
break_node.break_node.merge = break_block; break_node.data.break_node.merge = break_block;
break_node.break_node.skip = skip_block; break_node.data.break_node.skip = skip_block;
auto& merge{syntax_list.emplace_back()}; auto& merge{syntax_list.emplace_back()};
merge.type = IR::AbstractSyntaxNode::Type::Block; merge.type = IR::AbstractSyntaxNode::Type::Block;
merge.block = skip_block; merge.data.block = skip_block;
break; break;
} }
case StatementType::Return: { case StatementType::Return: {
@ -824,7 +824,7 @@ private:
auto& merge{syntax_list.emplace_back()}; auto& merge{syntax_list.emplace_back()};
merge.type = IR::AbstractSyntaxNode::Type::Block; merge.type = IR::AbstractSyntaxNode::Type::Block;
merge.block = demote_block; merge.data.block = demote_block;
break; break;
} }
case StatementType::Unreachable: { case StatementType::Unreachable: {