Skip to content

[Passes] Generalize ShouldRunExtraVectorPasses to allow re-use (NFCI). #118323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 4, 2024

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Dec 2, 2024

Generalize ShouldRunExtraVectorPasses toj ShouldRunExtraPasses, to allow re-use for other transformations. I intend to use this to let LowerMatrixIntrinsicsPass request EarlyCSE if there are any matrix constructs to lower. This should allow enabling LowerMatrixIntrinsics without a noticable compile-time hit.

@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-ir

Author: Florian Hahn (fhahn)

Changes

Generalize ShouldRunExtraVectorPasses toj ShouldRunExtraPasses, to allow re-use for other transformations. I intend to use this to let LowerMatrixIntrinsicsPass request EarlyCSE if there are any matrix constructs to lower. This should allow enabling LowerMatrixIntrinsics without a noticable compile-time hit.


Full diff: https://github.com/llvm/llvm-project/pull/118323.diff

6 Files Affected:

  • (modified) llvm/include/llvm/IR/PassManager.h (+32)
  • (modified) llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h (-32)
  • (modified) llvm/lib/IR/PassManager.cpp (+2)
  • (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+2-2)
  • (modified) llvm/lib/Passes/PassRegistry.def (+2-2)
  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+2-4)
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 5dab9d0d0a7979..91730301bbd415 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -935,6 +935,38 @@ struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
   }
 };
 
+/// A marker analyss to determine if extra passes should be run on demand.
+/// Passes requesting extra transformations to run need to request and preserve
+/// this analysis.
+struct ShouldRunExtraPasses : public AnalysisInfoMixin<ShouldRunExtraPasses> {
+  static AnalysisKey Key;
+  struct Result {
+    bool invalidate(Function &F, const PreservedAnalyses &PA,
+                    FunctionAnalysisManager::Invalidator &) {
+      // Check whether the analysis has been explicitly invalidated. Otherwise,
+      // it remains preserved.
+      auto PAC = PA.getChecker<ShouldRunExtraPasses>();
+      return !PAC.preservedWhenStateless();
+    }
+  };
+
+  Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
+};
+
+/// A pass manager to run a set of extra function passes if the
+/// ShouldRunExtraPasses marker analysis is present. This allows passes to
+/// request additional transformations on demand. An example is extra
+/// simplifications after loop-vectorization, if runtime checks have been added.
+struct ExtraPassManager : public FunctionPassManager {
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
+    auto PA = PreservedAnalyses::all();
+    if (AM.getCachedResult<ShouldRunExtraPasses>(F))
+      PA.intersect(FunctionPassManager::run(F, AM));
+    PA.abandon<ShouldRunExtraPasses>();
+    return PA;
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_PASSMANAGER_H
diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
index 24b6354662955e..9256cf16c0157e 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
@@ -80,38 +80,6 @@ class TargetTransformInfo;
 extern cl::opt<bool> EnableLoopInterleaving;
 extern cl::opt<bool> EnableLoopVectorization;
 
-/// A marker to determine if extra passes after loop vectorization should be
-/// run.
-struct ShouldRunExtraVectorPasses
-    : public AnalysisInfoMixin<ShouldRunExtraVectorPasses> {
-  static AnalysisKey Key;
-  struct Result {
-    bool invalidate(Function &F, const PreservedAnalyses &PA,
-                    FunctionAnalysisManager::Invalidator &) {
-      // Check whether the analysis has been explicitly invalidated. Otherwise,
-      // it remains preserved.
-      auto PAC = PA.getChecker<ShouldRunExtraVectorPasses>();
-      return !PAC.preservedWhenStateless();
-    }
-  };
-
-  Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
-};
-
-/// A pass manager to run a set of extra function simplification passes after
-/// vectorization, if requested. LoopVectorize caches the
-/// ShouldRunExtraVectorPasses analysis to request extra simplifications, if
-/// they could be beneficial.
-struct ExtraVectorPassManager : public FunctionPassManager {
-  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
-    auto PA = PreservedAnalyses::all();
-    if (AM.getCachedResult<ShouldRunExtraVectorPasses>(F))
-      PA.intersect(FunctionPassManager::run(F, AM));
-    PA.abandon<ShouldRunExtraVectorPasses>();
-    return PA;
-  }
-};
-
 struct LoopVectorizeOptions {
   /// If false, consider all loops for interleaving.
   /// If true, only loops that explicitly request interleaving are considered.
diff --git a/llvm/lib/IR/PassManager.cpp b/llvm/lib/IR/PassManager.cpp
index bf8f7906d3368d..4990695108fc70 100644
--- a/llvm/lib/IR/PassManager.cpp
+++ b/llvm/lib/IR/PassManager.cpp
@@ -160,3 +160,5 @@ void llvm::printIRUnitNameForStackTrace<Function>(raw_ostream &OS,
 AnalysisSetKey CFGAnalyses::SetKey;
 
 AnalysisSetKey PreservedAnalyses::AllAnalysesKey;
+
+AnalysisKey ShouldRunExtraPasses::Key;
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 5a7c327de95870..5a8c60adccee34 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1306,8 +1306,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
   // Cleanup after the loop optimization passes.
   FPM.addPass(InstCombinePass());
 
+  ExtraPassManager ExtraPasses;
   if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
-    ExtraVectorPassManager ExtraPasses;
     // At higher optimization levels, try to clean up any runtime overlap and
     // alignment checks inserted by the vectorizer. We want to track correlated
     // runtime checks for two inner loops in the same outer loop, fold any
@@ -1328,8 +1328,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
     ExtraPasses.addPass(
         SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
     ExtraPasses.addPass(InstCombinePass());
-    FPM.addPass(std::move(ExtraPasses));
   }
+  FPM.addPass(std::move(ExtraPasses));
 
   // Now that we've formed fast to execute loop structures, we do further
   // optimizations. These are run afterward as they might block doing complex
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 7c3798f6462a46..260fbae1d2f87d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -303,8 +303,8 @@ FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
 FUNCTION_ANALYSIS("should-not-run-function-passes",
                   ShouldNotRunFunctionPassesAnalysis())
-FUNCTION_ANALYSIS("should-run-extra-vector-passes",
-                  ShouldRunExtraVectorPasses())
+FUNCTION_ANALYSIS("should-run-extra-passes",
+                  ShouldRunExtraPasses())
 FUNCTION_ANALYSIS("ssp-layout", SSPLayoutAnalysis())
 FUNCTION_ANALYSIS("stack-safety-local", StackSafetyAnalysis())
 FUNCTION_ANALYSIS("target-ir",
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 90312c1a28df3c..2ce293889e88e4 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -442,8 +442,6 @@ using SCEV2ValueTy = DenseMap<const SCEV *, Value *>;
 
 namespace llvm {
 
-AnalysisKey ShouldRunExtraVectorPasses::Key;
-
 /// InnerLoopVectorizer vectorizes loops which contain only one basic
 /// block to a specified vectorization factor (VF).
 /// This class performs the widening of scalars into vectors, or multiple
@@ -10476,8 +10474,8 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
     // extra simplification passes should be run.
     // TODO: MadeCFGChanges is not a prefect proxy. Extra passes should only
     // be run if runtime checks have been added.
-    AM.getResult<ShouldRunExtraVectorPasses>(F);
-    PA.preserve<ShouldRunExtraVectorPasses>();
+    AM.getResult<ShouldRunExtraPasses>(F);
+    PA.preserve<ShouldRunExtraPasses>();
   } else {
     PA.preserveSet<CFGAnalyses>();
   }

@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2024

@llvm/pr-subscribers-vectorizers

Author: Florian Hahn (fhahn)

Changes

Generalize ShouldRunExtraVectorPasses toj ShouldRunExtraPasses, to allow re-use for other transformations. I intend to use this to let LowerMatrixIntrinsicsPass request EarlyCSE if there are any matrix constructs to lower. This should allow enabling LowerMatrixIntrinsics without a noticable compile-time hit.


Full diff: https://github.com/llvm/llvm-project/pull/118323.diff

6 Files Affected:

  • (modified) llvm/include/llvm/IR/PassManager.h (+32)
  • (modified) llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h (-32)
  • (modified) llvm/lib/IR/PassManager.cpp (+2)
  • (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+2-2)
  • (modified) llvm/lib/Passes/PassRegistry.def (+2-2)
  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+2-4)
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 5dab9d0d0a7979..91730301bbd415 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -935,6 +935,38 @@ struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
   }
 };
 
+/// A marker analyss to determine if extra passes should be run on demand.
+/// Passes requesting extra transformations to run need to request and preserve
+/// this analysis.
+struct ShouldRunExtraPasses : public AnalysisInfoMixin<ShouldRunExtraPasses> {
+  static AnalysisKey Key;
+  struct Result {
+    bool invalidate(Function &F, const PreservedAnalyses &PA,
+                    FunctionAnalysisManager::Invalidator &) {
+      // Check whether the analysis has been explicitly invalidated. Otherwise,
+      // it remains preserved.
+      auto PAC = PA.getChecker<ShouldRunExtraPasses>();
+      return !PAC.preservedWhenStateless();
+    }
+  };
+
+  Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
+};
+
+/// A pass manager to run a set of extra function passes if the
+/// ShouldRunExtraPasses marker analysis is present. This allows passes to
+/// request additional transformations on demand. An example is extra
+/// simplifications after loop-vectorization, if runtime checks have been added.
+struct ExtraPassManager : public FunctionPassManager {
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
+    auto PA = PreservedAnalyses::all();
+    if (AM.getCachedResult<ShouldRunExtraPasses>(F))
+      PA.intersect(FunctionPassManager::run(F, AM));
+    PA.abandon<ShouldRunExtraPasses>();
+    return PA;
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_PASSMANAGER_H
diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
index 24b6354662955e..9256cf16c0157e 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
@@ -80,38 +80,6 @@ class TargetTransformInfo;
 extern cl::opt<bool> EnableLoopInterleaving;
 extern cl::opt<bool> EnableLoopVectorization;
 
-/// A marker to determine if extra passes after loop vectorization should be
-/// run.
-struct ShouldRunExtraVectorPasses
-    : public AnalysisInfoMixin<ShouldRunExtraVectorPasses> {
-  static AnalysisKey Key;
-  struct Result {
-    bool invalidate(Function &F, const PreservedAnalyses &PA,
-                    FunctionAnalysisManager::Invalidator &) {
-      // Check whether the analysis has been explicitly invalidated. Otherwise,
-      // it remains preserved.
-      auto PAC = PA.getChecker<ShouldRunExtraVectorPasses>();
-      return !PAC.preservedWhenStateless();
-    }
-  };
-
-  Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
-};
-
-/// A pass manager to run a set of extra function simplification passes after
-/// vectorization, if requested. LoopVectorize caches the
-/// ShouldRunExtraVectorPasses analysis to request extra simplifications, if
-/// they could be beneficial.
-struct ExtraVectorPassManager : public FunctionPassManager {
-  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
-    auto PA = PreservedAnalyses::all();
-    if (AM.getCachedResult<ShouldRunExtraVectorPasses>(F))
-      PA.intersect(FunctionPassManager::run(F, AM));
-    PA.abandon<ShouldRunExtraVectorPasses>();
-    return PA;
-  }
-};
-
 struct LoopVectorizeOptions {
   /// If false, consider all loops for interleaving.
   /// If true, only loops that explicitly request interleaving are considered.
diff --git a/llvm/lib/IR/PassManager.cpp b/llvm/lib/IR/PassManager.cpp
index bf8f7906d3368d..4990695108fc70 100644
--- a/llvm/lib/IR/PassManager.cpp
+++ b/llvm/lib/IR/PassManager.cpp
@@ -160,3 +160,5 @@ void llvm::printIRUnitNameForStackTrace<Function>(raw_ostream &OS,
 AnalysisSetKey CFGAnalyses::SetKey;
 
 AnalysisSetKey PreservedAnalyses::AllAnalysesKey;
+
+AnalysisKey ShouldRunExtraPasses::Key;
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 5a7c327de95870..5a8c60adccee34 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1306,8 +1306,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
   // Cleanup after the loop optimization passes.
   FPM.addPass(InstCombinePass());
 
+  ExtraPassManager ExtraPasses;
   if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
-    ExtraVectorPassManager ExtraPasses;
     // At higher optimization levels, try to clean up any runtime overlap and
     // alignment checks inserted by the vectorizer. We want to track correlated
     // runtime checks for two inner loops in the same outer loop, fold any
@@ -1328,8 +1328,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
     ExtraPasses.addPass(
         SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
     ExtraPasses.addPass(InstCombinePass());
-    FPM.addPass(std::move(ExtraPasses));
   }
+  FPM.addPass(std::move(ExtraPasses));
 
   // Now that we've formed fast to execute loop structures, we do further
   // optimizations. These are run afterward as they might block doing complex
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 7c3798f6462a46..260fbae1d2f87d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -303,8 +303,8 @@ FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
 FUNCTION_ANALYSIS("should-not-run-function-passes",
                   ShouldNotRunFunctionPassesAnalysis())
-FUNCTION_ANALYSIS("should-run-extra-vector-passes",
-                  ShouldRunExtraVectorPasses())
+FUNCTION_ANALYSIS("should-run-extra-passes",
+                  ShouldRunExtraPasses())
 FUNCTION_ANALYSIS("ssp-layout", SSPLayoutAnalysis())
 FUNCTION_ANALYSIS("stack-safety-local", StackSafetyAnalysis())
 FUNCTION_ANALYSIS("target-ir",
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 90312c1a28df3c..2ce293889e88e4 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -442,8 +442,6 @@ using SCEV2ValueTy = DenseMap<const SCEV *, Value *>;
 
 namespace llvm {
 
-AnalysisKey ShouldRunExtraVectorPasses::Key;
-
 /// InnerLoopVectorizer vectorizes loops which contain only one basic
 /// block to a specified vectorization factor (VF).
 /// This class performs the widening of scalars into vectors, or multiple
@@ -10476,8 +10474,8 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
     // extra simplification passes should be run.
     // TODO: MadeCFGChanges is not a prefect proxy. Extra passes should only
     // be run if runtime checks have been added.
-    AM.getResult<ShouldRunExtraVectorPasses>(F);
-    PA.preserve<ShouldRunExtraVectorPasses>();
+    AM.getResult<ShouldRunExtraPasses>(F);
+    PA.preserve<ShouldRunExtraPasses>();
   } else {
     PA.preserveSet<CFGAnalyses>();
   }

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about reusing a single, unparameterized marker analysis for multiple extra pass managers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be part of PassManager.h, which is widely included.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a separate file (llvm/Transforms/Utils/ExtraPassManager), but maybe there's a better place or name?

@@ -935,6 +935,38 @@ struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
}
};

/// A marker analyss to determine if extra passes should be run on demand.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A marker analyss to determine if extra passes should be run on demand.
/// A marker analysis to determine if extra passes should be run on demand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

}
FPM.addPass(std::move(ExtraPasses));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this move?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a consequence of using a single marker, this required the pass manager to run unconditionally to clear the marker set by LV.

@fhahn fhahn force-pushed the genearlize-extra-vector-passes branch from cb6f7b9 to ab05874 Compare December 3, 2024 13:08
Copy link

github-actions bot commented Dec 3, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@fhahn fhahn force-pushed the genearlize-extra-vector-passes branch from ab05874 to b91287d Compare December 3, 2024 13:12
@fhahn
Copy link
Contributor Author

fhahn commented Dec 3, 2024

I'm concerned about reusing a single, unparameterized marker analysis for multiple extra pass managers.

Updated to require each use to create their own marker analysis, not sure if there's a nicer way to avoid some of the extra boilerplate (although it is quite minimal)

@@ -0,0 +1,56 @@
//===- ExtraPassManager.h - Loop pass management -----------------*- C++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied header comment :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, missed that. Updated thanks!

/// request additional transformations on demand. An example is extra
/// simplifications after loop-vectorization, if runtime checks have been added.
template <typename MarkerTy>
struct ExtraPassManager : public FunctionPassManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct ExtraPassManager : public FunctionPassManager {
struct ExtraFunctionPassManager : public FunctionPassManager {

I assume the reason that this doesn't cover the extra LoopUnswitch run is that that one needs an LPM instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might still make sense to also move the LPM variant here as well? It can at least use the same ShouldRunExtraPasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, update the name and moved ExtraLoopPassManager here as well. Extended ShouldRunExtraPasses to support Loops as well

@@ -201,6 +170,13 @@ void reportVectorizationFailure(const StringRef DebugMsg,
const StringRef OREMsg, const StringRef ORETag,
OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I = nullptr);

/// A marker analyss to determine if extra passes should be run after loop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A marker analyss to determine if extra passes should be run after loop
/// A marker analysis to determine if extra passes should be run after loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks!

@@ -134,6 +134,7 @@
#include "llvm/Support/NativeFormatting.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/ExtraPassManager.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this include needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, thanks!

@fhahn fhahn force-pushed the genearlize-extra-vector-passes branch from 9163f47 to c7772d2 Compare December 4, 2024 14:01
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

public AnalysisInfoMixin<ShouldRunExtraSimpleLoopUnswitch> {
static AnalysisKey Key;

static bool isRequired() { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this isRequired? I thought that's only relevant for passes.

Comment on lines 1 to 2
//===- ExtraFunctionPassManager.h - Run Optimizations on Demand ---------*- C++
//-*-===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to avoid the odd line break here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, I thought I already fixed this up....

//===- ExtraFunctionPassManager.h - Run Optimizations on Demand ---------*- C++
//-*-===//
//
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two empty lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single line now, thanks

return PA;
}

static bool isRequired() { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this should either be on both or neither. I'd expect this to be inherited from FunctionPassManager/LoopPassManager, but maybe my C++-foo is too weak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be needed, removed ,thanks

fhahn added 6 commits December 4, 2024 14:44
Generalize ShouldRunExtraVectorPasses toj ShouldRunExtraPasses, to allow
re-use for other transformations. I intend to use this to let
LowerMatrixIntrinsicsPass request EarlyCSE if there are any matrix
constructs to lower. This should allow enabling LowerMatrixIntrinsics
without a noticable compile-time hit.
@fhahn fhahn force-pushed the genearlize-extra-vector-passes branch from 55205b2 to ddc5037 Compare December 4, 2024 14:50
@fhahn fhahn merged commit 9e66206 into llvm:main Dec 4, 2024
6 of 8 checks passed
@fhahn fhahn deleted the genearlize-extra-vector-passes branch December 4, 2024 16:55
@fhahn fhahn restored the genearlize-extra-vector-passes branch December 4, 2024 16:55
@fhahn fhahn deleted the genearlize-extra-vector-passes branch December 4, 2024 16:55
Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad to see this sort of thing, one comment though

/// request additional transformations on demand. An example is extra
/// simplifications after loop-vectorization, if runtime checks have been added.
template <typename MarkerTy>
struct ExtraFunctionPassManager : public FunctionPassManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new pass manager data structures very much do not endorse overriding methods via inheritance. I'd prefer ExtraFunctionPassManager to have a FunctionPassManager member instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put up #119348, is that what you had in mind?

fhahn added a commit to fhahn/llvm-project that referenced this pull request Dec 10, 2024
As suggested post-commit for
llvm#118323, adjust the extra pass
managers to no inherit from Function/LoopPassManager, but manage the
extra passes via member pass managers.
fhahn added a commit to fhahn/llvm-project that referenced this pull request Dec 11, 2024
As suggested post-commit for
llvm#118323, adjust the extra pass
managers to no inherit from Function/LoopPassManager, but manage the
extra passes via member pass managers.
fhahn added a commit that referenced this pull request Dec 11, 2024
As suggested post-commit for
#118323, adjust the extra pass
managers to no inherit from Function/LoopPassManager, but manage the
extra passes via member pass managers.

PR: #119348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants