[llvm] [NewPM][CodeGen][llc] Add NPM support (PR #70922)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 3 03:41:39 PDT 2023
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/70922
>From 0de8431f96138a6b31ee2a654cf940791ed6cc38 Mon Sep 17 00:00:00 2001
From: Yuanfang Chen <455423+yuanfang-chen at users.noreply.github.com>
Date: Wed, 1 Nov 2023 10:48:45 +0800
Subject: [PATCH 1/4] [NewPM][CodeGen] Add NPM support to llc
---
.../Generic/llc-start-stop-instance-errors.ll | 2 +
.../CodeGen/Generic/new-pm/llc-start-stop.ll | 47 ++++
llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll | 116 ++++++++
.../X86/new-pm/llc-start-stop-instance.ll | 35 +++
llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll | 243 ++++++++++++++++
llvm/tools/llc/CMakeLists.txt | 3 +
llvm/tools/llc/NewPMDriver.cpp | 264 ++++++++++++++++++
llvm/tools/llc/NewPMDriver.h | 49 ++++
llvm/tools/llc/llc.cpp | 90 +++---
9 files changed, 793 insertions(+), 56 deletions(-)
create mode 100644 llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll
create mode 100644 llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll
create mode 100644 llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll
create mode 100644 llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll
create mode 100644 llvm/tools/llc/NewPMDriver.cpp
create mode 100644 llvm/tools/llc/NewPMDriver.h
diff --git a/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll b/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
index 76cc8b681b6a785..8cad70b5d9ede10 100644
--- a/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
+++ b/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
@@ -1,4 +1,6 @@
; RUN: not --crash llc -debug-pass=Structure -stop-after=dead-mi-elimination,arst %s -o /dev/null 2>&1 \
; RUN: | FileCheck -check-prefix=NOT-NUM %s
+; RUN: not --crash llc -enable-new-pm -debug-pass-manager -stop-after=dead-mi-elimination,arst %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=NOT-NUM %s
; NOT-NUM: LLVM ERROR: invalid pass instance specifier dead-mi-elimination,arst
diff --git a/llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll b/llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll
new file mode 100644
index 000000000000000..5245563763d81bf
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll
@@ -0,0 +1,47 @@
+; RUN: llc < %s -enable-new-pm -debug-pass-manager -stop-after=verify \
+; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-AFTER
+; STOP-AFTER: Running pass: VerifierPass
+; STOP-AFTER-NEXT: Running analysis: VerifierAnalysis
+; STOP-AFTER-NEXT: Skipping pass:
+
+; RUN: llc < %s -enable-new-pm -debug-pass-manager -stop-before=verify \
+; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-BEFORE
+; STOP-BEFORE: Running pass: AtomicExpandPass
+; STOP-BEFORE-NEXT: Skipping pass:
+
+; RUN: llc < %s -enable-new-pm -debug-pass-manager -start-after=verify \
+; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=START-AFTER
+; START-AFTER: Skipping pass: VerifierPass
+; START-AFTER-NEXT: Running pass:
+
+; RUN: llc < %s -enable-new-pm -debug-pass-manager -start-before=verify \
+; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=START-BEFORE
+; START-BEFORE-NOT: Running pass:
+; START-BEFORE: Running pass: VerifierPass
+
+; RUN: not --crash llc < %s -enable-new-pm -start-before=nonexistent -o /dev/null 2>&1 \
+; RUN: | FileCheck %s -check-prefix=NONEXISTENT-START-BEFORE
+; RUN: not --crash llc < %s -enable-new-pm -stop-before=nonexistent -o /dev/null 2>&1 \
+; RUN: | FileCheck %s -check-prefix=NONEXISTENT-STOP-BEFORE
+; RUN: not --crash llc < %s -enable-new-pm -start-after=nonexistent -o /dev/null 2>&1 \
+; RUN: | FileCheck %s -check-prefix=NONEXISTENT-START-AFTER
+; RUN: not --crash llc < %s -enable-new-pm -stop-after=nonexistent -o /dev/null 2>&1 \
+; RUN: | FileCheck %s -check-prefix=NONEXISTENT-STOP-AFTER
+; NONEXISTENT-START-BEFORE: "nonexistent" pass could not be found.
+; NONEXISTENT-STOP-BEFORE: "nonexistent" pass could not be found.
+; NONEXISTENT-START-AFTER: "nonexistent" pass could not be found.
+; NONEXISTENT-STOP-AFTER: "nonexistent" pass could not be found.
+
+; RUN: not --crash llc < %s -enable-new-pm -start-before=verify -start-after=verify \
+; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=DOUBLE-START
+; RUN: not --crash llc < %s -enable-new-pm -stop-before=verify -stop-after=verify \
+; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=DOUBLE-STOP
+; DOUBLE-START: start-before and start-after specified!
+; DOUBLE-STOP: stop-before and stop-after specified!
+
+define void @f() {
+ br label %b
+b:
+ br label %b
+ ret void
+}
diff --git a/llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll b/llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll
new file mode 100644
index 000000000000000..d2b3d333ba27266
--- /dev/null
+++ b/llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll
@@ -0,0 +1,116 @@
+; When EXPENSIVE_CHECKS are enabled, the machine verifier appears between each
+; pass. Ignore it with 'grep -v'.
+; RUN: llc -mtriple=x86_64-- -O0 -debug-pass-manager -enable-new-pm < %s \
+; RUN: -o /dev/null 2>&1 | grep -v 'Verify generated machine code' | FileCheck %s
+
+; REQUIRES: asserts
+
+; CHECK-LABEL: Running pass: PreISelIntrinsicLoweringPass on [module]
+; CHECK-NEXT: Running analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
+; CHECK-NEXT: Running pass: ExpandLargeDivRemPass on f (1 instruction)
+; CHECK-NEXT: Running pass: ExpandLargeFpConvertPass on f (1 instruction)
+; CHECK-NEXT: Running pass: AtomicExpandPass on f (1 instruction)
+; CHECK-NEXT: Running pass: VerifierPass on f (1 instruction)
+; CHECK-NEXT: Running analysis: VerifierAnalysis on f
+; CHECK-NEXT: Running pass: GCLoweringPass on f (1 instruction)
+; CHECK-NEXT: Running pass: ShadowStackGCLoweringPass on f (1 instruction)
+; CHECK-NEXT: Running pass: LowerConstantIntrinsicsPass on f (1 instruction)
+; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on f
+; CHECK-NEXT: Running pass: UnreachableBlockElimPass on f (1 instruction)
+; CHECK-NEXT: Running pass: ExpandVectorPredicationPass on f (1 instruction)
+; CHECK-NEXT: Running analysis: TargetIRAnalysis on f
+; CHECK-NEXT: Running pass: ScalarizeMaskedMemIntrinPass on f (1 instruction)
+; CHECK-NEXT: Running pass: ExpandReductionsPass on f (1 instruction)
+; CHECK-NEXT: Running pass: IndirectBrExpandPass on f (1 instruction)
+; CHECK-NEXT: Running pass: DwarfEHPass on f (1 instruction)
+; CHECK-NEXT: Running pass: CallBrPrepare on f (1 instruction)
+; CHECK-NEXT: Running pass: SafeStackPass on f (1 instruction)
+; CHECK-NEXT: Running pass: StackProtectorPass on f (1 instruction)
+; CHECK-NEXT: Running pass: VerifierPass on f (1 instruction)
+; CHECK-NEXT: Running analysis: MachineModuleAnalysis on [module]
+; CHECK-NEXT: Running pass: {{.*}}::X86ISelDagPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86GlobalBaseRegPass on f
+; CHECK-NEXT: Running pass: FinalizeISelPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: LocalStackSlotPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeLoadHardeningPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FlagsCopyLoweringDummyPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86DynAllocaExpanderPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FastPreTileConfigPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PHIEliminationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: TwoAddressInstructionPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: RegAllocPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FastTileConfigPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86LowerTileCopyPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FloatingPointStackifierPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: RemoveRedundantDebugValuesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: FixupStatepointCallerSavedPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PrologEpilogInserterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: ExpandPostRAPseudosPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86ExpandPseudoPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: KCFIPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: FEntryInserterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: XRayInstrumentationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PatchableFunctionPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86IndirectBranchTrackingPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86IssueVZeroUpperPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86EvexToVexInstsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86DiscriminateMemOpsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86InsertPrefetchPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86InsertX87waitPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: FuncletLayoutPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: StackMapLivenessPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: LiveDebugValuesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineSanitizerBinaryMetadata on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: StackFrameLayoutAnalysisPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeExecutionSideEffectSuppressionPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86IndirectThunksPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86ReturnThunksPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: CFIInstrInserterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86LoadValueInjectionRetHardeningPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PseudoProbeInserterPass on [module]
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: UnpackMachineBundlesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86AsmPrinterPass on f
+; CHECK-NEXT: Running pass: FreeMachineFunctionPass on f
+
+define void @f() {
+ ret void
+}
diff --git a/llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll b/llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll
new file mode 100644
index 000000000000000..a6d5cf2fd8aff58
--- /dev/null
+++ b/llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll
@@ -0,0 +1,35 @@
+; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -stop-after=verify,1 \
+; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=STOP-AFTER-1 %s
+
+; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -stop-after=verify,0 \
+; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=STOP-AFTER-0 %s
+
+; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -stop-before=verify,1 \
+; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=STOP-BEFORE-1 %s
+
+; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -start-before=verify,1 \
+; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=START-BEFORE-1 %s
+
+; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -start-after=verify,1 \
+; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=START-AFTER-1 %s
+
+
+; STOP-AFTER-1: Running pass: VerifierPass
+; STOP-AFTER-1: Running pass: VerifierPass
+
+; STOP-AFTER-0-NOT: Running pass: VerifierPass
+; STOP-AFTER-0: Running pass: VerifierPass
+; STOP-AFTER-0-NOT: Running pass: VerifierPass
+
+; STOP-BEFORE-1: Running pass: VerifierPass
+; STOP-BEFORE-1-NOT: Running pass: VerifierPass
+
+; START-BEFORE-1-NOT: Running pass: VerifierPass
+; START-BEFORE-1: Running pass: VerifierPass
+; START-BEFORE-1-NOT: Running pass: VerifierPass
+
+; START-AFTER-1-NOT: Running pass: VerifierPass
+
+define void @f() {
+ ret void
+}
diff --git a/llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll b/llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll
new file mode 100644
index 000000000000000..73b074a5e67f967
--- /dev/null
+++ b/llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll
@@ -0,0 +1,243 @@
+; When EXPENSIVE_CHECKS are enabled, the machine verifier appears between each
+; pass. Ignore it with 'grep -v'.
+; RUN: llc -mtriple=x86_64-- -O1 -debug-pass-manager -enable-new-pm < %s \
+; RUN: -o /dev/null 2>&1 | FileCheck %s
+; RUN: llc -mtriple=x86_64-- -O2 -debug-pass-manager -enable-new-pm < %s \
+; RUN: -o /dev/null 2>&1 | FileCheck %s
+; RUN: llc -mtriple=x86_64-- -O3 -debug-pass-manager -enable-new-pm < %s \
+; RUN: -o /dev/null 2>&1 | FileCheck %s
+
+; REQUIRES: asserts
+
+; CHECK-LABEL: Running pass: PreISelIntrinsicLoweringPass on [module]
+; CHECK-NEXT: Running analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
+; CHECK-NEXT: Running pass: ExpandLargeDivRemPass on f (3 instructions)
+; CHECK-NEXT: Running pass: ExpandLargeFpConvertPass on f (3 instructions)
+; CHECK-NEXT: Running pass: AtomicExpandPass on f (3 instructions)
+; CHECK-NEXT: Running pass: VerifierPass on f (3 instructions)
+; CHECK-NEXT: Running analysis: VerifierAnalysis on f
+; CHECK-NEXT: Running pass: LoopSimplifyPass on f (3 instructions)
+; CHECK-NEXT: Running analysis: LoopAnalysis on f
+; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on f
+; CHECK-NEXT: Running analysis: AssumptionAnalysis on f
+; CHECK-NEXT: Running analysis: TargetIRAnalysis on f
+; CHECK-NEXT: Running pass: LCSSAPass on f (3 instructions)
+; CHECK-NEXT: Running analysis: MemorySSAAnalysis on f
+; CHECK-NEXT: Running analysis: AAManager on f
+; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on f
+; CHECK-NEXT: Running analysis: BasicAA on f
+; CHECK-NEXT: Running analysis: ScopedNoAliasAA on f
+; CHECK-NEXT: Running analysis: TypeBasedAA on f
+; CHECK-NEXT: Running analysis: {{.*OuterAnalysisManagerProxy.*|UNKNOWN_TYPE}}
+; CHECK-NEXT: Running analysis: ScalarEvolutionAnalysis on f
+; CHECK-NEXT: Running analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
+; CHECK-NEXT: Running pass: CanonicalizeFreezeInLoopsPass on b
+; CHECK-NEXT: Running pass: LoopSimplifyPass on f (3 instructions)
+; CHECK-NEXT: Running pass: LCSSAPass on f (3 instructions)
+; CHECK-NEXT: Running pass: LoopStrengthReducePass on b
+; CHECK-NEXT: Running analysis: IVUsersAnalysis on b
+; CHECK-NEXT: Running pass: MergeICmpsPass on f (3 instructions)
+; CHECK-NEXT: Running pass: ExpandMemCmpPass on f (3 instructions)
+; CHECK-NEXT: Running pass: GCLoweringPass on f (3 instructions)
+; CHECK-NEXT: Running pass: ShadowStackGCLoweringPass on f (3 instructions)
+; CHECK-NEXT: Running pass: LowerConstantIntrinsicsPass on f (3 instructions)
+; CHECK-NEXT: Running pass: UnreachableBlockElimPass on f (3 instructions)
+; CHECK-NEXT: Clearing all analysis results for: <possibly invalidated loop>
+; CHECK-NEXT: Invalidating analysis: VerifierAnalysis on f
+; CHECK-NEXT: Invalidating analysis: LoopAnalysis on f
+; CHECK-NEXT: Invalidating analysis: MemorySSAAnalysis on f
+; CHECK-NEXT: Invalidating analysis: ScalarEvolutionAnalysis on f
+; CHECK-NEXT: Invalidating analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
+; CHECK-NEXT: Running pass: ConstantHoistingPass on f (2 instructions)
+; CHECK-NEXT: Running analysis: BlockFrequencyAnalysis on f
+; CHECK-NEXT: Running analysis: BranchProbabilityAnalysis on f
+; CHECK-NEXT: Running analysis: LoopAnalysis on f
+; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on f
+; CHECK-NEXT: Running pass: ReplaceWithVeclib on f (2 instructions)
+; CHECK-NEXT: Running pass: PartiallyInlineLibCallsPass on f (2 instructions)
+; CHECK-NEXT: Running pass: ExpandVectorPredicationPass on f (2 instructions)
+; CHECK-NEXT: Running pass: ScalarizeMaskedMemIntrinPass on f (2 instructions)
+; CHECK-NEXT: Running pass: ExpandReductionsPass on f (2 instructions)
+; CHECK-NEXT: Running pass: TLSVariableHoistPass on f (2 instructions)
+; CHECK-NEXT: Running pass: InterleavedAccessPass on f (2 instructions)
+; CHECK-NEXT: Running pass: IndirectBrExpandPass on f (2 instructions)
+; CHECK-NEXT: Running pass: CodeGenPreparePass on f (2 instructions)
+; CHECK-NEXT: Running pass: DwarfEHPass on f (2 instructions)
+; CHECK-NEXT: Running pass: CallBrPrepare on f (2 instructions)
+; CHECK-NEXT: Running pass: SafeStackPass on f (2 instructions)
+; CHECK-NEXT: Running pass: StackProtectorPass on f (2 instructions)
+; CHECK-NEXT: Running pass: VerifierPass on f (2 instructions)
+; CHECK-NEXT: Running analysis: VerifierAnalysis on f
+; CHECK-NEXT: Running analysis: MachineModuleAnalysis on [module]
+; CHECK-NEXT: Running pass: {{.*}}::X86ISelDagPass on f
+; CHECK-NEXT: Running pass: {{.*}}::CleanupLocalDynamicTLSPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86GlobalBaseRegPass on f
+; CHECK-NEXT: Running pass: FinalizeISelPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86DomainReassignmentPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: EarlyTailDuplicatePass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: OptimizePHIsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: StackColoringPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: LocalStackSlotPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: DeadMachineInstructionElimPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: EarlyIfConverterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineCombinerPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86CmovConverterDummyPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: EarlyMachineLICMPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineCSEPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineSinkingPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PeepholeOptimizerPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: DeadMachineInstructionElimPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: LiveRangeShrinkPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FixupSetCCPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86OptimizeLEAsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86CallFrameOptimizationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86AvoidStoreForwardingBlocksPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeLoadHardeningPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FlagsCopyLoweringDummyPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86DynAllocaExpanderPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86PreTileConfigPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: DetectDeadLanesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: ProcessImplicitDefsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PHIEliminationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: TwoAddressInstructionPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: RegisterCoalescerPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: RenameIndependentSubregsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineSchedulerPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: RegAllocPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FastTileConfigPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineCopyPropagationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineLICMPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86LowerTileCopyPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FloatingPointStackifierPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86LoadValueInjectionRetHardeningPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: RemoveRedundantDebugValuesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: FixupStatepointCallerSavedPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PostRAMachineSinkingPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: ShrinkWrapPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PrologEpilogInserterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: BranchFolderPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: TailDuplicatePass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineLateInstrsCleanupPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineCopyPropagationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: ExpandPostRAPseudosPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86ExpandPseudoPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: KCFIPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PostRASchedulerPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineBlockPlacementPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: FEntryInserterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: XRayInstrumentationPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PatchableFunctionPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86ExecutionDomainFixPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: BreakFalseDepsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86IndirectBranchTrackingPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86IssueVZeroUpperPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FixupBWInstsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86PadShortFunctionsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FixupLEAsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FixupInstTuningPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86FixupVectorConstantsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86EvexToVexInstsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86DiscriminateMemOpsPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86InsertPrefetchPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86InsertX87waitPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: FuncletLayoutPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: StackMapLivenessPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: LiveDebugValuesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: MachineSanitizerBinaryMetadata on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: StackFrameLayoutAnalysisPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeExecutionSideEffectSuppressionPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86IndirectThunksPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86ReturnThunksPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: CFIInstrInserterPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86LoadValueInjectionRetHardeningPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: PseudoProbeInserterPass on [module]
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: UnpackMachineBundlesPass on f
+; CHECK-NEXT: Running pass: MachineVerifierPass on f
+; CHECK-NEXT: Running pass: {{.*}}::X86AsmPrinterPass on f
+; CHECK-NEXT: Running pass: FreeMachineFunctionPass on f
+
+define void @f() {
+ br label %b
+b:
+ br label %b
+ ret void
+}
diff --git a/llvm/tools/llc/CMakeLists.txt b/llvm/tools/llc/CMakeLists.txt
index 257d5b519f0406f..01825c6e4c64c77 100644
--- a/llvm/tools/llc/CMakeLists.txt
+++ b/llvm/tools/llc/CMakeLists.txt
@@ -8,9 +8,11 @@ set(LLVM_LINK_COMPONENTS
CodeGen
CodeGenTypes
Core
+ IRPrinter
IRReader
MC
MIRParser
+ Passes
Remarks
ScalarOpts
SelectionDAG
@@ -23,6 +25,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(llc
llc.cpp
+ NewPMDriver.cpp
DEPENDS
intrinsics_gen
diff --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
new file mode 100644
index 000000000000000..83e8c60ade93f71
--- /dev/null
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -0,0 +1,264 @@
+//===- NewPMDriver.cpp - Driver for llc using new PM ----------------------===//
+//
+// 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
+///
+/// This file is just a split of the code that logically belongs in llc.cpp but
+/// that includes the new pass manager headers.
+///
+//===----------------------------------------------------------------------===//
+
+#include "NewPMDriver.h"
+#include "llvm/Analysis/CGSCCPassManager.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/CodeGen/CodeGenPassBuilder.h"
+#include "llvm/CodeGen/CommandFlags.h"
+#include "llvm/CodeGen/MIRParser/MIRParser.h"
+#include "llvm/CodeGen/MIRPrinter.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/IR/IRPrintingPasses.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Verifier.h"
+#include "llvm/IRReader/IRReader.h"
+#include "llvm/Passes/PassBuilder.h"
+#include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/WithColor.h"
+#include "llvm/Target/CGPassBuilderOption.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
+#include "llvm/Transforms/Scalar/LoopPassManager.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+
+using namespace llvm;
+
+static cl::opt<RegAllocType> RegAlloc(
+ "regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
+ cl::Hidden, cl::ValueOptional, cl::init(RegAllocType::Default),
+ cl::values(
+ clEnumValN(RegAllocType::Default, "default",
+ "pick register allocator based on -O option"),
+ clEnumValN(RegAllocType::Basic, "basic", "basic register allocator"),
+ clEnumValN(RegAllocType::Fast, "fast", "fast register allocator"),
+ clEnumValN(RegAllocType::Greedy, "greedy", "greedy register allocator"),
+ clEnumValN(RegAllocType::PBQP, "pbqp", "PBQP register allocator")));
+
+static cl::opt<bool>
+ DebugPM("debug-pass-manager", cl::Hidden,
+ cl::desc("Print pass management debugging information"));
+
+bool LLCDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) {
+ if (DI.getKind() == llvm::DK_SrcMgr) {
+ const auto &DISM = cast<DiagnosticInfoSrcMgr>(DI);
+ const SMDiagnostic &SMD = DISM.getSMDiag();
+
+ if (SMD.getKind() == SourceMgr::DK_Error)
+ *HasError = true;
+
+ SMD.print(nullptr, errs());
+
+ // For testing purposes, we print the LocCookie here.
+ if (DISM.isInlineAsmDiag() && DISM.getLocCookie())
+ WithColor::note() << "!srcloc = " << DISM.getLocCookie() << "\n";
+
+ return true;
+ }
+
+ if (DI.getSeverity() == DS_Error)
+ *HasError = true;
+
+ if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
+ if (!Remark->isEnabled())
+ return true;
+
+ DiagnosticPrinterRawOStream DP(errs());
+ errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
+ DI.print(DP);
+ errs() << "\n";
+ return true;
+}
+
+static llvm::ExitOnError ExitOnErr;
+
+static void RunPasses(bool CompileTwice, bool BOS, ToolOutputFile *Out,
+ Module *M, LLVMContext &Context,
+ SmallVector<char, 0> &Buffer, ModulePassManager *MPM,
+ ModuleAnalysisManager *MAM,
+ MachineFunctionPassManager &MFPM,
+ MachineFunctionAnalysisManager &MFAM) {
+ auto RunPM = [=, &MFPM, &MFAM]() {
+ if (MPM) {
+ assert(MAM);
+ MPM->run(*M, *MAM);
+ }
+
+ ExitOnErr(MFPM.run(*M, MFAM));
+ };
+
+ assert(M && "invalid input module!");
+
+ // Before executing passes, print the final values of the LLVM options.
+ cl::PrintOptionValues();
+
+ // If requested, run the pass manager over the same module again,
+ // to catch any bugs due to persistent state in the passes. Note that
+ // opt has the same functionality, so it may be worth abstracting this out
+ // in the future.
+ SmallVector<char, 0> CompileTwiceBuffer;
+ if (CompileTwice) {
+ std::unique_ptr<Module> M2(llvm::CloneModule(*M));
+ RunPM();
+ CompileTwiceBuffer = Buffer;
+ Buffer.clear();
+ }
+
+ RunPM();
+
+ auto HasError =
+ ((const LLCDiagnosticHandler *)(Context.getDiagHandlerPtr()))->HasError;
+ if (*HasError)
+ exit(1);
+
+ // Compare the two outputs and make sure they're the same
+ if (CompileTwice) {
+ if (Buffer.size() != CompileTwiceBuffer.size() ||
+ (memcmp(Buffer.data(), CompileTwiceBuffer.data(), Buffer.size()) !=
+ 0)) {
+ errs() << "Running the pass manager twice changed the output.\n"
+ "Writing the result of the second run to the specified output\n"
+ "To generate the one-run comparison binary, just run without\n"
+ "the compile-twice option\n";
+ Out->os() << Buffer;
+ Out->keep();
+ exit(1);
+ }
+ }
+
+ if (BOS)
+ Out->os() << Buffer;
+}
+
+int llvm::compileModuleWithNewPM(
+ StringRef Arg0, std::unique_ptr<Module> M, std::unique_ptr<MIRParser> MIR,
+ std::unique_ptr<TargetMachine> Target, std::unique_ptr<ToolOutputFile> Out,
+ std::unique_ptr<ToolOutputFile> DwoOut, LLVMContext &Context,
+ const TargetLibraryInfoImpl &TLII, bool NoVerify, bool CompileTwice,
+ const std::vector<std::string> &RunPassNames, CodeGenFileType FileType) {
+
+ if (!RunPassNames.empty() && TargetPassConfig::hasLimitedCodeGenPipeline()) {
+ WithColor::warning(errs(), Arg0)
+ << "run-pass cannot be used with "
+ << TargetPassConfig::getLimitedCodeGenPipelineReason(" and ") << ".\n";
+ return 1;
+ }
+
+ LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine &>(*Target);
+
+ {
+ raw_pwrite_stream *OS = &Out->os();
+
+ // Manually do the buffering rather than using buffer_ostream,
+ // so we can memcmp the contents in CompileTwice mode
+ SmallVector<char, 0> Buffer;
+ std::unique_ptr<raw_svector_ostream> BOS;
+ if ((codegen::getFileType() != CodeGenFileType::AssemblyFile &&
+ !Out->os().supportsSeeking()) ||
+ CompileTwice) {
+ BOS = std::make_unique<raw_svector_ostream>(Buffer);
+ OS = BOS.get();
+ }
+
+ // Fetch options from TargetPassConfig
+ CGPassBuilderOption Opt = getCGPassBuilderOption();
+ Opt.DisableVerify = NoVerify;
+ Opt.DebugPM = DebugPM;
+ Opt.RegAlloc = RegAlloc;
+
+ PassInstrumentationCallbacks PIC;
+ StandardInstrumentations SI(Context, Opt.DebugPM);
+ SI.registerCallbacks(PIC);
+ registerCodeGenCallback(PIC, LLVMTM);
+
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
+ PassBuilder PB(Target.get(), PipelineTuningOptions(), std::nullopt, &PIC);
+ PB.registerModuleAnalyses(MAM);
+ PB.registerCGSCCAnalyses(CGAM);
+ PB.registerFunctionAnalyses(FAM);
+ PB.registerLoopAnalyses(LAM);
+ PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+
+ FAM.registerPass([&] { return TargetLibraryAnalysis(TLII); });
+ MAM.registerPass([&] { return MachineModuleAnalysis(&LLVMTM); });
+
+ MachineFunctionAnalysisManager MFAM(FAM, MAM);
+
+ if (!RunPassNames.empty()) {
+ // Construct a custom pass pipeline that starts after instruction
+ // selection.
+
+ if (!MIR) {
+ WithColor::warning(errs(), Arg0) << "run-pass is for .mir file only.\n";
+ return 1;
+ }
+
+ MachineFunctionPassManager MFPM;
+ ExitOnErr(LLVMTM.parseMIRPipeline(MFPM, llvm::join(RunPassNames, ","),
+ Opt, MFAM, &PIC));
+ MFPM.addPass(PrintMIRPass(*OS));
+ MFPM.addPass(FreeMachineFunctionPass());
+
+ auto &MMI = MFAM.getResult<MachineModuleAnalysis>(*M);
+ if (MIR->parseMachineFunctions(*M, MMI))
+ return 1;
+
+ RunPasses(CompileTwice, BOS.get(), Out.get(), M.get(), Context, Buffer,
+ nullptr, nullptr, MFPM, MFAM);
+ } else {
+ ModulePassManager MPM;
+ MachineFunctionPassManager MFPM;
+
+ ExitOnErr(LLVMTM.buildCodeGenPipeline(MPM, MFPM, *OS,
+ DwoOut ? &DwoOut->os() : nullptr,
+ FileType, Opt, MFAM, &PIC));
+
+ // Add IR or MIR printing pass according the pass type.
+ if (PIC.isStartStopInfoRegistered()) {
+ auto &Info = PIC.getStartStopInfo();
+ if (!Info.willCompleteCodeGenPipeline()) {
+ if (Info.isStopMachineFunctionPass())
+ MFPM.addPass(PrintMIRPass(*OS));
+ else
+ MPM.addPass(PrintModulePass(*OS));
+ }
+ }
+
+ RunPasses(CompileTwice, BOS.get(), Out.get(), M.get(), Context, Buffer,
+ &MPM, &MAM, MFPM, MFAM);
+ }
+ }
+
+ // Declare success.
+ Out->keep();
+ if (DwoOut)
+ DwoOut->keep();
+
+ return 0;
+}
diff --git a/llvm/tools/llc/NewPMDriver.h b/llvm/tools/llc/NewPMDriver.h
new file mode 100644
index 000000000000000..d8310a996284cab
--- /dev/null
+++ b/llvm/tools/llc/NewPMDriver.h
@@ -0,0 +1,49 @@
+//===- NewPMDriver.h - Function to drive llc with the new PM --------------===//
+//
+// 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
+///
+/// A single function which is called to drive the llc behavior for the new
+/// PassManager.
+///
+/// This is only in a separate TU with a header to avoid including all of the
+/// old pass manager headers and the new pass manager headers into the same
+/// file. Eventually all of the routines here will get folded back into
+/// llc.cpp.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_OPT_NEWPMDRIVER_H
+#define LLVM_TOOLS_OPT_NEWPMDRIVER_H
+
+#include "llvm/IR/DiagnosticHandler.h"
+#include "llvm/Support/CodeGen.h"
+#include <memory>
+#include <vector>
+
+namespace llvm {
+class Module;
+class TargetLibraryInfoImpl;
+class TargetMachine;
+class ToolOutputFile;
+class LLVMContext;
+class MIRParser;
+
+struct LLCDiagnosticHandler : public DiagnosticHandler {
+ bool *HasError;
+ LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
+ bool handleDiagnostics(const DiagnosticInfo &DI) override;
+};
+
+int compileModuleWithNewPM(
+ StringRef Arg0, std::unique_ptr<Module> M, std::unique_ptr<MIRParser> MIR,
+ std::unique_ptr<TargetMachine> Target, std::unique_ptr<ToolOutputFile> Out,
+ std::unique_ptr<ToolOutputFile> DwoOut, LLVMContext &Context,
+ const TargetLibraryInfoImpl &TLII, bool NoVerify, bool CompileTwice,
+ const std::vector<std::string> &RunPassNames, CodeGenFileType FileType);
+} // namespace llvm
+
+#endif
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 0b174afc22ddced..c3cc47dc58b610d 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#include "NewPMDriver.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
@@ -66,23 +67,22 @@ static codegen::RegisterCodeGenFlags CGF;
// and back-end code generation options are specified with the target machine.
//
static cl::opt<std::string>
-InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
+ InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
static cl::opt<std::string>
-InputLanguage("x", cl::desc("Input language ('ir' or 'mir')"));
+ InputLanguage("x", cl::desc("Input language ('ir' or 'mir')"));
-static cl::opt<std::string>
-OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
+static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
+ cl::value_desc("filename"));
static cl::opt<std::string>
- SplitDwarfOutputFile("split-dwarf-output",
- cl::desc(".dwo output filename"),
+ SplitDwarfOutputFile("split-dwarf-output", cl::desc(".dwo output filename"),
cl::value_desc("filename"));
static cl::opt<unsigned>
-TimeCompilations("time-compilations", cl::Hidden, cl::init(1u),
- cl::value_desc("N"),
- cl::desc("Repeat compilation N times for timing"));
+ TimeCompilations("time-compilations", cl::Hidden, cl::init(1u),
+ cl::value_desc("N"),
+ cl::desc("Repeat compilation N times for timing"));
static cl::opt<bool> TimeTrace("time-trace", cl::desc("Record time trace"));
@@ -119,7 +119,7 @@ static cl::opt<char>
cl::Prefix, cl::init('2'));
static cl::opt<std::string>
-TargetTriple("mtriple", cl::desc("Override target triple for module"));
+ TargetTriple("mtriple", cl::desc("Override target triple for module"));
static cl::opt<std::string> SplitDwarfFile(
"split-dwarf-file",
@@ -129,8 +129,9 @@ static cl::opt<std::string> SplitDwarfFile(
static cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
cl::desc("Do not verify input module"));
-static cl::opt<bool> DisableSimplifyLibCalls("disable-simplify-libcalls",
- cl::desc("Disable simplify-libcalls"));
+static cl::opt<bool>
+ DisableSimplifyLibCalls("disable-simplify-libcalls",
+ cl::desc("Disable simplify-libcalls"));
static cl::opt<bool> ShowMCEncoding("show-mc-encoding", cl::Hidden,
cl::desc("Show encoding in .s output"));
@@ -186,6 +187,8 @@ static cl::opt<std::string> RemarksFormat(
cl::desc("The format used for serializing remarks (default: YAML)"),
cl::value_desc("format"), cl::init("yaml"));
+static cl::opt<bool> EnableNewPassManager(
+ "enable-new-pm", cl::desc("Enable the new pass manager"), cl::init(false));
namespace {
std::vector<std::string> &getRunPassNames() {
@@ -203,7 +206,7 @@ struct RunPassOption {
getRunPassNames().push_back(std::string(PassName));
}
};
-}
+} // namespace
static RunPassOption RunPassOpt;
@@ -299,41 +302,6 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
return FDOut;
}
-struct LLCDiagnosticHandler : public DiagnosticHandler {
- bool *HasError;
- LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- if (DI.getKind() == llvm::DK_SrcMgr) {
- const auto &DISM = cast<DiagnosticInfoSrcMgr>(DI);
- const SMDiagnostic &SMD = DISM.getSMDiag();
-
- if (SMD.getKind() == SourceMgr::DK_Error)
- *HasError = true;
-
- SMD.print(nullptr, errs());
-
- // For testing purposes, we print the LocCookie here.
- if (DISM.isInlineAsmDiag() && DISM.getLocCookie())
- WithColor::note() << "!srcloc = " << DISM.getLocCookie() << "\n";
-
- return true;
- }
-
- if (DI.getSeverity() == DS_Error)
- *HasError = true;
-
- if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
- if (!Remark->isEnabled())
- return true;
-
- DiagnosticPrinterRawOStream DP(errs());
- errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
- DI.print(DP);
- errs() << "\n";
- return true;
- }
-};
-
// main - Entry point for the llc compiler.
//
int main(int argc, char **argv) {
@@ -421,8 +389,8 @@ int main(int argc, char **argv) {
return 0;
}
-static bool addPass(PassManagerBase &PM, const char *argv0,
- StringRef PassName, TargetPassConfig &TPC) {
+static bool addPass(PassManagerBase &PM, const char *argv0, StringRef PassName,
+ TargetPassConfig &TPC) {
if (PassName == "none")
return false;
@@ -619,7 +587,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Figure out where we are going to send the output.
std::unique_ptr<ToolOutputFile> Out =
GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]);
- if (!Out) return 1;
+ if (!Out)
+ return 1;
// Ensure the filename is passed down to CodeViewDebug.
Target->Options.ObjectFilenameForDebug = Out->outputFilename();
@@ -628,21 +597,17 @@ static int compileModule(char **argv, LLVMContext &Context) {
if (!SplitDwarfOutputFile.empty()) {
std::error_code EC;
DwoOut = std::make_unique<ToolOutputFile>(SplitDwarfOutputFile, EC,
- sys::fs::OF_None);
+ sys::fs::OF_None);
if (EC)
reportError(EC.message(), SplitDwarfOutputFile);
}
- // Build up all of the passes that we want to do to the module.
- legacy::PassManager PM;
-
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
TLII.disableAllFunctions();
- PM.add(new TargetLibraryInfoWrapperPass(TLII));
// Verify module immediately to catch problems before doInitialization() is
// called on any passes.
@@ -658,6 +623,19 @@ static int compileModule(char **argv, LLVMContext &Context) {
WithColor::warning(errs(), argv[0])
<< ": warning: ignoring -mc-relax-all because filetype != obj";
+ bool RunPassNone =
+ !getRunPassNames().empty() && getRunPassNames().at(0) == "none";
+ if (EnableNewPassManager && !RunPassNone) {
+ return compileModuleWithNewPM(
+ argv[0], std::move(M), std::move(MIR), std::move(Target),
+ std::move(Out), std::move(DwoOut), Context, TLII, NoVerify,
+ CompileTwice, getRunPassNames(), codegen::getFileType());
+ }
+
+ // Build up all of the passes that we want to do to the module.
+ legacy::PassManager PM;
+ PM.add(new TargetLibraryInfoWrapperPass(TLII));
+
{
raw_pwrite_stream *OS = &Out->os();
>From fcf73a3cc72351c0d2c88c12047d927776aba800 Mon Sep 17 00:00:00 2001
From: PaperChalice <example at example.com>
Date: Fri, 3 Nov 2023 18:32:08 +0800
Subject: [PATCH 2/4] drop llc tests temporarily
---
.../Generic/llc-start-stop-instance-errors.ll | 2 -
.../CodeGen/Generic/new-pm/llc-start-stop.ll | 47 ----
llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll | 116 ---------
.../X86/new-pm/llc-start-stop-instance.ll | 35 ---
llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll | 243 ------------------
5 files changed, 443 deletions(-)
delete mode 100644 llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll
delete mode 100644 llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll
delete mode 100644 llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll
delete mode 100644 llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll
diff --git a/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll b/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
index 8cad70b5d9ede10..76cc8b681b6a785 100644
--- a/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
+++ b/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
@@ -1,6 +1,4 @@
; RUN: not --crash llc -debug-pass=Structure -stop-after=dead-mi-elimination,arst %s -o /dev/null 2>&1 \
; RUN: | FileCheck -check-prefix=NOT-NUM %s
-; RUN: not --crash llc -enable-new-pm -debug-pass-manager -stop-after=dead-mi-elimination,arst %s -o /dev/null 2>&1 \
-; RUN: | FileCheck -check-prefix=NOT-NUM %s
; NOT-NUM: LLVM ERROR: invalid pass instance specifier dead-mi-elimination,arst
diff --git a/llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll b/llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll
deleted file mode 100644
index 5245563763d81bf..000000000000000
--- a/llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll
+++ /dev/null
@@ -1,47 +0,0 @@
-; RUN: llc < %s -enable-new-pm -debug-pass-manager -stop-after=verify \
-; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-AFTER
-; STOP-AFTER: Running pass: VerifierPass
-; STOP-AFTER-NEXT: Running analysis: VerifierAnalysis
-; STOP-AFTER-NEXT: Skipping pass:
-
-; RUN: llc < %s -enable-new-pm -debug-pass-manager -stop-before=verify \
-; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-BEFORE
-; STOP-BEFORE: Running pass: AtomicExpandPass
-; STOP-BEFORE-NEXT: Skipping pass:
-
-; RUN: llc < %s -enable-new-pm -debug-pass-manager -start-after=verify \
-; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=START-AFTER
-; START-AFTER: Skipping pass: VerifierPass
-; START-AFTER-NEXT: Running pass:
-
-; RUN: llc < %s -enable-new-pm -debug-pass-manager -start-before=verify \
-; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=START-BEFORE
-; START-BEFORE-NOT: Running pass:
-; START-BEFORE: Running pass: VerifierPass
-
-; RUN: not --crash llc < %s -enable-new-pm -start-before=nonexistent -o /dev/null 2>&1 \
-; RUN: | FileCheck %s -check-prefix=NONEXISTENT-START-BEFORE
-; RUN: not --crash llc < %s -enable-new-pm -stop-before=nonexistent -o /dev/null 2>&1 \
-; RUN: | FileCheck %s -check-prefix=NONEXISTENT-STOP-BEFORE
-; RUN: not --crash llc < %s -enable-new-pm -start-after=nonexistent -o /dev/null 2>&1 \
-; RUN: | FileCheck %s -check-prefix=NONEXISTENT-START-AFTER
-; RUN: not --crash llc < %s -enable-new-pm -stop-after=nonexistent -o /dev/null 2>&1 \
-; RUN: | FileCheck %s -check-prefix=NONEXISTENT-STOP-AFTER
-; NONEXISTENT-START-BEFORE: "nonexistent" pass could not be found.
-; NONEXISTENT-STOP-BEFORE: "nonexistent" pass could not be found.
-; NONEXISTENT-START-AFTER: "nonexistent" pass could not be found.
-; NONEXISTENT-STOP-AFTER: "nonexistent" pass could not be found.
-
-; RUN: not --crash llc < %s -enable-new-pm -start-before=verify -start-after=verify \
-; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=DOUBLE-START
-; RUN: not --crash llc < %s -enable-new-pm -stop-before=verify -stop-after=verify \
-; RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=DOUBLE-STOP
-; DOUBLE-START: start-before and start-after specified!
-; DOUBLE-STOP: stop-before and stop-after specified!
-
-define void @f() {
- br label %b
-b:
- br label %b
- ret void
-}
diff --git a/llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll b/llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll
deleted file mode 100644
index d2b3d333ba27266..000000000000000
--- a/llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll
+++ /dev/null
@@ -1,116 +0,0 @@
-; When EXPENSIVE_CHECKS are enabled, the machine verifier appears between each
-; pass. Ignore it with 'grep -v'.
-; RUN: llc -mtriple=x86_64-- -O0 -debug-pass-manager -enable-new-pm < %s \
-; RUN: -o /dev/null 2>&1 | grep -v 'Verify generated machine code' | FileCheck %s
-
-; REQUIRES: asserts
-
-; CHECK-LABEL: Running pass: PreISelIntrinsicLoweringPass on [module]
-; CHECK-NEXT: Running analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
-; CHECK-NEXT: Running pass: ExpandLargeDivRemPass on f (1 instruction)
-; CHECK-NEXT: Running pass: ExpandLargeFpConvertPass on f (1 instruction)
-; CHECK-NEXT: Running pass: AtomicExpandPass on f (1 instruction)
-; CHECK-NEXT: Running pass: VerifierPass on f (1 instruction)
-; CHECK-NEXT: Running analysis: VerifierAnalysis on f
-; CHECK-NEXT: Running pass: GCLoweringPass on f (1 instruction)
-; CHECK-NEXT: Running pass: ShadowStackGCLoweringPass on f (1 instruction)
-; CHECK-NEXT: Running pass: LowerConstantIntrinsicsPass on f (1 instruction)
-; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on f
-; CHECK-NEXT: Running pass: UnreachableBlockElimPass on f (1 instruction)
-; CHECK-NEXT: Running pass: ExpandVectorPredicationPass on f (1 instruction)
-; CHECK-NEXT: Running analysis: TargetIRAnalysis on f
-; CHECK-NEXT: Running pass: ScalarizeMaskedMemIntrinPass on f (1 instruction)
-; CHECK-NEXT: Running pass: ExpandReductionsPass on f (1 instruction)
-; CHECK-NEXT: Running pass: IndirectBrExpandPass on f (1 instruction)
-; CHECK-NEXT: Running pass: DwarfEHPass on f (1 instruction)
-; CHECK-NEXT: Running pass: CallBrPrepare on f (1 instruction)
-; CHECK-NEXT: Running pass: SafeStackPass on f (1 instruction)
-; CHECK-NEXT: Running pass: StackProtectorPass on f (1 instruction)
-; CHECK-NEXT: Running pass: VerifierPass on f (1 instruction)
-; CHECK-NEXT: Running analysis: MachineModuleAnalysis on [module]
-; CHECK-NEXT: Running pass: {{.*}}::X86ISelDagPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86GlobalBaseRegPass on f
-; CHECK-NEXT: Running pass: FinalizeISelPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: LocalStackSlotPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeLoadHardeningPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FlagsCopyLoweringDummyPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86DynAllocaExpanderPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FastPreTileConfigPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PHIEliminationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: TwoAddressInstructionPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: RegAllocPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FastTileConfigPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86LowerTileCopyPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FloatingPointStackifierPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: RemoveRedundantDebugValuesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: FixupStatepointCallerSavedPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PrologEpilogInserterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: ExpandPostRAPseudosPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86ExpandPseudoPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: KCFIPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: FEntryInserterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: XRayInstrumentationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PatchableFunctionPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86IndirectBranchTrackingPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86IssueVZeroUpperPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86EvexToVexInstsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86DiscriminateMemOpsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86InsertPrefetchPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86InsertX87waitPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: FuncletLayoutPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: StackMapLivenessPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: LiveDebugValuesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineSanitizerBinaryMetadata on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: StackFrameLayoutAnalysisPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeExecutionSideEffectSuppressionPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86IndirectThunksPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86ReturnThunksPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: CFIInstrInserterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86LoadValueInjectionRetHardeningPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PseudoProbeInserterPass on [module]
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: UnpackMachineBundlesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86AsmPrinterPass on f
-; CHECK-NEXT: Running pass: FreeMachineFunctionPass on f
-
-define void @f() {
- ret void
-}
diff --git a/llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll b/llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll
deleted file mode 100644
index a6d5cf2fd8aff58..000000000000000
--- a/llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll
+++ /dev/null
@@ -1,35 +0,0 @@
-; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -stop-after=verify,1 \
-; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=STOP-AFTER-1 %s
-
-; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -stop-after=verify,0 \
-; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=STOP-AFTER-0 %s
-
-; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -stop-before=verify,1 \
-; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=STOP-BEFORE-1 %s
-
-; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -start-before=verify,1 \
-; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=START-BEFORE-1 %s
-
-; RUN: llc -mtriple=x86_64-- -enable-new-pm -debug-pass-manager -start-after=verify,1 \
-; RUN: %s -o /dev/null 2>&1 | FileCheck -check-prefix=START-AFTER-1 %s
-
-
-; STOP-AFTER-1: Running pass: VerifierPass
-; STOP-AFTER-1: Running pass: VerifierPass
-
-; STOP-AFTER-0-NOT: Running pass: VerifierPass
-; STOP-AFTER-0: Running pass: VerifierPass
-; STOP-AFTER-0-NOT: Running pass: VerifierPass
-
-; STOP-BEFORE-1: Running pass: VerifierPass
-; STOP-BEFORE-1-NOT: Running pass: VerifierPass
-
-; START-BEFORE-1-NOT: Running pass: VerifierPass
-; START-BEFORE-1: Running pass: VerifierPass
-; START-BEFORE-1-NOT: Running pass: VerifierPass
-
-; START-AFTER-1-NOT: Running pass: VerifierPass
-
-define void @f() {
- ret void
-}
diff --git a/llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll b/llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll
deleted file mode 100644
index 73b074a5e67f967..000000000000000
--- a/llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll
+++ /dev/null
@@ -1,243 +0,0 @@
-; When EXPENSIVE_CHECKS are enabled, the machine verifier appears between each
-; pass. Ignore it with 'grep -v'.
-; RUN: llc -mtriple=x86_64-- -O1 -debug-pass-manager -enable-new-pm < %s \
-; RUN: -o /dev/null 2>&1 | FileCheck %s
-; RUN: llc -mtriple=x86_64-- -O2 -debug-pass-manager -enable-new-pm < %s \
-; RUN: -o /dev/null 2>&1 | FileCheck %s
-; RUN: llc -mtriple=x86_64-- -O3 -debug-pass-manager -enable-new-pm < %s \
-; RUN: -o /dev/null 2>&1 | FileCheck %s
-
-; REQUIRES: asserts
-
-; CHECK-LABEL: Running pass: PreISelIntrinsicLoweringPass on [module]
-; CHECK-NEXT: Running analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
-; CHECK-NEXT: Running pass: ExpandLargeDivRemPass on f (3 instructions)
-; CHECK-NEXT: Running pass: ExpandLargeFpConvertPass on f (3 instructions)
-; CHECK-NEXT: Running pass: AtomicExpandPass on f (3 instructions)
-; CHECK-NEXT: Running pass: VerifierPass on f (3 instructions)
-; CHECK-NEXT: Running analysis: VerifierAnalysis on f
-; CHECK-NEXT: Running pass: LoopSimplifyPass on f (3 instructions)
-; CHECK-NEXT: Running analysis: LoopAnalysis on f
-; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on f
-; CHECK-NEXT: Running analysis: AssumptionAnalysis on f
-; CHECK-NEXT: Running analysis: TargetIRAnalysis on f
-; CHECK-NEXT: Running pass: LCSSAPass on f (3 instructions)
-; CHECK-NEXT: Running analysis: MemorySSAAnalysis on f
-; CHECK-NEXT: Running analysis: AAManager on f
-; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on f
-; CHECK-NEXT: Running analysis: BasicAA on f
-; CHECK-NEXT: Running analysis: ScopedNoAliasAA on f
-; CHECK-NEXT: Running analysis: TypeBasedAA on f
-; CHECK-NEXT: Running analysis: {{.*OuterAnalysisManagerProxy.*|UNKNOWN_TYPE}}
-; CHECK-NEXT: Running analysis: ScalarEvolutionAnalysis on f
-; CHECK-NEXT: Running analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
-; CHECK-NEXT: Running pass: CanonicalizeFreezeInLoopsPass on b
-; CHECK-NEXT: Running pass: LoopSimplifyPass on f (3 instructions)
-; CHECK-NEXT: Running pass: LCSSAPass on f (3 instructions)
-; CHECK-NEXT: Running pass: LoopStrengthReducePass on b
-; CHECK-NEXT: Running analysis: IVUsersAnalysis on b
-; CHECK-NEXT: Running pass: MergeICmpsPass on f (3 instructions)
-; CHECK-NEXT: Running pass: ExpandMemCmpPass on f (3 instructions)
-; CHECK-NEXT: Running pass: GCLoweringPass on f (3 instructions)
-; CHECK-NEXT: Running pass: ShadowStackGCLoweringPass on f (3 instructions)
-; CHECK-NEXT: Running pass: LowerConstantIntrinsicsPass on f (3 instructions)
-; CHECK-NEXT: Running pass: UnreachableBlockElimPass on f (3 instructions)
-; CHECK-NEXT: Clearing all analysis results for: <possibly invalidated loop>
-; CHECK-NEXT: Invalidating analysis: VerifierAnalysis on f
-; CHECK-NEXT: Invalidating analysis: LoopAnalysis on f
-; CHECK-NEXT: Invalidating analysis: MemorySSAAnalysis on f
-; CHECK-NEXT: Invalidating analysis: ScalarEvolutionAnalysis on f
-; CHECK-NEXT: Invalidating analysis: {{.*InnerAnalysisManagerProxy.*|UNKNOWN_TYPE}}
-; CHECK-NEXT: Running pass: ConstantHoistingPass on f (2 instructions)
-; CHECK-NEXT: Running analysis: BlockFrequencyAnalysis on f
-; CHECK-NEXT: Running analysis: BranchProbabilityAnalysis on f
-; CHECK-NEXT: Running analysis: LoopAnalysis on f
-; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on f
-; CHECK-NEXT: Running pass: ReplaceWithVeclib on f (2 instructions)
-; CHECK-NEXT: Running pass: PartiallyInlineLibCallsPass on f (2 instructions)
-; CHECK-NEXT: Running pass: ExpandVectorPredicationPass on f (2 instructions)
-; CHECK-NEXT: Running pass: ScalarizeMaskedMemIntrinPass on f (2 instructions)
-; CHECK-NEXT: Running pass: ExpandReductionsPass on f (2 instructions)
-; CHECK-NEXT: Running pass: TLSVariableHoistPass on f (2 instructions)
-; CHECK-NEXT: Running pass: InterleavedAccessPass on f (2 instructions)
-; CHECK-NEXT: Running pass: IndirectBrExpandPass on f (2 instructions)
-; CHECK-NEXT: Running pass: CodeGenPreparePass on f (2 instructions)
-; CHECK-NEXT: Running pass: DwarfEHPass on f (2 instructions)
-; CHECK-NEXT: Running pass: CallBrPrepare on f (2 instructions)
-; CHECK-NEXT: Running pass: SafeStackPass on f (2 instructions)
-; CHECK-NEXT: Running pass: StackProtectorPass on f (2 instructions)
-; CHECK-NEXT: Running pass: VerifierPass on f (2 instructions)
-; CHECK-NEXT: Running analysis: VerifierAnalysis on f
-; CHECK-NEXT: Running analysis: MachineModuleAnalysis on [module]
-; CHECK-NEXT: Running pass: {{.*}}::X86ISelDagPass on f
-; CHECK-NEXT: Running pass: {{.*}}::CleanupLocalDynamicTLSPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86GlobalBaseRegPass on f
-; CHECK-NEXT: Running pass: FinalizeISelPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86DomainReassignmentPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: EarlyTailDuplicatePass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: OptimizePHIsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: StackColoringPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: LocalStackSlotPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: DeadMachineInstructionElimPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: EarlyIfConverterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineCombinerPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86CmovConverterDummyPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: EarlyMachineLICMPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineCSEPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineSinkingPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PeepholeOptimizerPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: DeadMachineInstructionElimPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: LiveRangeShrinkPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FixupSetCCPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86OptimizeLEAsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86CallFrameOptimizationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86AvoidStoreForwardingBlocksPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeLoadHardeningPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FlagsCopyLoweringDummyPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86DynAllocaExpanderPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86PreTileConfigPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: DetectDeadLanesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: ProcessImplicitDefsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PHIEliminationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: TwoAddressInstructionPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: RegisterCoalescerPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: RenameIndependentSubregsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineSchedulerPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: RegAllocPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FastTileConfigPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineCopyPropagationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineLICMPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86LowerTileCopyPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FloatingPointStackifierPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86LoadValueInjectionRetHardeningPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: RemoveRedundantDebugValuesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: FixupStatepointCallerSavedPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PostRAMachineSinkingPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: ShrinkWrapPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PrologEpilogInserterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: BranchFolderPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: TailDuplicatePass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineLateInstrsCleanupPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineCopyPropagationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: ExpandPostRAPseudosPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86ExpandPseudoPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: KCFIPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PostRASchedulerPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineBlockPlacementPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: FEntryInserterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: XRayInstrumentationPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PatchableFunctionPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86ExecutionDomainFixPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: BreakFalseDepsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86IndirectBranchTrackingPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86IssueVZeroUpperPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FixupBWInstsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86PadShortFunctionsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FixupLEAsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FixupInstTuningPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86FixupVectorConstantsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86EvexToVexInstsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86DiscriminateMemOpsPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86InsertPrefetchPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86InsertX87waitPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: FuncletLayoutPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: StackMapLivenessPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: LiveDebugValuesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: MachineSanitizerBinaryMetadata on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: StackFrameLayoutAnalysisPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86SpeculativeExecutionSideEffectSuppressionPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86IndirectThunksPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86ReturnThunksPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: CFIInstrInserterPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86LoadValueInjectionRetHardeningPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: PseudoProbeInserterPass on [module]
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: UnpackMachineBundlesPass on f
-; CHECK-NEXT: Running pass: MachineVerifierPass on f
-; CHECK-NEXT: Running pass: {{.*}}::X86AsmPrinterPass on f
-; CHECK-NEXT: Running pass: FreeMachineFunctionPass on f
-
-define void @f() {
- br label %b
-b:
- br label %b
- ret void
-}
>From 1d353b6deaab4c7dd7a56a9d5eec68b9fab8ee51 Mon Sep 17 00:00:00 2001
From: liujunchang <lgamma at 163.com>
Date: Wed, 1 Nov 2023 10:46:27 +0800
Subject: [PATCH 3/4] [Pass] Support start/stop in instrumentation
---
llvm/include/llvm/IR/PassInstrumentation.h | 33 ++++++++++++++++++++
llvm/lib/CodeGen/TargetPassConfig.cpp | 19 +++++++++--
llvm/lib/Passes/StandardInstrumentations.cpp | 7 +++--
3 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/IR/PassInstrumentation.h b/llvm/include/llvm/IR/PassInstrumentation.h
index 519a5e46b4373b7..3f70fcf180af81a 100644
--- a/llvm/include/llvm/IR/PassInstrumentation.h
+++ b/llvm/include/llvm/IR/PassInstrumentation.h
@@ -84,6 +84,23 @@ class PassInstrumentationCallbacks {
using AfterAnalysisFunc = void(StringRef, Any);
using AnalysisInvalidatedFunc = void(StringRef, Any);
using AnalysesClearedFunc = void(StringRef);
+ using StartStopFunc = bool(StringRef, Any);
+
+ struct CodeGenStartStopInfo {
+ StringRef Start;
+ StringRef Stop;
+
+ bool IsStopMachinePass = false;
+
+ llvm::unique_function<StartStopFunc> StartStopCallback;
+
+ bool operator()(StringRef PassID, Any IR) {
+ return StartStopCallback(PassID, IR);
+ }
+ bool isStopMachineFunctionPass() const { return IsStopMachinePass; }
+ bool willCompleteCodeGenPipeline() const { return Stop.empty(); }
+ StringRef getStop() const { return Stop; }
+ };
public:
PassInstrumentationCallbacks() = default;
@@ -148,6 +165,17 @@ class PassInstrumentationCallbacks {
AnalysesClearedCallbacks.emplace_back(std::move(C));
}
+ void registerStartStopInfo(CodeGenStartStopInfo &&C) {
+ StartStopInfo = std::move(C);
+ }
+
+ bool isStartStopInfoRegistered() const { return StartStopInfo.has_value(); }
+
+ CodeGenStartStopInfo &getStartStopInfo() {
+ assert(StartStopInfo.has_value() && "StartStopInfo is unregistered!");
+ return *StartStopInfo;
+ }
+
/// Add a class name to pass name mapping for use by pass instrumentation.
void addClassToPassName(StringRef ClassName, StringRef PassName);
/// Get the pass name for a given pass class name.
@@ -183,6 +211,8 @@ class PassInstrumentationCallbacks {
/// These are run on analyses that have been cleared.
SmallVector<llvm::unique_function<AnalysesClearedFunc>, 4>
AnalysesClearedCallbacks;
+ /// For `llc` -start-* -stop-* options.
+ std::optional<CodeGenStartStopInfo> StartStopInfo;
StringMap<std::string> ClassToPassName;
};
@@ -236,6 +266,9 @@ class PassInstrumentation {
ShouldRun &= C(Pass.name(), llvm::Any(&IR));
}
+ if (Callbacks->StartStopInfo)
+ ShouldRun &= (*Callbacks->StartStopInfo)(Pass.name(), llvm::Any(&IR));
+
if (ShouldRun) {
for (auto &C : Callbacks->BeforeNonSkippedPassCallbacks)
C(Pass.name(), llvm::Any(&IR));
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index e6ecbc9b03f7149..bea8590a14080ca 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -508,6 +508,9 @@ static void registerPartialPipelineCallback(PassInstrumentationCallbacks &PIC,
unsigned StopBeforeInstanceNum = 0;
unsigned StopAfterInstanceNum = 0;
+ bool IsStopBeforeMachinePass = false;
+ bool IsStopAfterMachinePass = false;
+
std::tie(StartBefore, StartBeforeInstanceNum) =
getPassNameAndInstanceNum(StartBeforeOpt);
std::tie(StartAfter, StartAfterInstanceNum) =
@@ -536,7 +539,15 @@ static void registerPartialPipelineCallback(PassInstrumentationCallbacks &PIC,
report_fatal_error(Twine(StopBeforeOptName) + Twine(" and ") +
Twine(StopAfterOptName) + Twine(" specified!"));
- PIC.registerShouldRunOptionalPassCallback(
+ std::vector<StringRef> SpecialPasses = {"PassManager", "PassAdaptor",
+ "PrintMIRPass", "PrintModulePass"};
+
+ PassInstrumentationCallbacks::CodeGenStartStopInfo Info;
+ Info.Start = StartBefore.empty() ? StartAfter : StartBefore;
+ Info.Stop = StopBefore.empty() ? StopAfter : StopBefore;
+
+ Info.IsStopMachinePass = IsStopBeforeMachinePass || IsStopAfterMachinePass;
+ Info.StartStopCallback =
[=, EnableCurrent = StartBefore.empty() && StartAfter.empty(),
EnableNext = std::optional<bool>(), StartBeforeCount = 0u,
StartAfterCount = 0u, StopBeforeCount = 0u,
@@ -567,8 +578,10 @@ static void registerPartialPipelineCallback(PassInstrumentationCallbacks &PIC,
EnableCurrent = true;
if (StopBeforePass && StopBeforeCount++ == StopBeforeInstanceNum)
EnableCurrent = false;
- return EnableCurrent;
- });
+ return EnableCurrent || isSpecialPass(P, SpecialPasses);
+ };
+
+ PIC.registerStartStopInfo(std::move(Info));
}
void llvm::registerCodeGenCallback(PassInstrumentationCallbacks &PIC,
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 06cc58c0219632d..c6ec1c34d74418d 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1036,9 +1036,10 @@ void PrintPassInstrumentation::registerCallbacks(
SpecialPasses.emplace_back("PassAdaptor");
}
- PIC.registerBeforeSkippedPassCallback([this, SpecialPasses](StringRef PassID,
- Any IR) {
- assert(!isSpecialPass(PassID, SpecialPasses) &&
+ PIC.registerBeforeSkippedPassCallback([this, SpecialPasses,
+ &PIC](StringRef PassID, Any IR) {
+ assert((!isSpecialPass(PassID, SpecialPasses) ||
+ PIC.isStartStopInfoRegistered()) &&
"Unexpectedly skipping special pass");
print() << "Skipping pass: " << PassID << " on " << getIRName(IR) << "\n";
>From b9d46724635371f2170462db2d376143d4785379 Mon Sep 17 00:00:00 2001
From: PaperChalice <example at example.com>
Date: Fri, 3 Nov 2023 18:41:06 +0800
Subject: [PATCH 4/4] add parseMIRPipeline
---
llvm/include/llvm/Target/TargetMachine.h | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index c1d05b25ea21f8a..6459229baaa3fc9 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -14,6 +14,7 @@
#define LLVM_TARGET_TARGETMACHINE_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Allocator.h"
@@ -452,17 +453,24 @@ class LLVMTargetMachine : public TargetMachine {
virtual Error buildCodeGenPipeline(ModulePassManager &,
MachineFunctionPassManager &,
- MachineFunctionAnalysisManager &,
raw_pwrite_stream &, raw_pwrite_stream *,
CodeGenFileType, CGPassBuilderOption,
+ MachineFunctionAnalysisManager &,
PassInstrumentationCallbacks *) {
return make_error<StringError>("buildCodeGenPipeline is not overridden",
inconvertibleErrorCode());
}
virtual std::pair<StringRef, bool> getPassNameFromLegacyName(StringRef) {
- llvm_unreachable(
- "getPassNameFromLegacyName parseMIRPipeline is not overridden");
+ llvm_unreachable("getPassNameFromLegacyName is not overridden");
+ }
+
+ virtual Error parseMIRPipeline(MachineFunctionPassManager &MFPM,
+ StringRef PipelineText,
+ CGPassBuilderOption Opts,
+ MachineFunctionAnalysisManager &MFAM,
+ PassInstrumentationCallbacks *PIC) {
+ llvm_unreachable("parseMIRPipeline is not overridden");
}
/// Add passes to the specified pass manager to get machine code emitted with
More information about the llvm-commits
mailing list