[llvm-branch-commits] [polly] [Polly] Introduce PhaseManager and remove LPM support (PR #125442)
Karthika Devi C via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 8 22:02:13 PDT 2025
================
@@ -0,0 +1,419 @@
+//===------ PhaseManager.cpp ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "polly/Pass/PhaseManager.h"
+#include "polly/CodeGen/CodeGeneration.h"
+#include "polly/CodeGen/IslAst.h"
+#include "polly/CodePreparation.h"
+#include "polly/DeLICM.h"
+#include "polly/DeadCodeElimination.h"
+#include "polly/DependenceInfo.h"
+#include "polly/FlattenSchedule.h"
+#include "polly/ForwardOpTree.h"
+#include "polly/JSONExporter.h"
+#include "polly/MaximalStaticExpansion.h"
+#include "polly/PruneUnprofitable.h"
+#include "polly/ScheduleOptimizer.h"
+#include "polly/ScopDetection.h"
+#include "polly/ScopDetectionDiagnostic.h"
+#include "polly/ScopGraphPrinter.h"
+#include "polly/ScopInfo.h"
+#include "polly/Simplify.h"
+#include "llvm/Analysis/AssumptionCache.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
+#include "llvm/IR/Module.h"
+
+#define DEBUG_TYPE "polly-pass"
+
+using namespace polly;
+using namespace llvm;
+
+namespace {
+
+/// Recurse through all subregions and all regions and add them to RQ.
+static void addRegionIntoQueue(Region &R, SmallVector<Region *> &RQ) {
+ RQ.push_back(&R);
+ for (const auto &E : R)
+ addRegionIntoQueue(*E, RQ);
+}
+
+/// The phase pipeline of Polly to be embedded into another pass manager than
+/// runs passes on functions.
+///
+/// Polly holds state besides LLVM-IR (RegionInfo and ScopInfo) between phases
+/// that LLVM pass managers do not consider when scheduling analyses and passes.
+/// That is, the ScopInfo must persist between phases that a pass manager must
+/// not invalidate to recompute later.
+class PhaseManager {
+private:
+ Function &F;
+ FunctionAnalysisManager &FAM;
+ PollyPassOptions Opts;
+
+public:
+ PhaseManager(Function &F, FunctionAnalysisManager &FAM, PollyPassOptions Opts)
+ : F(F), FAM(FAM), Opts(std::move(Opts)) {}
+
+ /// Execute Polly's phases as indicated by the options.
+ bool run() {
+ // Get analyses from the function pass manager.
+ // These must be preserved during all phases so that if processing one SCoP
+ // has finished, the next SCoP can still use them. Recomputing is not an
+ // option because ScopDetection stores references to the old results.
+ // TODO: CodePreparation doesn't actually need these analysis, it just keeps
+ // them up-to-date. If they are not computed yet, can also compute after the
+ // prepare phase.
+ auto &LI = FAM.getResult<LoopAnalysis>(F);
+ auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
+ bool ModifiedIR = false;
+
+ // Phase: prepare
+ // TODO: Setting ModifiedIR will invalidate any anlysis, even if DT, LI are
+ // preserved.
+ if (Opts.isPhaseEnabled(PassPhase::Prepare))
+ ModifiedIR |= runCodePreparation(F, &DT, &LI, nullptr);
+
----------------
kartcq wrote:
Can we invalidate the necessary analysis here after CodePreparation pass.
FAM.invalidate(F, PA); helped me.
I am sure this is not the right way to go about this.
One of my observations is PDT got regenerated and as a result Regions got generated correctly again as Region Analysis requires PDT in turn. (Not sure how accurate is this again).
But in general I think we have to invalidate analysis as required after such transformations.
https://github.com/llvm/llvm-project/pull/125442
More information about the llvm-branch-commits
mailing list