DefinednessAnalysis::DefinednessAnalysis(AST_arguments *args, CFG* cfg, ScopeInfo *scope_info) : scope_info(scope_info) { results = computeFixedPoint(cfg, DefinednessBBAnalyzer(cfg, args), false); for (const auto &p : results) { RequiredSet required; for (const auto &p2 : p.second) { if (scope_info->refersToGlobal(p2.first)) continue; //printf("%d %s %d\n", p.first->idx, p2.first.c_str(), p2.second); required.insert(p2.first); } defined.insert(make_pair(p.first, required)); } }
DefinednessAnalysis::DefinednessAnalysis(AST_arguments *args, CFG* cfg, ScopeInfo *scope_info) : scope_info(scope_info) { results = computeFixedPoint(cfg, DefinednessBBAnalyzer(args), false); for (std::unordered_map<CFGBlock*, std::unordered_map<std::string, DefinitionLevel> >::iterator it = results.begin(), end = results.end(); it != end; ++it) { RequiredSet required; for (std::unordered_map<std::string, DefinitionLevel>::iterator it2 = it->second.begin(), end2 = it->second.end(); it2 != end2; ++it2) { if (scope_info->refersToGlobal(it2->first)) continue; //printf("%d %s %d\n", it->first->idx, it2->first.c_str(), it2->second); required.insert(it2->first); } defined.insert(make_pair(it->first, required)); } }
DefinednessAnalysis::DefinednessAnalysis(const SourceInfo::ArgNames& arg_names, CFG* cfg, ScopeInfo* scope_info) : scope_info(scope_info) { Timer _t("DefinednessAnalysis()", 10); results = computeFixedPoint(cfg, DefinednessBBAnalyzer(cfg, arg_names), false); for (const auto& p : results) { RequiredSet required; for (const auto& p2 : p.second) { if (scope_info->refersToGlobal(p2.first)) continue; // printf("%d %s %d\n", p.first->idx, p2.first.c_str(), p2.second); required.insert(p2.first); } defined_at_end.insert(make_pair(p.first, required)); } static StatCounter us_definedness("us_compiling_analysis_definedness"); us_definedness.log(_t.end()); }
int main(int argc, char* argv[]) { int nStatus = 0; double nP0; double nRelativeError; double nP; int nMaxIter; printf("\n *** Fixed-Point Iteration *** "); printf("\n\n Using g(x) = -4 + 4x - x^2/2 "); /* Ask for input */ printf("\n\n Enter the initial value P0 : "); scanf("%lf",&nP0); fflush(stdin); printf(" Enter the maximum number of iterations: "); scanf("%d",&nMaxIter); fflush(stdin); /* Copmpute the the fixed-point iteration */ nStatus = computeFixedPoint(nP0,gFunc,nMaxIter,200,1,&nP,&nRelativeError); /* Display output */ if(nStatus == 0) { printf("\n The computed fixed point is : %2.8lf",nP); printf("\n The the relative error is : %2.8lf",nRelativeError); } else { printf("\n The sequence appears tobe diverging."); } printf("\n\nPress any key to continue...."); getch(); return 0; }
void DefinednessAnalysis::run(const CodeConstants& code_constants, VRegMap<DefinednessAnalysis::DefinitionLevel> initial_map, CFGBlock* initial_block) { Timer _t("DefinednessAnalysis()", 10); // Don't run this twice: assert(!defined_at_end.size()); auto cfg = initial_block->cfg; int nvregs = cfg->getVRegInfo().getTotalNumOfVRegs(); assert(initial_map.numVregs() == nvregs); auto&& vreg_info = cfg->getVRegInfo(); computeFixedPoint(std::move(initial_map), initial_block, DefinednessBBAnalyzer(code_constants), false, defined_at_beginning, defined_at_end); for (const auto& p : defined_at_end) { assert(p.second.numVregs() == nvregs); assert(!defined_at_end_sets.count(p.first)); VRegSet& required = defined_at_end_sets.insert(std::make_pair(p.first, VRegSet(nvregs))).first->second; // required.resize(nvregs, /* value= */ false); for (int vreg = 0; vreg < nvregs; vreg++) { auto status = p.second[vreg]; // assert(p.second.count(name)); // auto status = p.second.find(name)->second; assert(status != DefinednessAnalysis::Unknown); if (status != DefinednessAnalysis::Undefined) required.set(vreg); } } static StatCounter us_definedness("us_compiling_analysis_definedness"); us_definedness.log(_t.end()); }