From 35559d0e76792b554b92f27dbe92481934985615 Mon Sep 17 00:00:00 2001 From: Peter Arzt Date: Wed, 17 Jan 2024 21:40:25 +0100 Subject: [PATCH] PGIS: Use getOrCreateMD instead of plain get to work around current issue. --- pgis/lib/src/CgHelper.cpp | 8 ++-- pgis/lib/src/ExtrapEstimatorPhase.cpp | 4 +- pgis/lib/src/IPCGEstimatorPhase.cpp | 30 ++++++------- pgis/lib/src/LegacyMCGReader.cpp | 6 +-- .../src/loadImbalance/LIEstimatorPhase.cpp | 42 +++++++++---------- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/pgis/lib/src/CgHelper.cpp b/pgis/lib/src/CgHelper.cpp index b760779..20afcdf 100644 --- a/pgis/lib/src/CgHelper.cpp +++ b/pgis/lib/src/CgHelper.cpp @@ -76,13 +76,13 @@ bool isOnCycle(metacg::CgNode *node, const metacg::Callgraph *const graph) { Statements visitNodeForInclusiveStatements(metacg::CgNode *node, CgNodeRawPtrUSet *visitedNodes, const metacg::Callgraph *const graph) { if (visitedNodes->find(node) != visitedNodes->end()) { - return node->get()->getNumberOfInclusiveStatements(); + return node->getOrCreateMD()->getNumberOfInclusiveStatements(); } visitedNodes->insert(node); CgNodeRawPtrUSet visistedChilds; - Statements inclusiveStatements = node->get()->getNumberOfStatements(); + Statements inclusiveStatements = node->getOrCreateMD()->getNumberOfStatements(); for (auto childNode : graph->getCallees(node)) { // prevent double processing if (visistedChilds.find(childNode) != visistedChilds.end()) @@ -90,7 +90,7 @@ Statements visitNodeForInclusiveStatements(metacg::CgNode *node, CgNodeRawPtrUSe visistedChilds.insert(childNode); // approximate statements of a abstract function with maximum of its children (potential call targets) - if (node->get()->isVirtual() && node->get()->getNumberOfStatements() == 0) { + if (node->getOrCreateMD()->isVirtual() && node->getOrCreateMD()->getNumberOfStatements() == 0) { inclusiveStatements = std::max(inclusiveStatements, visitNodeForInclusiveStatements(childNode, visitedNodes, graph)); } else { @@ -98,7 +98,7 @@ Statements visitNodeForInclusiveStatements(metacg::CgNode *node, CgNodeRawPtrUSe } } - node->get()->setNumberOfInclusiveStatements(inclusiveStatements); + node->getOrCreateMD()->setNumberOfInclusiveStatements(inclusiveStatements); metacg::MCGLogger::instance().getConsole()->trace("Visiting node " + node->getFunctionName() + ". Result = " + std::to_string(inclusiveStatements)); diff --git a/pgis/lib/src/ExtrapEstimatorPhase.cpp b/pgis/lib/src/ExtrapEstimatorPhase.cpp index 364e788..297f945 100644 --- a/pgis/lib/src/ExtrapEstimatorPhase.cpp +++ b/pgis/lib/src/ExtrapEstimatorPhase.cpp @@ -38,7 +38,7 @@ void ExtrapLocalEstimatorPhaseBase::modifyGraph(metacg::CgNode *mainNode) { if (shouldInstr) { auto useCSInstr = pgis::config::GlobalConfig::get().getAs(pgis::options::useCallSiteInstrumentation.cliName); - if (useCSInstr && !n->get()->getHasBody()) { + if (useCSInstr && !n->getOrCreateMD()->getHasBody()) { // If no definition, use call-site instrumentation pgis::instrumentPathNode(n); // n->setState(CgNodeState::INSTRUMENT_PATH); @@ -142,7 +142,7 @@ void ExtrapLocalEstimatorPhaseSingleValueExpander::modifyGraph(metacg::CgNode *m console->trace("Running ExtrapLocalEstimatorPhaseExpander::modifyGraph on {}", n->getFunctionName()); auto [shouldInstr, funcRtVal] = shouldInstrument(n); if (shouldInstr) { - if (!n->get()->getHasBody() && n->get()->getRuntimeInSeconds() == .0) { + if (!n->getOrCreateMD()->getHasBody() && n->get()->getRuntimeInSeconds() == .0) { // If no definition, use call-site instrumentation // n->setState(CgNodeState::INSTRUMENT_PATH); pgis::instrumentPathNode(n); diff --git a/pgis/lib/src/IPCGEstimatorPhase.cpp b/pgis/lib/src/IPCGEstimatorPhase.cpp index 3a97c83..da939a4 100644 --- a/pgis/lib/src/IPCGEstimatorPhase.cpp +++ b/pgis/lib/src/IPCGEstimatorPhase.cpp @@ -91,7 +91,7 @@ void StatementCountEstimatorPhase::estimateStatementCount(metacg::CgNode *startN while (!workQueue.empty()) { auto node = workQueue.front(); - const auto nodePOD = node->get(); + const auto nodePOD = node->getOrCreateMD(); workQueue.pop(); if (const auto [it, inserted] = visitedNodes.insert(node); inserted) { @@ -107,7 +107,7 @@ void StatementCountEstimatorPhase::estimateStatementCount(metacg::CgNode *startN inclStmtCounts[startNode] = inclStmtCount; } else { // EXCLUSIVE - const auto snPOD = startNode->get(); + const auto snPOD = startNode->getOrCreateMD(); inclStmtCount = snPOD->getNumberOfStatements(); } @@ -183,7 +183,7 @@ void RuntimeEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { spdlog::get("console")->debug("The runtime is threshold is computed as: {}", runTimeThreshold); // The main method is always in the dominant runtime path - mainMethod->get()->setDominantRuntime(); + mainMethod->getOrCreateMD()->setDominantRuntime(); std::queue workQueue; workQueue.push(mainMethod); @@ -216,7 +216,7 @@ void RuntimeEstimatorPhase::estimateRuntime(metacg::CgNode *startNode) { // Skip not leave nodes const auto &childs = graph->getCallees(startNode); if (calls > 0 && std::none_of(childs.begin(), childs.end(), [](const auto cnode) { - return cnode->template get()->comesFromCube(); + return cnode->template getOrCreateMD()->comesFromCube(); })) { exclusiveCalls.emplace(calls, startNode); } @@ -257,7 +257,7 @@ void RuntimeEstimatorPhase::doInstrumentation(metacg::CgNode *startNode, metacg: maxStmts = childStmts[childNode]; } - if (childNode->get()->comesFromCube()) { + if (childNode->getOrCreateMD()->comesFromCube()) { if (childNode->get()->getInclusiveRuntimeInSeconds() < runTimeThreshold) { continue; } @@ -322,10 +322,10 @@ void RuntimeEstimatorPhase::doInstrumentation(metacg::CgNode *startNode, metacg: spdlog::get("console")->debug("This is the dominant runtime path"); // maxRtChild->setState(CgNodeState::INSTRUMENT_WITNESS); pgis::instrumentNode(maxRtChild); - maxRtChild->get()->setDominantRuntime(); + maxRtChild->getOrCreateMD()->setDominantRuntime(); } else { spdlog::get("console")->debug("This is the non-dominant runtime path"); - if (startNode->get()->isDominantRuntime()) { + if (startNode->getOrCreateMD()->isDominantRuntime()) { spdlog::get("console")->debug("\tPrincipal: {}", startNode->getFunctionName()); for (auto child : graph->getCallees(startNode)) { spdlog::get("console")->trace("\tEvaluating {} with {} [stmt threshold: {}]", child->getFunctionName(), @@ -353,7 +353,7 @@ InstumentationInfo RuntimeEstimatorPhase::getEstimatedInfoForInstrumentedNode(Cg unsigned long exclusiveStmtCount = 0; while (!workQueue.empty()) { auto wnode = workQueue.front(); - const auto nodePOD = wnode->get(); + const auto nodePOD = wnode->getOrCreateMD(); workQueue.pop(); if (visitedNodes.find(wnode) == visitedNodes.end()) { visitedNodes.insert(wnode); @@ -404,7 +404,7 @@ void RuntimeEstimatorPhase::modifyGraphOverhead(metacg::CgNode *mainMethod) { } for (const auto &elem : graph->getNodes()) { const auto &node = elem.second.get(); - if (node->get()->comesFromCube()) { + if (node->getOrCreateMD()->comesFromCube()) { if (node->getHasBody() || isMPIFunction(node) || (!onlyEligibleNodes && !useCSInstrumentation)) { pgis::instrumentNode(node); } else if (useCSInstrumentation) { @@ -474,7 +474,7 @@ void RuntimeEstimatorPhase::modifyGraphOverhead(metacg::CgNode *mainMethod) { // Find direct childs nodes to potentially instrument for (const auto &elem : graph->getNodes()) { const auto &node = elem.second.get(); - if (node->get()->comesFromCube()) { + if (node->getOrCreateMD()->comesFromCube()) { // TODO: Do we need this check if (!node->get()->isKicked) { for (const auto &C : graph->getCallees(node)) { @@ -906,11 +906,11 @@ void StatisticsEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { } numReachableFunctions++; - auto numStmts = node->get()->getNumberOfStatements(); + auto numStmts = node->getOrCreateMD()->getNumberOfStatements(); if (pgis::isInstrumented(node)) { stmtsCoveredWithInstr += numStmts; } - if (node->get()->comesFromCube()) { + if (node->getOrCreateMD()->comesFromCube()) { stmtsActuallyCovered += numStmts; } auto &histElem = stmtHist[numStmts]; @@ -1299,7 +1299,7 @@ void AttachInstrumentationResultsEstimatorPhase::modifyGraph(CgNode *mainMethod) // We have pretty exact information about a function if we instrument it and all of its childs // This information should not change between iterations, so we do not need to overwrite/recalculate it const auto instResult = node->checkAndGet(); - if (instResult.first && (instResult.second->shouldBeInstrumented && !node->get()->comesFromCube())) { + if (instResult.first && (instResult.second->shouldBeInstrumented && !node->getOrCreateMD()->comesFromCube())) { // A node should have been instrumented, but was not in the cube file. This means it has zero calls and zero // runtime instResult.second->isExclusiveRuntime = true; @@ -1315,7 +1315,7 @@ void AttachInstrumentationResultsEstimatorPhase::modifyGraph(CgNode *mainMethod) continue; } - if (node->get()->comesFromCube()) { + if (node->getOrCreateMD()->comesFromCube()) { // We already calculated an exclusive result before. Do not change it, as there could be small measurement // differences that could cause flickering between different instrumentation states bool hasPrevExclusive = instResult.first && instResult.second->isExclusiveRuntime; @@ -1326,7 +1326,7 @@ void AttachInstrumentationResultsEstimatorPhase::modifyGraph(CgNode *mainMethod) const auto callsFromParents = node->get()->getCallsFromParents(); const auto &childs = graph->getCallees(node); const bool isExclusive = std::none_of(childs.begin(), childs.end(), [](const auto &child) { - return !child->template get()->comesFromCube(); + return !child->template getOrCreateMD()->comesFromCube(); }); // Calculate the summing inclusive runtime std::queue workQueue; diff --git a/pgis/lib/src/LegacyMCGReader.cpp b/pgis/lib/src/LegacyMCGReader.cpp index c6eca86..059be8b 100644 --- a/pgis/lib/src/LegacyMCGReader.cpp +++ b/pgis/lib/src/LegacyMCGReader.cpp @@ -66,14 +66,14 @@ void VersionOneMetaCGReader::read(metacg::graph::MCGManager &cgManager) { if (opt_f.has_value()) { metacg::CgNode *node = opt_f.value(); node->getOrCreateMD(); - node->get()->setVirtual(pfi.second.isVirtual); + node->getOrCreateMD()->setVirtual(pfi.second.isVirtual); if (pfi.second.visited) { - node->get()->flag(LoadImbalance::FlagType::Visited); + node->getOrCreateMD()->flag(LoadImbalance::FlagType::Visited); } if (pfi.second.irrelevant) { - node->get()->flag(LoadImbalance::FlagType::Irrelevant); + node->getOrCreateMD()->flag(LoadImbalance::FlagType::Irrelevant); } } } diff --git a/pgis/lib/src/loadImbalance/LIEstimatorPhase.cpp b/pgis/lib/src/loadImbalance/LIEstimatorPhase.cpp index 57512a1..9c6a034 100644 --- a/pgis/lib/src/loadImbalance/LIEstimatorPhase.cpp +++ b/pgis/lib/src/loadImbalance/LIEstimatorPhase.cpp @@ -36,7 +36,7 @@ LIEstimatorPhase::LIEstimatorPhase(std::unique_ptr &&config, metacg::C LIEstimatorPhase::~LIEstimatorPhase() { delete this->metric; } void LIEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { - double totalRuntime = mainMethod->get()->getInclusiveRuntimeInSeconds(); + double totalRuntime = mainMethod->getOrCreateMD()->getInclusiveRuntimeInSeconds(); // make sure no node is marked for instrumentation yet for (const auto &elem : graph->getNodes()) { @@ -59,14 +59,14 @@ void LIEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { spdlog::get("console")->debug("LIEstimatorPhase: Processing node " + n->getFunctionName()); // flag node as visited - n->get()->flag(FlagType::Visited); + n->getOrCreateMD()->flag(FlagType::Visited); - double runtime = n->get()->getInclusiveRuntimeInSeconds(); + double runtime = n->getOrCreateMD()->getInclusiveRuntimeInSeconds(); std::ostringstream debugString; debugString << "Visiting node " << n->getFunctionName() << " (" - << n->get()->getNumberOfInclusiveStatements() << "): "; + << n->getOrCreateMD()->getNumberOfInclusiveStatements() << "): "; // check whether node is sufficiently important if (runtime / totalRuntime >= c->relevanceThreshold) { @@ -79,12 +79,12 @@ void LIEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { statementThreshold = c->childConstantThreshold; } else if (c->childRelevanceStrategy == ChildRelevanceStrategy::RelativeToParent) { statementThreshold = - std::max((pira::Statements)(n->get()->getNumberOfInclusiveStatements() * + std::max((pira::Statements)(n->getOrCreateMD()->getNumberOfInclusiveStatements() * c->childFraction), c->childConstantThreshold); } else if (c->childRelevanceStrategy == ChildRelevanceStrategy::RelativeToMain) { statementThreshold = std::max( - (pira::Statements)(mainMethod->get()->getNumberOfInclusiveStatements() * + (pira::Statements)(mainMethod->getOrCreateMD()->getNumberOfInclusiveStatements() * c->childFraction), c->childConstantThreshold); } @@ -99,8 +99,8 @@ void LIEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { debugString << " -> " << m; if (m >= c->imbalanceThreshold) { debugString << " => imbalanced"; - n->get()->setAssessment(m); - n->get()->flag(FlagType::Imbalanced); + n->getOrCreateMD()->setAssessment(m); + n->getOrCreateMD()->flag(FlagType::Imbalanced); imbalancedNodeSet.push_back(n); instrument(n); // make sure imbalanced functions stays instrumented @@ -108,12 +108,12 @@ void LIEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { } else { debugString << " => balanced"; // mark as irrelevant - n->get()->flag(FlagType::Irrelevant); + n->getOrCreateMD()->flag(FlagType::Irrelevant); } } else { debugString << "ignored (" << runtime << " / " << totalRuntime << " = " << runtime / totalRuntime << ")"; // mark as irrelevant - n->get()->flag(FlagType::Irrelevant); + n->getOrCreateMD()->flag(FlagType::Irrelevant); } spdlog::get("console")->debug(debugString.str()); } @@ -133,8 +133,8 @@ void LIEstimatorPhase::modifyGraph(metacg::CgNode *mainMethod) { std::ostringstream imbalancedNames; for (const auto &i : imbalancedNodeSet) { imbalancedNames << i->getFunctionName(); - imbalancedNames << " load imbalance assessment: " << i->get()->getAssessment().value(); - imbalancedNames << " incl. runtime: " << i->get()->getInclusiveRuntimeInSeconds() << " sec."; + imbalancedNames << " load imbalance assessment: " << i->getOrCreateMD()->getAssessment().value(); + imbalancedNames << " incl. runtime: " << i->getOrCreateMD()->getInclusiveRuntimeInSeconds() << " sec."; imbalancedNames << "\n"; } spdlog::get("console")->info("Load imbalance summary: " + imbalancedNames.str()); @@ -160,24 +160,24 @@ void LIEstimatorPhase::instrumentRelevantChildren(metacg::CgNode *node, pira::St visitedSet.insert(child); // process grandchilds (as possible implementations of virtual functions are children of those) - if (child->get()->isVirtual()) { + if (child->getOrCreateMD()->isVirtual()) { for (metacg::CgNode *gc : graph->getCallees(child)) { workQueue.push(gc); } } - if (child->get()->getNumberOfInclusiveStatements() >= statementThreshold) { - if (!child->get()->isFlagged(FlagType::Irrelevant)) { + if (child->getOrCreateMD()->getNumberOfInclusiveStatements() >= statementThreshold) { + if (!child->getOrCreateMD()->isFlagged(FlagType::Irrelevant)) { instrument(child); debugString << child->getFunctionName() << " (" - << child->get()->getNumberOfInclusiveStatements() << ") "; + << child->getOrCreateMD()->getNumberOfInclusiveStatements() << ") "; } else { debugString << "-" << child->getFunctionName() << "- (" - << child->get()->getNumberOfInclusiveStatements() << ") "; + << child->getOrCreateMD()->getNumberOfInclusiveStatements() << ") "; } } else { debugString << "/" << child->getFunctionName() << "\\ (" - << child->get()->getNumberOfInclusiveStatements() << ") "; + << child->getOrCreateMD()->getNumberOfInclusiveStatements() << ") "; } } } @@ -205,7 +205,7 @@ void LoadImbalance::LIEstimatorPhase::contextHandling(metacg::CgNode *n, metacg: if (c->contextStrategy == ContextStrategy::MajorPathsToMain || c->contextStrategy == ContextStrategy::MajorParentSteps) { for (metacg::CgNode *x : nodesOnPathToMain) { - if (!x->get()->isFlagged(FlagType::Visited)) { + if (!x->getOrCreateMD()->isFlagged(FlagType::Visited)) { relevantPaths.erase(x); } } @@ -273,8 +273,8 @@ void LIEstimatorPhase::findSyncPoints(CgNode *node) { // process all parents which are balanced + visisted for (CgNode *parent : graph->getCallers(node)) { - if (!parent->get()->isFlagged(FlagType::Imbalanced) && - parent->get()->isFlagged(FlagType::Visited)) { + if (!parent->getOrCreateMD()->isFlagged(FlagType::Imbalanced) && + parent->getOrCreateMD()->isFlagged(FlagType::Visited)) { // instrument all descendant synchronization routines instrumentByPattern( parent, [](CgNode *nodeInQuestion) { return nodeInQuestion->getFunctionName().rfind("MPI_", 0) == 0; },