Commit f8634e6d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix computeFixedPoint

Was not being careful about distinguishing starting states
vs ending states... I'm not sure why that worked at all.

Also include Marius's optimization from PR #137

This is currently only being used by the DefinednessAnalysis which
could probably have a much faster algorithm.
parent b404b9bc
......@@ -46,20 +46,24 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T>&
typedef typename BBAnalyzer<T>::Map Map;
typedef typename BBAnalyzer<T>::AllMap AllMap;
AllMap states;
AllMap starting_states;
AllMap ending_states;
std::unordered_set<CFGBlock*> in_queue;
std::priority_queue<CFGBlock*, std::vector<CFGBlock*>, CFGBlockMinIndex> q;
states.insert(make_pair(cfg->getStartingBlock(), Map()));
starting_states.insert(make_pair(cfg->getStartingBlock(), Map()));
q.push(cfg->getStartingBlock());
in_queue.insert(cfg->getStartingBlock());
int num_evaluations = 0;
while (q.size()) {
num_evaluations++;
CFGBlock* block = q.top();
q.pop();
in_queue.erase(block);
Map& initial = states[block];
Map& initial = starting_states[block];
if (VERBOSITY("analysis") >= 2)
printf("fpc on block %d - %ld entries\n", block->idx, initial.size());
......@@ -71,12 +75,12 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T>&
CFGBlock* next_block = block->successors[i];
bool changed = false;
bool initial = false;
if (states.count(next_block) == 0) {
if (starting_states.count(next_block) == 0) {
changed = true;
initial = true;
}
Map& next = states[next_block];
Map& next = starting_states[next_block];
for (const auto& p : ending) {
if (next.count(p.first) == 0) {
changed = true;
......@@ -107,12 +111,12 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T>&
}
}
if (changed)
if (changed && in_queue.insert(next_block).second) {
q.push(next_block);
}
}
states.erase(block);
states.insert(make_pair(block, ending));
ending_states[block] = std::move(ending);
}
if (VERBOSITY("analysis")) {
......@@ -121,7 +125,7 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T>&
}
return states;
return ending_states;
}
}
......
......@@ -299,6 +299,8 @@ void DefinednessBBAnalyzer::processBB(Map& starting, CFGBlock* block) const {
DefinednessAnalysis::DefinednessAnalysis(const SourceInfo::ArgNames& arg_names, CFG* cfg, ScopeInfo* scope_info)
: scope_info(scope_info) {
Timer _t("DefinednessAnalysis()");
results = computeFixedPoint(cfg, DefinednessBBAnalyzer(cfg, arg_names), false);
for (const auto& p : results) {
......@@ -312,6 +314,9 @@ DefinednessAnalysis::DefinednessAnalysis(const SourceInfo::ArgNames& arg_names,
}
defined_at_end.insert(make_pair(p.first, required));
}
static StatCounter us_definedness("us_analysis_definedness");
us_definedness.log(_t.end());
}
DefinednessAnalysis::DefinitionLevel DefinednessAnalysis::isDefinedAtEnd(const std::string& name, CFGBlock* block) {
......
......@@ -24,6 +24,7 @@
#include "core/ast.h"
#include "core/cfg.h"
#include "core/options.h"
#include "core/util.h"
#include "runtime/types.h"
//#undef VERBOSITY
......@@ -664,6 +665,8 @@ public:
static PropagatingTypeAnalysis* doAnalysis(CFG* cfg, const SourceInfo::ArgNames& arg_names,
const std::vector<ConcreteCompilerType*>& arg_types,
SpeculationLevel speculation, ScopeInfo* scope_info) {
Timer _t("PropagatingTypeAnalysis::doAnalysis()");
AllTypeMap starting_types;
ExprTypeMap expr_types;
TypeSpeculations type_speculations;
......@@ -765,6 +768,9 @@ public:
}
}
static StatCounter us_types("us_analysis_types");
us_types.log(_t.end());
return new PropagatingTypeAnalysis(starting_types, expr_types, type_speculations, speculation);
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment