MCPcopy Create free account
hub / github.com/InoriRus/Kyty / SimplifyFunction

Method SimplifyFunction

source/3rdparty/vulkan/source/opt/simplification_pass.cpp:47–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47bool SimplificationPass::SimplifyFunction(Function* function) {
48 bool modified = false;
49 // Phase 1: Traverse all instructions in dominance order.
50 // The second phase will only be on the instructions whose inputs have changed
51 // after being processed during phase 1. Since OpPhi instructions are the
52 // only instructions whose inputs do not necessarily dominate the use, we keep
53 // track of the OpPhi instructions already seen, and add them to the work list
54 // for phase 2 when needed.
55 std::vector<Instruction*> work_list;
56 std::unordered_set<Instruction*> process_phis;
57 std::unordered_set<Instruction*> inst_to_kill;
58 std::unordered_set<Instruction*> in_work_list;
59 std::unordered_set<Instruction*> inst_seen;
60 const InstructionFolder& folder = context()->get_instruction_folder();
61
62 cfg()->ForEachBlockInReversePostOrder(
63 function->entry().get(),
64 [&modified, &process_phis, &work_list, &in_work_list, &inst_to_kill,
65 &folder, &inst_seen, this](BasicBlock* bb) {
66 for (Instruction* inst = &*bb->begin(); inst; inst = inst->NextNode()) {
67 inst_seen.insert(inst);
68 if (inst->opcode() == SpvOpPhi) {
69 process_phis.insert(inst);
70 }
71
72 bool is_foldable_copy =
73 inst->opcode() == SpvOpCopyObject &&
74 context()->get_decoration_mgr()->HaveSubsetOfDecorations(
75 inst->result_id(), inst->GetSingleWordInOperand(0));
76
77 if (is_foldable_copy || folder.FoldInstruction(inst)) {
78 modified = true;
79 context()->AnalyzeUses(inst);
80 get_def_use_mgr()->ForEachUser(inst, [&work_list, &process_phis,
81 &in_work_list](
82 Instruction* use) {
83 if (process_phis.count(use) && in_work_list.insert(use).second) {
84 work_list.push_back(use);
85 }
86 });
87
88 AddNewOperands(inst, &inst_seen, &work_list);
89
90 if (inst->opcode() == SpvOpCopyObject) {
91 context()->ReplaceAllUsesWithPredicate(
92 inst->result_id(), inst->GetSingleWordInOperand(0),
93 [](Instruction* user) {
94 const auto opcode = user->opcode();
95 if (!spvOpcodeIsDebug(opcode) &&
96 !spvOpcodeIsDecoration(opcode)) {
97 return true;
98 }
99 return false;
100 });
101 inst_to_kill.insert(inst);
102 in_work_list.insert(inst);
103 } else if (inst->opcode() == SpvOpNop) {
104 inst_to_kill.insert(inst);

Callers

nothing calls this directly

Calls 15

spvOpcodeIsDebugFunction · 0.85
spvOpcodeIsDecorationFunction · 0.85
FoldInstructionMethod · 0.80
AnalyzeUsesMethod · 0.80
ForEachUserMethod · 0.80
IsDecorationMethod · 0.80
KillInstMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected