Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[NewPM][CodeGen][llc] Add NPM support #70922

Merged
merged 10 commits into from Jan 24, 2024

Conversation

paperchalice
Copy link
Contributor

@paperchalice paperchalice commented Nov 1, 2023

Add new pass manager support to llc. Users can use --passes=pass1,pass2... to run mir passes, and use --enable-new-pm to run default codegen pipeline.
This patch is taken from D83612, the original author is @yuanfang-chen.

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 1, 2023

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-x86

Author: None (paperchalice)

Changes

This patch is stolen from D83612, the original author is @yuanfang-chen.
I just migrate it to the latest llvm.
Part of #69879, blocked by #70921.


Patch is 40.96 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/70922.diff

9 Files Affected:

  • (modified) llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll (+2)
  • (added) llvm/test/CodeGen/Generic/new-pm/llc-start-stop.ll (+47)
  • (added) llvm/test/CodeGen/X86/new-pm/O0-pipeline.ll (+116)
  • (added) llvm/test/CodeGen/X86/new-pm/llc-start-stop-instance.ll (+35)
  • (added) llvm/test/CodeGen/X86/new-pm/opt-pipeline.ll (+243)
  • (modified) llvm/tools/llc/CMakeLists.txt (+3)
  • (added) llvm/tools/llc/NewPMDriver.cpp (+264)
  • (added) llvm/tools/llc/NewPMDriver.h (+49)
  • (modified) llvm/tools/llc/llc.cpp (+16-39)
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 pas...
[truncated]

@aeubanks
Copy link
Contributor

aeubanks commented Nov 1, 2023

I'd like this to land before any of the other patches so all the other patches have proper testing (unless other patches are blocking this one)

Will try to find some time to review this

}

MachineFunctionPassManager MFPM;
ExitOnErr(LLVMTM.parseMIRPipeline(MFPM, llvm::join(RunPassNames, ","),
Copy link
Contributor

Choose a reason for hiding this comment

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

I get:

tools/llc/NewPMDriver.cpp:223:24: error: no member named 'parseMIRPipeline' in 'llvm::LLVMTargetMachine'

plus some more errors in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need #70912 and #70906.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. It would be nice to have a buildable branch to pull from that includes just this PR plus necessary dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This version should be a buildable version.

using namespace llvm;

static cl::opt<RegAllocType> RegAlloc(
"regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid having separate copies of the same options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This option is special

static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
RegisterPassParser<RegisterRegAlloc>>
RegAlloc("regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
cl::desc("Register allocator to use"));

It handles regalloc pass directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's doubly unfortunate because AMDGPU also has to duplicate 2 additional clones of this flag

Copy link
Contributor

Choose a reason for hiding this comment

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

can we rework that option to be a std::string and lookup the pass on demand?

// 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;
Copy link
Contributor

Choose a reason for hiding this comment

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

SmallString?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just copy it from llc.cpp, will fix it later.

@@ -0,0 +1,49 @@
//===- NewPMDriver.h - Function to drive llc with the new PM --------------===//
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing C++ mode comment

using namespace llvm;

static cl::opt<RegAllocType> RegAlloc(
"regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
Copy link
Contributor

Choose a reason for hiding this comment

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

That's doubly unfortunate because AMDGPU also has to duplicate 2 additional clones of this flag

llvm/tools/llc/NewPMDriver.cpp Show resolved Hide resolved
@paperchalice paperchalice force-pushed the NPM/CodeGen/tool branch 2 times, most recently from ef9e875 to 1757063 Compare December 16, 2023 02:15
@paperchalice
Copy link
Contributor Author

Rebased. If this pull request looks good, I will land this firstly.

exit(1);

// Compare the two outputs and make sure they're the same
if (CompileTwice) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we haven't guaranteed that reusing a pipeline twice works as expected for the new PM so I'd remove all the CompileTwice code until we have that guarantee everywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

and inline RunPM() with this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

CGPassBuilderOption Opts,
MachineFunctionAnalysisManager &MFAM,
PassInstrumentationCallbacks *PIC) {
llvm_unreachable("parseMIRPipeline is not overridden");
Copy link
Contributor

Choose a reason for hiding this comment

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

could make these pure virtual instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will convert to pure virtual once all patches look good.

/// llc.cpp.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_OPT_NEWPMDRIVER_H
Copy link
Contributor

Choose a reason for hiding this comment

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

s/OPT/LLC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -506,6 +506,9 @@ static void registerPartialPipelineCallback(PassInstrumentationCallbacks &PIC,
unsigned StopBeforeInstanceNum = 0;
unsigned StopAfterInstanceNum = 0;

bool IsStopBeforeMachinePass = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

this patch is doing too much at once, please split out the stop before/after to a separate change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already in #70912.

@paperchalice
Copy link
Contributor Author

paperchalice commented Jan 18, 2024

Target specific parts may need more time, but at least now we can use llc --run-pass=pass1... to test single machine function pass, although there is no machine function passes are supported.

}

MachineFunctionPassManager MFPM;
ExitOnErr(PB.parsePassPipeline(MFPM, llvm::join(RunPassNames, ",")));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why it reuses --run-pass option, but machine function passes may have options, that is why I move the machine function parsing part from TargetMachine to PassBuilder. Should we introduce a new option like --mir-passes='pass1<param>,pass2...'?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes we should definitely have an option like that (maybe just --passes)

@paperchalice paperchalice force-pushed the NPM/CodeGen/tool branch 2 times, most recently from efe5b8a to 2e9aed1 Compare January 18, 2024 13:46
Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

definitely needs some tests in llvm/test/tools/llc/

using namespace llvm;

static cl::opt<RegAllocType> RegAlloc(
"regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we rework that option to be a std::string and lookup the pass on demand?

llvm/tools/llc/NewPMDriver.cpp Outdated Show resolved Hide resolved
@paperchalice
Copy link
Contributor Author

paperchalice commented Jan 19, 2024

can we rework that option to be a std::string and lookup the pass on demand?

We could, current implementation is trying to compatible with the legacy version, may refactor it in future, it may involve PassBuilder, because register allocators are passes with parameters.

definitely needs some tests in llvm/test/tools/llc/

Need stub code in some targets, e.g. X86, so we can move some unit tests to test folder, also need #78570.

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

thanks for adding the x86 passbuilder and tests, this is great

}

MachineFunctionPassManager MFPM;
ExitOnErr(PB.parsePassPipeline(MFPM, llvm::join(RunPassNames, ",")));
Copy link
Contributor

Choose a reason for hiding this comment

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

yes we should definitely have an option like that (maybe just --passes)

llvm/tools/llc/NewPMDriver.cpp Outdated Show resolved Hide resolved
@paperchalice paperchalice force-pushed the NPM/CodeGen/tool branch 2 times, most recently from c00287c to 4447a34 Compare January 20, 2024 02:05
@paperchalice
Copy link
Contributor Author

paperchalice commented Jan 20, 2024

Print MIR only now, add new option--passes to run machine function passes. regalloc option is not so trivial, it may interact with backend e.g. AMDGPU, will refactor it in future, e.g. let it accept --regalloc-npm=regalloc-algorithm<params>, may handle this in PassBuilder but it may cause circular dependency between Passes and CodeGen, then it would be better to move CodeGenPassBuilder to Passes.

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

in general, having more tests that cover the various error conditions here would be good (where possible)

llvm/tools/llc/NewPMDriver.cpp Show resolved Hide resolved
if (!PassPipeline.empty() && TargetPassConfig::hasLimitedCodeGenPipeline()) {
WithColor::warning(errs(), Arg0)
<< "run-pass cannot be used with "
<< TargetPassConfig::getLimitedCodeGenPipelineReason(" and ") << ".\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

all callers to this method pass " and ", but the argument has a default param of "/", can you push a fix to just use " and " directly in the method?

llvm/tools/llc/NewPMDriver.cpp Outdated Show resolved Hide resolved
@@ -0,0 +1,4 @@
; RUN: llc -mtriple=x86_64-pc-linux-gnu -enable-new-pm -print-pipeline-passes -start-before=mergeicmps -stop-after=gc-lowering -filetype=null %s | FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

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

should FileCheck --match-full-lines %s

@aeubanks
Copy link
Contributor

and commit description should be more descriptive, the current description can probably all be removed except "taken from D83612"

@paperchalice
Copy link
Contributor Author

Address comments above.

yuanfang-chen and others added 4 commits January 23, 2024 13:45
This patch add new pass manager support to llc. User can use `--passes`
to run mir passes in new pass manager.
This patch is taken from D83612, the original author is yichen.
@paperchalice
Copy link
Contributor Author

Change the type of RegAlloc to StringRef, and delete the old implementation, will update it in future.

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

nice!


LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine &>(*Target);

{
Copy link
Contributor

Choose a reason for hiding this comment

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

why the extra braces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is copied from llc.cpp, llc.cpp also has these extra braces, will remove it.

@paperchalice paperchalice merged commit 7e50f00 into llvm:main Jan 24, 2024
3 of 4 checks passed
@paperchalice paperchalice deleted the NPM/CodeGen/tool branch January 24, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants