VapourSynth-llvmexpr
Loading...
Searching...
No Matches
BlockAnalysisPass.cpp
Go to the documentation of this file.
1
19
20#include "BlockAnalysisPass.hpp"
23#include "BuildCFGPass.hpp"
24
25#include <algorithm>
26
27namespace analysis {
28
30BlockAnalysisPass::run(const std::vector<Token>& tokens, AnalysisManager& am) {
31 const auto& cfg_result = am.getResult<BuildCFGPass>();
32
33 Result result;
34 result.cfg_blocks = cfg_result.cfg_blocks;
35
36 for (auto& block : result.cfg_blocks) {
37 int current_stack = 0;
38 int min_stack_in_block = 0;
39
40 for (int j = block.start_token_idx; j < block.end_token_idx; ++j) {
41 const auto& token = tokens[j];
42 const auto behavior = get_token_behavior(token);
43
44 int items_needed = behavior.arity;
45 if (current_stack < items_needed) {
46 min_stack_in_block =
47 std::max(min_stack_in_block, items_needed - current_stack);
48 }
49
50 current_stack += behavior.stack_effect;
51 }
52
53 block.stack_effect = current_stack;
54 block.min_stack_needed = min_stack_in_block;
55 }
56
57 return result;
58}
59
60} // namespace analysis
TokenBehavior get_token_behavior(const Token &token)
Result run(const std::vector< Token > &tokens, AnalysisManager &am) override