From 6091fa474d9b8e122eb3647fcb9c339054277728 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sat, 14 Feb 2026 09:59:20 +0300 Subject: [PATCH] improved CFG settings --- src/CFGraph/CFGraph.h | 55 ++++++++++++++----- src/DirectiveProcessing/shadow.cpp | 5 +- src/Predictor/PredictScheme.cpp | 4 +- src/Sapfor.cpp | 2 +- .../DeadCodeRemoving/dead_code.cpp | 4 +- .../LoopSplitting/loops_splitter.cpp | 6 +- .../PrivateArrayRemoving/private_removing.cpp | 5 +- src/Utils/version.h | 2 +- 8 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/CFGraph/CFGraph.h b/src/CFGraph/CFGraph.h index 4db260b..20608d2 100644 --- a/src/CFGraph/CFGraph.h +++ b/src/CFGraph/CFGraph.h @@ -105,23 +105,48 @@ namespace SAPFOR struct CFG_Settings { + enum setting { CFG_atLeastOneIterInLoop = 1, + CFG_withRD = 2, + CFG_withRegisters = 3, + CFG_withSPF = 4, + CFG_withDVM = 5, + CFG_withCallsInBlocks = 6, + CFG_withCallFrom = 7, + CFG_withDominators = 8 }; + bool atLeastOneIterInLoop = false; - bool withRD = true; - bool withRegisters = false; - bool withSPF = false; - bool withDVM = false; - bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock - bool withCallFrom = true; - bool withDominators = true; + bool withRD = false; + bool withRegisters = false; + bool withSPF = false; + bool withDVM = false; + bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock + bool withCallFrom = false; + bool withDominators = false; - explicit CFG_Settings(int) { } - - explicit CFG_Settings(bool atLeastOneIterInLoop = false, bool withRD = true, bool withRegisters = false, - bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false, - bool withCallFrom = true, bool withDominators = true) : - atLeastOneIterInLoop(atLeastOneIterInLoop), withRD(withRD), withRegisters(withRegisters), withDVM(withDVM), withSPF(withSPF), - withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom), withDominators(withDominators) - { } + explicit CFG_Settings(const std::set &settings = { CFG_withRD, CFG_withCallFrom, CFG_withDominators }) + { + for (auto& set : settings) + { + if (set == CFG_atLeastOneIterInLoop) + atLeastOneIterInLoop = true; + else if (set == CFG_withRD) + withRD = true; + else if (set == CFG_withRegisters) + withRegisters = true; + else if (set == CFG_withSPF) + withSPF = true; + else if (set == CFG_withDVM) + withDVM = true; + else if (set == CFG_withCallsInBlocks) + withCallsInBlocks = true; + else if (set == CFG_withCallFrom) + withCallFrom = true; + else if (set == CFG_withDominators) + withDominators = true; + else + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + } }; } diff --git a/src/DirectiveProcessing/shadow.cpp b/src/DirectiveProcessing/shadow.cpp index 94c64b5..07cd69d 100644 --- a/src/DirectiveProcessing/shadow.cpp +++ b/src/DirectiveProcessing/shadow.cpp @@ -26,6 +26,7 @@ using std::string; using std::vector; using std::pair; using std::make_pair; +using SAPFOR::CFG_Settings; extern int debSh; @@ -1672,9 +1673,11 @@ void GroupShadow(const map>& allFuncs, SgStatement* func = currF->funcPointer->GetOriginal(); - auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, true, false, true, false), commonBlocks, allFuncs); + const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withSPF, CFG_Settings::CFG_withCallsInBlocks }); + auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncs); if (cfg.size() != 1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + auto& blocks = cfg.begin()->second; //create reaching blocks diff --git a/src/Predictor/PredictScheme.cpp b/src/Predictor/PredictScheme.cpp index 764ce1a..e4d304a 100644 --- a/src/Predictor/PredictScheme.cpp +++ b/src/Predictor/PredictScheme.cpp @@ -33,6 +33,7 @@ using std::set; using std::ofstream; using std::pair; using std::tuple; +using SAPFOR::CFG_Settings; using json = nlohmann::json; @@ -507,7 +508,8 @@ static void parallelDir(const map& byPos, SgExpression* spec, if (currF == NULL) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, true, false, false, true), commonBlocks, allFuncInfo); + const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withSPF, CFG_Settings::CFG_withDominators }); + auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncInfo); //TODO IP analysis unsigned countOfAccess = 0; diff --git a/src/Sapfor.cpp b/src/Sapfor.cpp index 2473782..53e2b8c 100644 --- a/src/Sapfor.cpp +++ b/src/Sapfor.cpp @@ -1893,7 +1893,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne findParameters(parametersOfProject, fullIR, declaredArrays); else if (curr_regime == BUILD_IR) { - auto CFG_forFile = buildCFG(commonBlocks, allFuncInfo_IR, SAPFOR::CFG_Settings(0)); + auto CFG_forFile = buildCFG(commonBlocks, allFuncInfo_IR, SAPFOR::CFG_Settings()); for (auto& byFunc : CFG_forFile) fullIR[byFunc.first].insert(fullIR[byFunc.first].end(), byFunc.second.begin(), byFunc.second.end()); diff --git a/src/Transformations/DeadCodeRemoving/dead_code.cpp b/src/Transformations/DeadCodeRemoving/dead_code.cpp index aa89dbc..b27d2b4 100644 --- a/src/Transformations/DeadCodeRemoving/dead_code.cpp +++ b/src/Transformations/DeadCodeRemoving/dead_code.cpp @@ -12,6 +12,7 @@ using std::map; using std::string; using std::vector; using std::set; +using SAPFOR::CFG_Settings; using std::remove_if; @@ -424,7 +425,8 @@ int removeDeadCode(SgStatement* func, if (intervalDelEnd->lineNumber() < prog->lineNumber() || intervalDelEnd->lineNumber() > prog->lastNodeOfStmt()->lineNumber()) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, false, false, false, false), commonBlocks, allFuncs); + const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop }); + auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncs); if(cfg.size() != 1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); diff --git a/src/Transformations/LoopSplitting/loops_splitter.cpp b/src/Transformations/LoopSplitting/loops_splitter.cpp index 185296d..b26167d 100644 --- a/src/Transformations/LoopSplitting/loops_splitter.cpp +++ b/src/Transformations/LoopSplitting/loops_splitter.cpp @@ -19,6 +19,7 @@ using std::pair; using std::make_pair; using std::wstring; using std::stack; +using SAPFOR::CFG_Settings; #define PRINT_SPLITTED_FRAGMENTS 0 @@ -315,7 +316,7 @@ static map, set>> printInternalError(convertFileName(__FILE__).c_str(), __LINE__); map> outForCurr; - buildGenKillForCFG(itCFG->second, funcByName, outForFunc, gen, kill, &genForIR, &killForIR, notInitedGlobals, SAPFOR::CFG_Settings(0)); + buildGenKillForCFG(itCFG->second, funcByName, outForFunc, gen, kill, &genForIR, &killForIR, notInitedGlobals, SAPFOR::CFG_Settings()); if (outForFunc.count(byFunc)) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); @@ -1051,7 +1052,8 @@ int splitLoops(SgFile *file, vector &loopGraphs, vector &m checkNull(listExp, convertFileName(__FILE__).c_str(), __LINE__); int deep = listExp->length(); - currIR = buildCFGforCurrentFunc(loop->loop, SAPFOR::CFG_Settings(true, true), commonBlocks, allFuncInfo); + const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withRD, CFG_Settings::CFG_withCallFrom, CFG_Settings::CFG_withDominators }); + currIR = buildCFGforCurrentFunc(loop->loop, settings, commonBlocks, allFuncInfo); totalErr = splitLoop(loop, messages, deep, depInfoForLoopGraph); if (totalErr > 0) diff --git a/src/Transformations/PrivateArrayRemoving/private_removing.cpp b/src/Transformations/PrivateArrayRemoving/private_removing.cpp index 3869c4f..8eb0015 100644 --- a/src/Transformations/PrivateArrayRemoving/private_removing.cpp +++ b/src/Transformations/PrivateArrayRemoving/private_removing.cpp @@ -13,6 +13,7 @@ using std::set; using std::string; using std::vector; using std::wstring; +using SAPFOR::CFG_Settings; using CFG_Type = map>; using UsersDirectives = map, set>; @@ -2207,8 +2208,8 @@ static void removePrivateAnalyze(Context *ctx) makeDeclaration(ctx->loopStmt, vector {receiverVar}, nullptr) )); - CFG_Type CFG_ForFunc = buildCFGforCurrentFunc(ctx->loopStmt, - SAPFOR::CFG_Settings(true, true), + const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withRD, CFG_Settings::CFG_withCallFrom, CFG_Settings::CFG_withDominators }); + CFG_Type CFG_ForFunc = buildCFGforCurrentFunc(ctx->loopStmt, settings, ctx->commonBlocks, ctx->allFuncInfo); if (CFG_ForFunc.empty()) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); diff --git a/src/Utils/version.h b/src/Utils/version.h index e5709c8..6c1461d 100644 --- a/src/Utils/version.h +++ b/src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2461" +#define VERSION_SPF "2462"