[llvm] Port CodeGenPrepare to new pass manager (PR #68530)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 8 08:32:59 PDT 2023


github-actions[bot] wrote:


<!--LLVM CODE FORMAT COMMENT: {clang-format}-->

:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 32f719776552542691f14e786400fc222b7416f1 990cd21f5f268ca45e95a07c703e2658c70aa02f -- llvm/include/llvm/CodeGen/CodeGenPrepare.h llvm/include/llvm/InitializePasses.h llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/CodeGenPrepare.cpp llvm/lib/Passes/PassBuilder.cpp llvm/tools/opt/opt.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/CodeGen/CodeGenPrepare.h b/llvm/include/llvm/CodeGen/CodeGenPrepare.h
index 66a76257423a..fd2a09ff739f 100644
--- a/llvm/include/llvm/CodeGen/CodeGenPrepare.h
+++ b/llvm/include/llvm/CodeGen/CodeGenPrepare.h
@@ -1,4 +1,5 @@
-//===- CodeGenPrepare.h ------------------------------------------*- C++ -*-===//
+//===- CodeGenPrepare.h ------------------------------------------*- C++
+//-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -26,7 +27,7 @@ private:
   const TargetMachine *TM;
 
 public:
-  CodeGenPreparePass(const TargetMachine *TM): TM(TM) { }
+  CodeGenPreparePass(const TargetMachine *TM) : TM(TM) {}
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
 };
 
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 2b368b3f2552..f48e6c975f7d 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -81,7 +81,7 @@ void initializeCallGraphPrinterLegacyPassPass(PassRegistry&);
 void initializeCallGraphViewerPass(PassRegistry&);
 void initializeCallGraphWrapperPassPass(PassRegistry&);
 void initializeCheckDebugMachineModulePass(PassRegistry &);
-void initializeCodeGenPrepareLegacyPass(PassRegistry&);
+void initializeCodeGenPrepareLegacyPass(PassRegistry &);
 void initializeComplexDeinterleavingLegacyPassPass(PassRegistry&);
 void initializeConstantHoistingLegacyPassPass(PassRegistry&);
 void initializeCostModelAnalysisPass(PassRegistry&);
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 63afcf74ad2d..03fae7e90ee3 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/CodeGen/CodeGenPrepare.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -34,7 +35,6 @@
 #include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
 #include "llvm/CodeGen/ISDOpcodes.h"
 #include "llvm/CodeGen/MachineValueType.h"
-#include "llvm/CodeGen/CodeGenPrepare.h"
 #include "llvm/CodeGen/SelectionDAGNodes.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -273,7 +273,7 @@ static cl::opt<unsigned>
 static cl::opt<bool>
     DisableDeletePHIs("disable-cgp-delete-phis", cl::Hidden, cl::init(false),
                       cl::desc("Disable elimination of dead PHI nodes."));
-namespace llvm{
+namespace llvm {
 
 enum ExtType {
   ZeroExtension, // Zero extension has been seen.
@@ -302,7 +302,7 @@ using ValueToSExts = MapVector<Value *, SExts>;
 class TypePromotionTransaction;
 
 class CodeGenPrepare {
-  public:
+public:
   const TargetMachine *TM = nullptr;
   const TargetSubtargetInfo *SubtargetInfo = nullptr;
   const TargetLowering *TLI = nullptr;
@@ -365,7 +365,7 @@ class CodeGenPrepare {
   /// lazily and update it when required.
   std::unique_ptr<DominatorTree> DT;
 
-  public:
+public:
   /// If encounter huge function, we need to limit the build time.
   bool IsHugeFunc = false;
 
@@ -441,10 +441,9 @@ class CodeGenPrepare {
     BPI.reset();
     BFI.reset();
   }
-  bool run(Function &F, const TargetMachine *TM,
-                              const TargetTransformInfo &TTI,
-                              LoopInfo &LI, ProfileSummaryInfo &PSI, 
-                              const TargetLibraryInfo &TLInfo);
+  bool run(Function &F, const TargetMachine *TM, const TargetTransformInfo &TTI,
+           LoopInfo &LI, ProfileSummaryInfo &PSI,
+           const TargetLibraryInfo &TLInfo);
 
 private:
   template <typename F>
@@ -473,39 +472,39 @@ private:
   }
 };
 
- class CodeGenPrepareLegacy : public FunctionPass {
- public:
-    static char ID; // Pass identification, replacement for typeid
-    bool runOnFunction(Function &F) override;
-    const TargetMachine *TM = nullptr;
-    const TargetSubtargetInfo *SubtargetInfo = nullptr;
-    const TargetLowering *TLI = nullptr;
-    const TargetRegisterInfo *TRI = nullptr;
-    const TargetTransformInfo *TTI = nullptr;
-    const BasicBlockSectionsProfileReader *BBSectionsProfileReader = nullptr;
-    const TargetLibraryInfo *TLInfo = nullptr;
-    LoopInfo *LI = nullptr;
-    std::unique_ptr<BlockFrequencyInfo> BFI;
-    std::unique_ptr<BranchProbabilityInfo> BPI;
-    ProfileSummaryInfo *PSI = nullptr;
-    StringRef getPassName() const { return "CodeGen Prepare"; }
-
-    void getAnalysisUsage(AnalysisUsage &AU) const {
-      // FIXME: When we can selectively preserve passes, preserve the domtree.
-      AU.addRequired<ProfileSummaryInfoWrapperPass>();
-      AU.addRequired<TargetLibraryInfoWrapperPass>();
-      AU.addRequired<TargetPassConfig>();
-      AU.addRequired<TargetTransformInfoWrapperPass>();
-      AU.addRequired<LoopInfoWrapperPass>();
-      AU.addUsedIfAvailable<BasicBlockSectionsProfileReader>();
-    }
-
-    CodeGenPrepareLegacy() : FunctionPass(ID) {
-      initializeCodeGenPrepareLegacyPass(*PassRegistry::getPassRegistry());
-    }
+class CodeGenPrepareLegacy : public FunctionPass {
+public:
+  static char ID; // Pass identification, replacement for typeid
+  bool runOnFunction(Function &F) override;
+  const TargetMachine *TM = nullptr;
+  const TargetSubtargetInfo *SubtargetInfo = nullptr;
+  const TargetLowering *TLI = nullptr;
+  const TargetRegisterInfo *TRI = nullptr;
+  const TargetTransformInfo *TTI = nullptr;
+  const BasicBlockSectionsProfileReader *BBSectionsProfileReader = nullptr;
+  const TargetLibraryInfo *TLInfo = nullptr;
+  LoopInfo *LI = nullptr;
+  std::unique_ptr<BlockFrequencyInfo> BFI;
+  std::unique_ptr<BranchProbabilityInfo> BPI;
+  ProfileSummaryInfo *PSI = nullptr;
+  StringRef getPassName() const { return "CodeGen Prepare"; }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const {
+    // FIXME: When we can selectively preserve passes, preserve the domtree.
+    AU.addRequired<ProfileSummaryInfoWrapperPass>();
+    AU.addRequired<TargetLibraryInfoWrapperPass>();
+    AU.addRequired<TargetPassConfig>();
+    AU.addRequired<TargetTransformInfoWrapperPass>();
+    AU.addRequired<LoopInfoWrapperPass>();
+    AU.addUsedIfAvailable<BasicBlockSectionsProfileReader>();
+  }
+
+  CodeGenPrepareLegacy() : FunctionPass(ID) {
+    initializeCodeGenPrepareLegacyPass(*PassRegistry::getPassRegistry());
+  }
 };
 
-} // end anonymous namespace
+} // namespace llvm
 
 char CodeGenPrepareLegacy::ID = 0;
 
@@ -517,11 +516,11 @@ INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
-INITIALIZE_PASS_END(CodeGenPrepareLegacy, DEBUG_TYPE, "Optimize for code generation",
-                    false, false)
+INITIALIZE_PASS_END(CodeGenPrepareLegacy, DEBUG_TYPE,
+                    "Optimize for code generation", false, false)
 
 FunctionPass *llvm::createCodeGenPreparePass() {
- return new CodeGenPrepareLegacy();
+  return new CodeGenPrepareLegacy();
 }
 
 bool CodeGenPrepareLegacy::runOnFunction(Function &F) {
@@ -543,27 +542,29 @@ bool CodeGenPrepareLegacy::runOnFunction(Function &F) {
   return CGP.run(F, TM, TTI, LI, PSI, TLInfo);
 }
 
-PreservedAnalyses CodeGenPreparePass::run(Function &F, FunctionAnalysisManager &AM) {
- auto &TTI = AM.getResult<TargetIRAnalysis>(F);
- auto &LI = AM.getResult<LoopAnalysis>(F);
- auto &PSI = AM.getResult<ProfileSummaryAnalysis>(F);
- auto &TLInfo = AM.getResult<TargetLibraryAnalysis>(F);
-// auto &BasicBlockSectionsProfileReader = AM.getResult<BasicBlockSectionsProfileReader>(F);
-
- CodeGenPrepare CGP;
- bool Changed = CGP.run(F, TM, TTI, LI, PSI, TLInfo);
- if (!Changed)
-   return PreservedAnalyses::all();
- PreservedAnalyses PA;
- PA.preserveSet<CFGAnalyses>();
- PA.preserve<LoopAnalysis>();
- return PA;
+PreservedAnalyses CodeGenPreparePass::run(Function &F,
+                                          FunctionAnalysisManager &AM) {
+  auto &TTI = AM.getResult<TargetIRAnalysis>(F);
+  auto &LI = AM.getResult<LoopAnalysis>(F);
+  auto &PSI = AM.getResult<ProfileSummaryAnalysis>(F);
+  auto &TLInfo = AM.getResult<TargetLibraryAnalysis>(F);
+  // auto &BasicBlockSectionsProfileReader =
+  // AM.getResult<BasicBlockSectionsProfileReader>(F);
+
+  CodeGenPrepare CGP;
+  bool Changed = CGP.run(F, TM, TTI, LI, PSI, TLInfo);
+  if (!Changed)
+    return PreservedAnalyses::all();
+  PreservedAnalyses PA;
+  PA.preserveSet<CFGAnalyses>();
+  PA.preserve<LoopAnalysis>();
+  return PA;
 }
 
 bool CodeGenPrepare::run(Function &F, const TargetMachine *TM,
-                            const TargetTransformInfo &TTI,
-                            LoopInfo &LI, ProfileSummaryInfo &PSI,
-                            const TargetLibraryInfo &TLInfo) {
+                         const TargetTransformInfo &TTI, LoopInfo &LI,
+                         ProfileSummaryInfo &PSI,
+                         const TargetLibraryInfo &TLInfo) {
   if (DisableBranchOpts)
     return false;
 
@@ -589,8 +590,7 @@ bool CodeGenPrepare::run(Function &F, const TargetMachine *TM,
   if (BBSectionsGuidedSectionPrefix && BBSectionsProfileReader &&
       BBSectionsProfileReader->isFunctionHot(F.getName())) {
     F.setSectionPrefix("hot");
-  } 
-  else if (ProfileGuidedSectionPrefix) {
+  } else if (ProfileGuidedSectionPrefix) {
     // The hot attribute overwrites profile count based hotness while profile
     // counts based hotness overwrite the cold attribute.
     // This is a conservative behabvior.
@@ -2837,9 +2837,9 @@ LLVM_DUMP_METHOD void ExtAddrMode::dump() const {
 }
 #endif
 
-} // end anonymous namespace
+} // namespace llvm
 
-namespace llvm{
+namespace llvm {
 
 /// This class provides transaction based operation on the IR.
 /// Every change made through this class is recorded in the internal state and
@@ -3265,7 +3265,7 @@ private:
   SetOfInstrs &RemovedInsts;
 };
 
-} // end anonymous namespace
+} // namespace llvm
 
 void TypePromotionTransaction::setOperand(Instruction *Inst, unsigned Idx,
                                           Value *NewVal) {
@@ -4092,7 +4092,7 @@ private:
     }
   }
 };
-} // end anonymous namespace
+} // namespace llvm
 
 /// Try adding ScaleReg*Scale to the current addressing mode.
 /// Return true and update AddrMode if this addr mode is legal for the target,
@@ -4268,7 +4268,7 @@ static bool isPromotedInstructionLegal(const TargetLowering &TLI,
       ISDOpcode, TLI.getValueType(DL, PromotedInst->getType()));
 }
 
-namespace llvm{
+namespace llvm {
 
 /// Hepler class to perform type promotion.
 class TypePromotionHelper {
@@ -4400,7 +4400,7 @@ public:
                           const InstrToOrigTy &PromotedInsts);
 };
 
-} // end anonymous namespace
+} // namespace llvm
 
 bool TypePromotionHelper::canGetThrough(const Instruction *Inst,
                                         Type *ConsideredExtType,
@@ -7428,7 +7428,7 @@ bool CodeGenPrepare::optimizeSwitchInst(SwitchInst *SI) {
   return Changed;
 }
 
-namespace llvm{
+namespace llvm {
 
 /// Helper class to promote a scalar operation to a vector one.
 /// This class is used to move downward extractelement transition.
@@ -7707,7 +7707,7 @@ public:
   }
 };
 
-} // end anonymous namespace
+} // namespace llvm
 
 void VectorPromoteHelper::promoteImpl(Instruction *ToBePromoted) {
   // At this point, we know that all the operands of ToBePromoted but Def
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 101ddee2b4ae..006fdd1ae9ac 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -234,8 +234,8 @@
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
 #include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h"
 #include "llvm/Transforms/Utils/CountVisits.h"
-#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/DXILUpgrade.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/FixIrreducible.h"
 #include "llvm/Transforms/Utils/HelloWorld.h"

``````````

</details>


https://github.com/llvm/llvm-project/pull/68530


More information about the llvm-commits mailing list