VapourSynth-llvmexpr
Loading...
Searching...
No Matches
StructurizeCFGPass.hpp
Go to the documentation of this file.
1
19
20#ifndef LLVMEXPR_ANALYSIS_STRUCTURIZECFG_PASS_HPP
21#define LLVMEXPR_ANALYSIS_STRUCTURIZECFG_PASS_HPP
22
24#include "../framework/Pass.hpp"
25
26#include <map>
27#include <set>
28#include <vector>
29
30namespace analysis {
31
33 // Whether we believe the CFG is structurizable.
34 bool success = true;
35
36 // If the CFG appears reducible (single-entry strongly-connected regions).
37 bool reducible = true;
38
39 // Post-dominator tree (immediate post-dominator) for each CFG block index.
40 // -1 = no post-dominator
41 std::vector<int> ipdom;
42
43 // Natural-loop information indexed by loop header block index.
44 std::map<int, std::set<int>>
45 loop_body; // header -> blocks in loop (incl hdr)
46 std::map<int, int> loop_follow; // header -> follow block (may be -1)
47
48 // For each block, the innermost loop header containing it, or -1.
49 std::vector<int> innermost_loop_header;
50
51 // Optional CFG rewrite for codegen (node splitting / tail duplication).
52 // If empty, codegen should use the original CFG from BlockAnalysisPass.
53 std::vector<CFGBlock> structured_cfg_blocks;
54
55 // Map: structured block index -> original block index.
56 // Only valid when structured_cfg_blocks is non-empty.
57 std::vector<int> structured_block_origin;
58
59 // Stack depth at entry for structured_cfg_blocks.
60 // Only valid when structured_cfg_blocks is non-empty.
61 std::vector<int> structured_stack_depth_in;
62
63 [[nodiscard]] bool isLoopHeader(int block_idx) const {
64 return loop_body.contains(block_idx);
65 }
66
67 [[nodiscard]] bool inLoop(int header, int block_idx) const {
68 auto it = loop_body.find(header);
69 if (it == loop_body.end()) {
70 return false;
71 }
72 return it->second.contains(block_idx);
73 }
74};
75
85 : public AnalysisPass<StructurizeCFGPass, StructurizeCFGResult> {
86 public:
88
89 [[nodiscard]] const char* getName() const override {
90 return "StructurizeCFG (Control Flow Structuring) Pass";
91 }
92
93 Result run(const std::vector<Token>& tokens, AnalysisManager& am) override;
94};
95
96} // namespace analysis
97
98#endif // LLVMEXPR_ANALYSIS_STRUCTURIZECFG_PASS_HPP
Result run(const std::vector< Token > &tokens, AnalysisManager &am) override
const char * getName() const override
std::vector< int > structured_stack_depth_in
bool isLoopHeader(int block_idx) const
std::map< int, std::set< int > > loop_body
std::vector< CFGBlock > structured_cfg_blocks
bool inLoop(int header, int block_idx) const