yuzu/src/shader_recompiler/frontend/maxwell/program.cpp

54 lines
1.9 KiB
C++
Raw Normal View History

2021-01-09 06:30:07 +00:00
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <algorithm>
#include <memory>
#include <vector>
2021-01-09 06:30:07 +00:00
2021-02-06 02:11:23 +00:00
#include "shader_recompiler/frontend/ir/basic_block.h"
2021-02-14 23:15:42 +00:00
#include "shader_recompiler/frontend/ir/post_order.h"
2021-01-09 06:30:07 +00:00
#include "shader_recompiler/frontend/maxwell/program.h"
#include "shader_recompiler/frontend/maxwell/structured_control_flow.h"
2021-01-09 06:30:07 +00:00
#include "shader_recompiler/frontend/maxwell/translate/translate.h"
2021-02-03 00:07:00 +00:00
#include "shader_recompiler/ir_opt/passes.h"
2021-01-09 06:30:07 +00:00
namespace Shader::Maxwell {
static void RemoveUnreachableBlocks(IR::Program& program) {
// Some blocks might be unreachable if a function call exists unconditionally
// If this happens the number of blocks and post order blocks will mismatch
if (program.blocks.size() == program.post_order_blocks.size()) {
return;
}
const IR::BlockList& post_order{program.post_order_blocks};
std::erase_if(program.blocks, [&](IR::Block* block) {
return std::ranges::find(post_order, block) == post_order.end();
});
2021-02-03 00:07:00 +00:00
}
2021-01-09 06:30:07 +00:00
2021-02-06 02:11:23 +00:00
IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
Environment& env, Flow::CFG& cfg) {
2021-02-06 02:11:23 +00:00
IR::Program program;
program.blocks = VisitAST(inst_pool, block_pool, env, cfg);
program.post_order_blocks = PostOrder(program.blocks);
RemoveUnreachableBlocks(program);
// Replace instructions before the SSA rewrite
2021-02-19 21:10:18 +00:00
Optimization::LowerFp16ToFp32(program);
Optimization::SsaRewritePass(program);
2021-02-16 07:10:22 +00:00
Optimization::GlobalMemoryToStorageBufferPass(program);
Optimization::TexturePass(env, program);
Optimization::ConstantPropagationPass(program);
Optimization::DeadCodeEliminationPass(program);
Optimization::IdentityRemovalPass(program);
Optimization::VerificationPass(program);
2021-02-16 07:10:22 +00:00
Optimization::CollectShaderInfoPass(program);
2021-02-06 02:11:23 +00:00
return program;
2021-01-09 06:30:07 +00:00
}
} // namespace Shader::Maxwell