VapourSynth-llvmexpr
Loading...
Searching...
No Matches
StaticAllocReachabilityPass.cpp
Go to the documentation of this file.
1
19
24#include "BlockAnalysisPass.hpp"
25
26namespace analysis {
27
29 : public ForwardDataflowAnalysis<std::set<std::string>> {
30 public:
31 std::set<std::string>
32 computeGenSet(size_t block_idx, const std::vector<Token>& tokens,
33 const std::vector<CFGBlock>& cfg_blocks) override {
34 std::set<std::string> gen_set;
35 const auto& block = cfg_blocks[block_idx];
36
37 for (int j = block.start_token_idx; j < block.end_token_idx; ++j) {
38 if (tokens[j].type == TokenType::ArrayAllocStatic) {
39 const auto& array_name =
40 std::get<TokenPayloadArrayOp>(tokens[j].payload).name;
41 gen_set.insert(var_naming::getArrayName(array_name));
42 }
43 }
44 return gen_set;
45 }
46
47 std::set<std::string>
48 meetOperation(const std::vector<std::set<std::string>>& inputs) override {
49 // Union: an array is statically allocated if allocated on ANY path
50 std::set<std::string> result;
51 for (const auto& input : inputs) {
52 result.insert(input.begin(), input.end());
53 }
54 return result;
55 }
56
57 std::set<std::string>
58 transferFunction(const std::set<std::string>& in_value,
59 const std::set<std::string>& gen_set) override {
60 // OUT = GEN U IN
61 std::set<std::string> out_value = gen_set;
62 out_value.insert(in_value.begin(), in_value.end());
63 return out_value;
64 }
65
66 std::set<std::string> getBoundaryValue() override {
67 // Entry block starts with no statically allocated arrays
68 return std::set<std::string>{};
69 }
70};
71
73StaticAllocReachabilityPass::run(const std::vector<Token>& tokens,
74 AnalysisManager& am) {
75 const auto& block_result = am.getResult<BlockAnalysisPass>();
76 const auto& cfg_blocks = block_result.cfg_blocks;
77
78 Result result;
79
81 auto [in_sets, out_sets] = analysis.analyze(tokens, cfg_blocks);
82
83 result.static_alloc_in = std::move(in_sets);
84 result.static_alloc_out = std::move(out_sets);
85
86 return result;
87}
88
89} // namespace analysis
@ ArrayAllocStatic
Definition Tokenizer.hpp:51
std::set< std::string > computeGenSet(size_t block_idx, const std::vector< Token > &tokens, const std::vector< CFGBlock > &cfg_blocks) override
std::set< std::string > getBoundaryValue() override
std::set< std::string > meetOperation(const std::vector< std::set< std::string > > &inputs) override
std::set< std::string > transferFunction(const std::set< std::string > &in_value, const std::set< std::string > &gen_set) override
Result run(const std::vector< Token > &tokens, AnalysisManager &am) override
std::string getArrayName(std::string_view base_name)
Definition VarNaming.hpp:30
std::vector< std::set< std::string > > static_alloc_in
std::vector< std::set< std::string > > static_alloc_out