[llvm] Port CodeGenPrepare to new pass manager (and BasicBlockSectionsProfil… (PR #77182)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 5 23:35:02 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
@llvm/pr-subscribers-debuginfo
Author: Nick Anderson (nickleus27)
<details>
<summary>Changes</summary>
Port CodeGenPrepare to new pass manager and dependency BasicBlockSectionsProfileReader
Fixes: #<!-- -->75380
---
Patch is 106.74 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/77182.diff
112 Files Affected:
- (modified) llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h (+62-21)
- (added) llvm/include/llvm/CodeGen/CodeGenPrepare.h (+35)
- (modified) llvm/include/llvm/CodeGen/Passes.h (+2-2)
- (modified) llvm/include/llvm/InitializePasses.h (+2-2)
- (modified) llvm/include/llvm/LinkAllPasses.h (+1-1)
- (modified) llvm/lib/CodeGen/BasicBlockPathCloning.cpp (+6-5)
- (modified) llvm/lib/CodeGen/BasicBlockSections.cpp (+4-4)
- (modified) llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp (+42-10)
- (modified) llvm/lib/CodeGen/CodeGen.cpp (+1-1)
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+87-38)
- (modified) llvm/lib/CodeGen/TargetPassConfig.cpp (+2-2)
- (modified) llvm/lib/Passes/PassBuilder.cpp (+2)
- (modified) llvm/lib/Passes/PassRegistry.def (+2)
- (modified) llvm/test/CodeGen/AArch64/aarch64-codegen-prepare-atp.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/and-sink.ll (+2-2)
- (modified) llvm/test/CodeGen/AArch64/arm64-bitfield-extract.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll (+3-3)
- (modified) llvm/test/CodeGen/AArch64/arm64_32-gep-sink.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/cgp-trivial-phi-node.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/convertphitype.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/scalable-vector-promotion.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/sve-vscale.ll (+1-1)
- (modified) llvm/test/CodeGen/AArch64/sve2-vscale-sinking.ll (+1-1)
- (modified) llvm/test/CodeGen/AMDGPU/cgp-addressing-modes-flat.ll (+4-4)
- (modified) llvm/test/CodeGen/AMDGPU/cgp-addressing-modes-gfx1030.ll (+1-1)
- (modified) llvm/test/CodeGen/AMDGPU/cgp-addressing-modes-gfx908.ll (+1-1)
- (modified) llvm/test/CodeGen/AMDGPU/cgp-addressing-modes.ll (+4-4)
- (modified) llvm/test/CodeGen/ARM/vector-promotion.ll (+2-2)
- (modified) llvm/test/CodeGen/Generic/addr-sink-call-multi-arg.ll (+1-1)
- (modified) llvm/test/CodeGen/Generic/addr-use-count.ll (+1-1)
- (modified) llvm/test/CodeGen/X86/callbr-codegenprepare.ll (+1-1)
- (modified) llvm/test/CodeGen/X86/codegen-prepare-addrmode-sext.ll (+1-1)
- (modified) llvm/test/CodeGen/X86/codegen-prepare-extload.ll (+3-3)
- (modified) llvm/test/CodeGen/X86/convertphitype.ll (+1-1)
- (modified) llvm/test/CodeGen/X86/indirect-br-gep-unmerge.ll (+1-1)
- (modified) llvm/test/CodeGen/X86/pr58538.ll (+2-2)
- (modified) llvm/test/CodeGen/X86/tailcall-cgp-dup.ll (+1-1)
- (modified) llvm/test/CodeGen/X86/tailcall-extract.ll (+1-1)
- (modified) llvm/test/DebugInfo/ARM/salvage-debug-info.ll (+1-1)
- (modified) llvm/test/DebugInfo/X86/zextload.ll (+1-1)
- (modified) llvm/test/Other/codegenprepare-and-debug.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/combine-address-mode.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/free-zext.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/gather-scatter-opt-inseltpoison.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/gather-scatter-opt.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/overflow-intrinsics.ll (+3-3)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/sink-gather-scatter-addressing.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/trunc-weird-user.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AArch64/zext-to-shuffle.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AMDGPU/addressing-modes.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AMDGPU/no-sink-addrspacecast.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/AMDGPU/sink-addrspacecast.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/dead-gep.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/memory-intrinsics.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/overflow-intrinsics.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/sink-addrmode.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/splitgep.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/NVPTX/bypass-slow-div-constant-numerator.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/NVPTX/bypass-slow-div-not-exact.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/NVPTX/bypass-slow-div-special-cases.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/NVPTX/bypass-slow-div.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/NVPTX/dont-introduce-addrspacecast.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/NVPTX/dont-sink-nop-addrspacecast.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/PowerPC/split-store-alignment.ll (+2-2)
- (modified) llvm/test/Transforms/CodeGenPrepare/RISCV/and-mask-sink.ll (+4-4)
- (modified) llvm/test/Transforms/CodeGenPrepare/RISCV/cttz-ctlz.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/SPARC/overflow-intrinsics.ll (+3-3)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/catchpad-phi-cast.ll (+2-2)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash-inseltpoison.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/computedgoto.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/cttz-ctlz.ll (+5-5)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/extend-sink-hoist.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/freeze-brcond.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/gather-scatter-opt-inseltpoison.ll (+2-2)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/gather-scatter-opt.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/gep-unmerging.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/invariant.group.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/masked-gather-struct-gep.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/nonintegral.ll (+2-2)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/optimizeSelect-DT.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll (+3-3)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/pr27536.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/pr35658.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/pr72046.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/recursively-delete-dead-instructions.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/remove-assume-block.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/select.ll (+3-3)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/sink-addrmode-base.ll (+2-2)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/sink-addrmode-inseltpoison.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/sink-addrmode-select.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/sink-addrmode-two-phi.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/sink-addrmode.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/sink-addrspacecast.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/split-indirect-loop.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/split-store-alignment.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/statepoint-relocate.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/tailcall-assume-xbb.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/vec-shift-inseltpoison.ll (+7-7)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/vec-shift.ll (+7-7)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/widenable-condition.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/x86-shuffle-sink-inseltpoison.ll (+4-4)
- (modified) llvm/test/Transforms/CodeGenPrepare/X86/x86-shuffle-sink.ll (+4-4)
- (modified) llvm/test/Transforms/CodeGenPrepare/dead-allocation.ll (+1-1)
- (modified) llvm/test/Transforms/CodeGenPrepare/skip-merging-case-block.ll (+1-1)
- (modified) llvm/test/Transforms/HotColdSplit/coldentrycount.ll (+1-1)
- (modified) llvm/test/Transforms/LoadStoreVectorizer/X86/codegenprepare-produced-address-math.ll (+1-1)
- (modified) llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll (+3-3)
- (modified) llvm/tools/opt/opt.cpp (+1-1)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index dfb8d5d9f2f5d3..bba675f1d3eb7d 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -21,11 +21,14 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Target/TargetMachine.h"
+
using namespace llvm;
namespace llvm {
@@ -72,25 +75,13 @@ template <> struct DenseMapInfo<UniqueBBID> {
}
};
-class BasicBlockSectionsProfileReader : public ImmutablePass {
+class BasicBlockSectionsProfileReader {
public:
- static char ID;
-
+ friend class BasicBlockSectionsProfileReaderWrapperPass;
BasicBlockSectionsProfileReader(const MemoryBuffer *Buf)
- : ImmutablePass(ID), MBuf(Buf),
- LineIt(*Buf, /*SkipBlanks=*/true, /*CommentMarker=*/'#') {
- initializeBasicBlockSectionsProfileReaderPass(
- *PassRegistry::getPassRegistry());
- };
+ : MBuf(Buf), LineIt(*Buf, /*SkipBlanks=*/true, /*CommentMarker=*/'#'){};
- BasicBlockSectionsProfileReader() : ImmutablePass(ID) {
- initializeBasicBlockSectionsProfileReaderPass(
- *PassRegistry::getPassRegistry());
- }
-
- StringRef getPassName() const override {
- return "Basic Block Sections Profile Reader";
- }
+ BasicBlockSectionsProfileReader(){};
// Returns true if basic block sections profile exist for function \p
// FuncName.
@@ -109,10 +100,6 @@ class BasicBlockSectionsProfileReader : public ImmutablePass {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- // Initializes the FunctionNameToDIFilename map for the current module and
- // then reads the profile for the matching functions.
- bool doInitialization(Module &M) override;
-
private:
StringRef getAliasName(StringRef FuncName) const {
auto R = FuncAliasMap.find(FuncName);
@@ -170,7 +157,61 @@ class BasicBlockSectionsProfileReader : public ImmutablePass {
// sections profile. \p Buf is a memory buffer that contains the list of
// functions and basic block ids to selectively enable basic block sections.
ImmutablePass *
-createBasicBlockSectionsProfileReaderPass(const MemoryBuffer *Buf);
+createBasicBlockSectionsProfileReaderWrapperPass(const MemoryBuffer *Buf);
+
+/// Analysis pass providing the \c BasicBlockSectionsProfileReader.
+///
+/// Note that this pass's result cannot be invalidated, it is immutable for the
+/// life of the module.
+class BasicBlockSectionsProfileReaderAnalysis
+ : public AnalysisInfoMixin<BasicBlockSectionsProfileReaderAnalysis> {
+
+public:
+ static AnalysisKey Key;
+ typedef BasicBlockSectionsProfileReader Result;
+ BasicBlockSectionsProfileReaderAnalysis(const TargetMachine *TM) : TM(TM) {}
+
+ Result run(Function &F, FunctionAnalysisManager &AM);
+
+private:
+ const TargetMachine *TM;
+};
+
+class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
+public:
+ static char ID;
+ BasicBlockSectionsProfileReader BBSPR;
+
+ BasicBlockSectionsProfileReaderWrapperPass(const MemoryBuffer *Buf)
+ : ImmutablePass(ID), BBSPR(BasicBlockSectionsProfileReader(Buf)) {
+ initializeBasicBlockSectionsProfileReaderWrapperPassPass(
+ *PassRegistry::getPassRegistry());
+ };
+
+ BasicBlockSectionsProfileReaderWrapperPass()
+ : ImmutablePass(ID), BBSPR(BasicBlockSectionsProfileReader()) {
+ initializeBasicBlockSectionsProfileReaderWrapperPassPass(
+ *PassRegistry::getPassRegistry());
+ }
+
+ StringRef getPassName() const override {
+ return "Basic Block Sections Profile Reader";
+ }
+
+ bool isFunctionHot(StringRef FuncName) const;
+
+ std::pair<bool, SmallVector<BBClusterInfo>>
+ getClusterInfoForFunction(StringRef FuncName) const;
+
+ SmallVector<SmallVector<unsigned>>
+ getClonePathsForFunction(StringRef FuncName) const;
+
+ // Initializes the FunctionNameToDIFilename map for the current module and
+ // then reads the profile for the matching functions.
+ bool doInitialization(Module &M) override;
+
+ BasicBlockSectionsProfileReader &getBBSPR();
+};
} // namespace llvm
#endif // LLVM_CODEGEN_BASICBLOCKSECTIONSPROFILEREADER_H
diff --git a/llvm/include/llvm/CodeGen/CodeGenPrepare.h b/llvm/include/llvm/CodeGen/CodeGenPrepare.h
new file mode 100644
index 00000000000000..dee3a9ee53d767
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/CodeGenPrepare.h
@@ -0,0 +1,35 @@
+//===- 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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+/// \file
+///
+/// Defines an IR pass for CodeGen Prepare.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_PREPARE_H
+#define LLVM_CODEGEN_PREPARE_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class Function;
+class TargetMachine;
+
+class CodeGenPreparePass : public PassInfoMixin<CodeGenPreparePass> {
+private:
+ const TargetMachine *TM;
+
+public:
+ CodeGenPreparePass(const TargetMachine *TM) : TM(TM) {}
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+} // end namespace llvm
+
+#endif // LLVM_CODEGEN_PREPARE_H
diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h
index ca9fbb1def7624..bbfb8a0dbe26a4 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -93,9 +93,9 @@ namespace llvm {
MachineFunctionPass *createResetMachineFunctionPass(bool EmitFallbackDiag,
bool AbortOnFailedISel);
- /// createCodeGenPreparePass - Transform the code to expose more pattern
+ /// createCodeGenPrepareLegacyPass - Transform the code to expose more pattern
/// matching during instruction selection.
- FunctionPass *createCodeGenPreparePass();
+ FunctionPass *createCodeGenPrepareLegacyPass();
/// This pass implements generation of target-specific intrinsics to support
/// handling of complex number arithmetic
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 46b1e95c3c15f3..3db639a6872407 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -54,7 +54,7 @@ void initializeAssignmentTrackingAnalysisPass(PassRegistry &);
void initializeAssumptionCacheTrackerPass(PassRegistry&);
void initializeAtomicExpandPass(PassRegistry&);
void initializeBasicBlockPathCloningPass(PassRegistry &);
-void initializeBasicBlockSectionsProfileReaderPass(PassRegistry &);
+void initializeBasicBlockSectionsProfileReaderWrapperPassPass(PassRegistry &);
void initializeBasicBlockSectionsPass(PassRegistry &);
void initializeBarrierNoopPass(PassRegistry&);
void initializeBasicAAWrapperPassPass(PassRegistry&);
@@ -75,7 +75,7 @@ void initializeCallGraphDOTPrinterPass(PassRegistry&);
void initializeCallGraphViewerPass(PassRegistry&);
void initializeCallGraphWrapperPassPass(PassRegistry&);
void initializeCheckDebugMachineModulePass(PassRegistry &);
-void initializeCodeGenPreparePass(PassRegistry&);
+void initializeCodeGenPrepareLegacyPassPass(PassRegistry &);
void initializeComplexDeinterleavingLegacyPassPass(PassRegistry&);
void initializeConstantHoistingLegacyPassPass(PassRegistry&);
void initializeCycleInfoWrapperPassPass(PassRegistry &);
diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h
index 7a21876e565a7c..fe7fedad18bc0e 100644
--- a/llvm/include/llvm/LinkAllPasses.h
+++ b/llvm/include/llvm/LinkAllPasses.h
@@ -113,7 +113,7 @@ namespace {
(void) llvm::createTailCallEliminationPass();
(void)llvm::createTLSVariableHoistPass();
(void) llvm::createConstantHoistingPass();
- (void) llvm::createCodeGenPreparePass();
+ (void)llvm::createCodeGenPrepareLegacyPass();
(void) llvm::createEarlyCSEPass();
(void) llvm::createGVNPass();
(void) llvm::createPostDomTree();
diff --git a/llvm/lib/CodeGen/BasicBlockPathCloning.cpp b/llvm/lib/CodeGen/BasicBlockPathCloning.cpp
index 5d5f3c3da48160..901542e8507bdf 100644
--- a/llvm/lib/CodeGen/BasicBlockPathCloning.cpp
+++ b/llvm/lib/CodeGen/BasicBlockPathCloning.cpp
@@ -196,7 +196,7 @@ class BasicBlockPathCloning : public MachineFunctionPass {
public:
static char ID;
- BasicBlockSectionsProfileReader *BBSectionsProfileReader = nullptr;
+ BasicBlockSectionsProfileReaderWrapperPass *BBSectionsProfileReader = nullptr;
BasicBlockPathCloning() : MachineFunctionPass(ID) {
initializeBasicBlockPathCloningPass(*PassRegistry::getPassRegistry());
@@ -218,7 +218,7 @@ INITIALIZE_PASS_BEGIN(
BasicBlockPathCloning, "bb-path-cloning",
"Applies path clonings for the -basic-block-sections=list option", false,
false)
-INITIALIZE_PASS_DEPENDENCY(BasicBlockSectionsProfileReader)
+INITIALIZE_PASS_DEPENDENCY(BasicBlockSectionsProfileReaderWrapperPass)
INITIALIZE_PASS_END(
BasicBlockPathCloning, "bb-path-cloning",
"Applies path clonings for the -basic-block-sections=list option", false,
@@ -230,13 +230,14 @@ bool BasicBlockPathCloning::runOnMachineFunction(MachineFunction &MF) {
if (hasInstrProfHashMismatch(MF))
return false;
- return ApplyCloning(MF, getAnalysis<BasicBlockSectionsProfileReader>()
- .getClonePathsForFunction(MF.getName()));
+ return ApplyCloning(MF,
+ getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
+ .getClonePathsForFunction(MF.getName()));
}
void BasicBlockPathCloning::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
- AU.addRequired<BasicBlockSectionsProfileReader>();
+ AU.addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}
diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp
index 42997d2287d61d..94b5a503fbd0f3 100644
--- a/llvm/lib/CodeGen/BasicBlockSections.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -103,7 +103,7 @@ class BasicBlockSections : public MachineFunctionPass {
public:
static char ID;
- BasicBlockSectionsProfileReader *BBSectionsProfileReader = nullptr;
+ BasicBlockSectionsProfileReaderWrapperPass *BBSectionsProfileReader = nullptr;
BasicBlockSections() : MachineFunctionPass(ID) {
initializeBasicBlockSectionsPass(*PassRegistry::getPassRegistry());
@@ -128,7 +128,7 @@ INITIALIZE_PASS_BEGIN(
"Prepares for basic block sections, by splitting functions "
"into clusters of basic blocks.",
false, false)
-INITIALIZE_PASS_DEPENDENCY(BasicBlockSectionsProfileReader)
+INITIALIZE_PASS_DEPENDENCY(BasicBlockSectionsProfileReaderWrapperPass)
INITIALIZE_PASS_END(BasicBlockSections, "bbsections-prepare",
"Prepares for basic block sections, by splitting functions "
"into clusters of basic blocks.",
@@ -306,7 +306,7 @@ bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
DenseMap<UniqueBBID, BBClusterInfo> FuncClusterInfo;
if (BBSectionsType == BasicBlockSection::List) {
auto [HasProfile, ClusterInfo] =
- getAnalysis<BasicBlockSectionsProfileReader>()
+ getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
.getClusterInfoForFunction(MF.getName());
if (!HasProfile)
return false;
@@ -362,7 +362,7 @@ bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
void BasicBlockSections::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
- AU.addRequired<BasicBlockSectionsProfileReader>();
+ AU.addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 15b6f63e86327a..79e42d9304dfe3 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -30,8 +30,9 @@
using namespace llvm;
-char BasicBlockSectionsProfileReader::ID = 0;
-INITIALIZE_PASS(BasicBlockSectionsProfileReader, "bbsections-profile-reader",
+char BasicBlockSectionsProfileReaderWrapperPass::ID = 0;
+INITIALIZE_PASS(BasicBlockSectionsProfileReaderWrapperPass,
+ "bbsections-profile-reader",
"Reads and parses a basic block sections profile.", false,
false)
@@ -395,11 +396,11 @@ Error BasicBlockSectionsProfileReader::ReadProfile() {
}
}
-bool BasicBlockSectionsProfileReader::doInitialization(Module &M) {
- if (!MBuf)
+bool BasicBlockSectionsProfileReaderWrapperPass::doInitialization(Module &M) {
+ if (!BBSPR.MBuf)
return false;
// Get the function name to debug info filename mapping.
- FunctionNameToDIFilename.clear();
+ BBSPR.FunctionNameToDIFilename.clear();
for (const Function &F : M) {
SmallString<128> DIFilename;
if (F.isDeclaration())
@@ -411,15 +412,46 @@ bool BasicBlockSectionsProfileReader::doInitialization(Module &M) {
DIFilename = sys::path::remove_leading_dotslash(CU->getFilename());
}
[[maybe_unused]] bool inserted =
- FunctionNameToDIFilename.try_emplace(F.getName(), DIFilename).second;
+ BBSPR.FunctionNameToDIFilename.try_emplace(F.getName(), DIFilename)
+ .second;
assert(inserted);
}
- if (auto Err = ReadProfile())
+ if (auto Err = BBSPR.ReadProfile())
report_fatal_error(std::move(Err));
return false;
}
-ImmutablePass *
-llvm::createBasicBlockSectionsProfileReaderPass(const MemoryBuffer *Buf) {
- return new BasicBlockSectionsProfileReader(Buf);
+AnalysisKey BasicBlockSectionsProfileReaderAnalysis::Key;
+
+BasicBlockSectionsProfileReader
+BasicBlockSectionsProfileReaderAnalysis::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ return BasicBlockSectionsProfileReader(TM->getBBSectionsFuncListBuf());
+}
+
+bool BasicBlockSectionsProfileReaderWrapperPass::isFunctionHot(
+ StringRef FuncName) const {
+ return BBSPR.isFunctionHot(FuncName);
+}
+
+std::pair<bool, SmallVector<BBClusterInfo>>
+BasicBlockSectionsProfileReaderWrapperPass::getClusterInfoForFunction(
+ StringRef FuncName) const {
+ return BBSPR.getClusterInfoForFunction(FuncName);
+}
+
+SmallVector<SmallVector<unsigned>>
+BasicBlockSectionsProfileReaderWrapperPass::getClonePathsForFunction(
+ StringRef FuncName) const {
+ return BBSPR.getClonePathsForFunction(FuncName);
+}
+
+BasicBlockSectionsProfileReader &
+BasicBlockSectionsProfileReaderWrapperPass::getBBSPR() {
+ return BBSPR;
+}
+
+ImmutablePass *llvm::createBasicBlockSectionsProfileReaderWrapperPass(
+ const MemoryBuffer *Buf) {
+ return new BasicBlockSectionsProfileReaderWrapperPass(Buf);
}
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 7b73a7b11ddf1c..418066452c1724 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -30,7 +30,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeCFIFixupPass(Registry);
initializeCFIInstrInserterPass(Registry);
initializeCheckDebugMachineModulePass(Registry);
- initializeCodeGenPreparePass(Registry);
+ initializeCodeGenPrepareLegacyPassPass(Registry);
initializeDeadMachineInstructionElimPass(Registry);
initializeDebugifyMachineModulePass(Registry);
initializeDetectDeadLanesPass(Registry);
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 5bd4c6b067d796..b8bfb9742bfbe9 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"
@@ -301,7 +302,8 @@ using ValueToSExts = MapVector<Value *, SExts>;
class TypePromotionTransaction;
-class CodeGenPrepare : public FunctionPass {
+class CodeGenPrepare {
+ friend class CodeGenPrepareLegacyPass;
const TargetMachine *TM = nullptr;
const TargetSubtargetInfo *SubtargetInfo = nullptr;
const TargetLowering *TLI = nullptr;
@@ -365,6 +367,8 @@ class CodeGenPrepare : public FunctionPass {
std::unique_ptr<DominatorTree> DT;
public:
+ CodeGenPrepare(){};
+ CodeGenPrepare(const TargetMachine *TM) : TM(TM){};
/// If encounter huge function, we need to limit the build time.
bool IsHugeFunc = false;
@@ -374,15 +378,7 @@ class CodeGenPrepare : public FunctionPass {
/// to insert such BB into FreshBBs for huge function.
SmallSet<BasicBlock *, 32> FreshBBs;
- static char ID; // Pass identification, replacement for typeid
-
- CodeGenPrepare() : FunctionPass(ID) {
- initializeCodeGenPreparePass(*PassRegistry::getPassRegistry());
- }
-
- bool runOnFunction(Function &F) override;
-
- void releaseMemory() override {
+ void releaseMemory() {
// Clear per function information.
InsertedInsts.clear();
PromotedInsts.clear();
@@ -391,17 +387,7 @@ class CodeGenPrepare : public FunctionPass {
BFI.reset();
}
- StringRef getPassName() const override { return "CodeGen Prepare"; }
-
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- // 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>();
- }
+ bool run(Function &F, FunctionAnalysisManager &AM);
private:
template <typename F>
@@ -488,45 +474,108 @@ class CodeGenPrepare : public FunctionPass {
bool combineToUSubWithOverflow(CmpInst *Cmp, ModifyDT &ModifiedDT);
bool combineToUAddWithOverflow(CmpInst *Cmp, ModifyDT &ModifiedDT);
void verifyBFIUpdates(Function &F);
+ bool _run(Function &F);
+};
+
+class CodeGenPrepareLegacyPass : public FunctionPass {
+public:
+ static char ID; // Pass identification, replacement for typeid
+
+ CodeGenPrepareLegacyPass() : FunctionPass(ID) {
+ initializeCodeGenPrepareLegacyPassPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnFunction(Function &F) override;
+
+ StringRef getPassName() const override { return "CodeGen Prepare"; }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ // 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<BasicBlockSectionsProfileReaderWrapperPass>();
+ }
};
} // end anonymous namespace
-char CodeGenPrepare::ID = 0;
+char CodeGenPrepareLegacyPass::ID = 0;
-INITIALIZE_PASS_BEGIN(CodeGenPrepare, DEBUG_TYPE,
+bool CodeGenPrepareLegacyPass::runOnFunction(Function &F) {
+ if (skipFunction(F))
+ return false;
+ auto TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
+ CodeGenPrepare CGP(TM);
+ CGP.DL = &F.getParent()->getDataLayout();
+ CGP.SubtargetInfo = TM->getSubtargetImpl(F);
+ CGP.TLI = CGP.SubtargetInfo->getTargetLowering();
+ CGP.TRI = CGP.SubtargetInfo->getRegisterInfo();
+ CGP.TLInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
+ CGP.TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
+ CGP.LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+ CGP.BPI.reset(new BranchProbabilityInfo(F, *CGP.LI));
+ CGP.BFI.reset(new BlockFrequencyInfo(F, *CGP.BPI, *CGP.LI));
+ CGP.PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
+ auto BBSPRW...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/77182
More information about the llvm-commits
mailing list