llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-systemz Author: Aiden Grossman (boomanaiden154) <details> <summary>Changes</summary> Standard NewPM CodeGenPassBuilder implementation. Tries to mirror the existing SystemZTargetPassConfig as much as possible. --- Full diff: https://github.com/llvm/llvm-project/pull/240268.diff 6 Files Affected: - (modified) llvm/lib/Target/SystemZ/CMakeLists.txt (+2) - (added) llvm/lib/Target/SystemZ/SystemZCodeGenPassBuilder.cpp (+174) - (added) llvm/lib/Target/SystemZ/SystemZPassRegistry.def (+20) - (modified) llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp (+4-4) - (modified) llvm/lib/Target/SystemZ/SystemZTargetMachine.h (+8) - (added) llvm/test/CodeGen/SystemZ/newpm-pipeline.ll (+139) ``````````diff diff --git a/llvm/lib/Target/SystemZ/CMakeLists.txt b/llvm/lib/Target/SystemZ/CMakeLists.txt index 11993576ef0316..9fe506992dd396 100644 --- a/llvm/lib/Target/SystemZ/CMakeLists.txt +++ b/llvm/lib/Target/SystemZ/CMakeLists.txt @@ -21,6 +21,7 @@ add_llvm_target(SystemZCodeGen SystemZAsmPrinter.cpp SystemZAlignGlobals.cpp SystemZCallingConv.cpp + SystemZCodeGenPassBuilder.cpp SystemZConstantPoolValue.cpp SystemZCopyPhysRegs.cpp SystemZELFAsmPrinter.cpp @@ -53,6 +54,7 @@ add_llvm_target(SystemZCodeGen CodeGenTypes Core MC + Passes Scalar SelectionDAG Support diff --git a/llvm/lib/Target/SystemZ/SystemZCodeGenPassBuilder.cpp b/llvm/lib/Target/SystemZ/SystemZCodeGenPassBuilder.cpp new file mode 100644 index 00000000000000..ab93b8f444fb70 --- /dev/null +++ b/llvm/lib/Target/SystemZ/SystemZCodeGenPassBuilder.cpp @@ -0,0 +1,174 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "SystemZ.h" +#include "SystemZTargetMachine.h" +#include "llvm/CodeGen/AtomicExpand.h" +#include "llvm/CodeGen/EarlyIfConversion.h" +#include "llvm/CodeGen/MachineCombiner.h" +#include "llvm/CodeGen/MachineScheduler.h" +#include "llvm/IR/PassInstrumentation.h" +#include "llvm/Passes/CodeGenPassBuilder.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/Support/CodeGen.h" +#include "llvm/Target/CGPassBuilderOption.h" +#include "llvm/Transforms/Scalar/LoopDataPrefetch.h" + +using namespace llvm; + +extern cl::opt<bool> EnableMachineCombinerPass; + +namespace { + +class SystemZCodeGenPassBuilder : public CodeGenPassBuilder { + using Base = CodeGenPassBuilder; + + SystemZTargetMachine &getTM() const { + return static_cast<SystemZTargetMachine &>(TM); + } + +public: + explicit SystemZCodeGenPassBuilder(SystemZTargetMachine &TM, + const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC) + : CodeGenPassBuilder(TM, Opts, PIC) {} + + void addIRPasses(PassManagerWrapper &PMW) override; + Error addInstSelector(PassManagerWrapper &PMW) override; + void addILPOpts(PassManagerWrapper &PMW) override; + void addPreRegAlloc(PassManagerWrapper &PMW) override; + void addPostRewrite(PassManagerWrapper &PMW) override; + void addPostRegAlloc(PassManagerWrapper &PMW) override; + void addPreSched2(PassManagerWrapper &PMW) override; + void addPreEmitPass(PassManagerWrapper &PMW) override; + void addAsmPrinterBegin(PassManagerWrapper &PMW) override; + void addAsmPrinter(PassManagerWrapper &PMW) override; + void addAsmPrinterEnd(PassManagerWrapper &PMW) override; +}; + +void SystemZCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) { + if (getOptLevel() != CodeGenOptLevel::None) { + // TODO(boomanaiden154): Add SystemZAlignGlobalsPass( + // TODO(boomanaiden154): Add SystemZTDCPass + addFunctionPass(LoopDataPrefetchPass(), PMW); + } + + addFunctionPass(AtomicExpandPass(getTM()), PMW); + + Base::addIRPasses(PMW); +} + +Error SystemZCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) { + addMachineFunctionPass(SystemZISelDAGToDAGPass(getTM(), getOptLevel()), PMW); + + if (getOptLevel() != CodeGenOptLevel::None) { + // TODO(boomanaiden154): Add SystemZLDCleanupPass + } + + return Error::success(); +} + +void SystemZCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) { + addMachineFunctionPass(EarlyIfConverterPass(), PMW); + + if (EnableMachineCombinerPass) + addMachineFunctionPass(MachineCombinerPass(), PMW); +} + +void SystemZCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) { + // TODO(boomanaiden154): Add SystemZCopyPhysRegsPass +} + +void SystemZCodeGenPassBuilder::addPostRewrite(PassManagerWrapper &PMW) { + // TODO(boomanaiden154): Add SystemZPostRewritePass +} + +void SystemZCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) { + // PostRewrite needs to be run at -O0 also (in which case addPostRewrite() + // is not called). + if (getOptLevel() == CodeGenOptLevel::None) { + // TODO(boomanaiden154): Add SystemZPostRewritePass + } +} + +void SystemZCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) { + if (getOptLevel() != CodeGenOptLevel::None) { + // TODO(boomanaiden154): Add IfConverter + } +} + +void SystemZCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) { + // Do instruction shortening before compare elimination because some + // vector instructions will be shortened into opcodes that compare + // elimination recognizes. + if (getOptLevel() != CodeGenOptLevel::None) { + // TODO(boomanaiden154): Add SystemZShortenInstPass + } + + // We eliminate comparisons here rather than earlier because some + // transformations can change the set of available CC values and we + // generally want those transformations to have priority. This is + // especially true in the commonest case where the result of the comparison + // is used by a single in-range branch instruction, since we will then + // be able to fuse the compare and the branch instead. + // + // For example, two-address NILF can sometimes be converted into + // three-address RISBLG. NILF produces a CC value that indicates whether + // the low word is zero, but RISBLG does not modify CC at all. On the + // other hand, 64-bit ANDs like NILL can sometimes be converted to RISBG. + // The CC value produced by NILL isn't useful for our purposes, but the + // value produced by RISBG can be used for any comparison with zero + // (not just equality). So there are some transformations that lose + // CC values (while still being worthwhile) and others that happen to make + // the CC result more useful than it was originally. + // + // Another reason is that we only want to use BRANCH ON COUNT in cases + // where we know that the count register is not going to be spilled. + // + // Doing it so late makes it more likely that a register will be reused + // between the comparison and the branch, but it isn't clear whether + // preventing that would be a win or not. + if (getOptLevel() != CodeGenOptLevel::None) { + // TODO(boomanaiden154): Add SystemZElimComparePass + } + // TODO(boomanaiden154): Add SystemZLongBranchPass + + // Do final scheduling after all other optimizations, to get an + // optimal input for the decoder (branch relaxation must happen + // after block placement). + if (getOptLevel() != CodeGenOptLevel::None) + addMachineFunctionPass(PostMachineSchedulerPass(&getTM()), PMW); +} + +void SystemZCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) { + // TODO(boomanaiden154): Add SystemZAsmPrinterBegin +} + +void SystemZCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) { + // TODO(boomanaiden154): Add SystemZAsmPrinter +} + +void SystemZCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) { + // TODO(boomanaiden154): Add SystemZAsmPrinterEnd +} + +} // namespace + +void SystemZTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB){ +#define GET_PASS_REGISTRY "SystemZPassRegistry.def" +#include "llvm/Passes/TargetPassRegistry.inc" +} + +Error SystemZTargetMachine::buildCodeGenPipeline( + ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, + raw_pwrite_stream *DwoOut, CodeGenFileType FileType, + const CGPassBuilderOption &Opt, MCContext &Ctx, + PassInstrumentationCallbacks *PIC) { + auto CGPB = SystemZCodeGenPassBuilder(*this, Opt, PIC); + return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx); +} diff --git a/llvm/lib/Target/SystemZ/SystemZPassRegistry.def b/llvm/lib/Target/SystemZ/SystemZPassRegistry.def new file mode 100644 index 00000000000000..4840391bed3c7d --- /dev/null +++ b/llvm/lib/Target/SystemZ/SystemZPassRegistry.def @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file is used as the registry of passes that are part of the SystemZ +// backend. +// +//===----------------------------------------------------------------------===// + +// NOTE: NO INCLUDE GUARD DESIRED! + +#ifndef MACHINE_FUNCTION_PASS +#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) +#endif +MACHINE_FUNCTION_PASS("systemz-isel", SystemZISelDAGToDAGPass(*this, getOptLevel())) +#undef MACHINE_FUNCTION_PASS diff --git a/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp b/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp index c5b7b1ff573709..987bc9b0b39968 100644 --- a/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp +++ b/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp @@ -31,10 +31,10 @@ using namespace llvm; -static cl::opt<bool> EnableMachineCombinerPass( - "systemz-machine-combiner", - cl::desc("Enable the machine combiner pass"), - cl::init(true), cl::Hidden); +cl::opt<bool> + EnableMachineCombinerPass("systemz-machine-combiner", + cl::desc("Enable the machine combiner pass"), + cl::init(true), cl::Hidden); static cl::opt<bool> GenericSched( "generic-sched", cl::Hidden, cl::init(false), diff --git a/llvm/lib/Target/SystemZ/SystemZTargetMachine.h b/llvm/lib/Target/SystemZ/SystemZTargetMachine.h index 1493332b9d3610..d0e62b1ecbf797 100644 --- a/llvm/lib/Target/SystemZ/SystemZTargetMachine.h +++ b/llvm/lib/Target/SystemZ/SystemZTargetMachine.h @@ -63,6 +63,14 @@ class SystemZTargetMachine : public CodeGenTargetMachineImpl { createPostMachineScheduler(MachineSchedContext *C) const override; bool targetSchedulesPostRAScheduling() const override { return true; }; + + void registerPassBuilderCallbacks(PassBuilder &PB) override; + + Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, + raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, + CodeGenFileType FileType, + const CGPassBuilderOption &Opt, MCContext &Ctx, + PassInstrumentationCallbacks *PIC) override; }; } // end namespace llvm diff --git a/llvm/test/CodeGen/SystemZ/newpm-pipeline.ll b/llvm/test/CodeGen/SystemZ/newpm-pipeline.ll new file mode 100644 index 00000000000000..1193cb2bbc36f7 --- /dev/null +++ b/llvm/test/CodeGen/SystemZ/newpm-pipeline.ll @@ -0,0 +1,139 @@ +; RUN: llc -enable-new-pm -mtriple=s390x-linux-gnu -O0 -print-pipeline-passes=tree < %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=O0 +; RUN: llc -enable-new-pm -mtriple=s390x-linux-gnu -O3 -print-pipeline-passes=tree < %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=O3 + +; O0: require<MachineModuleAnalysis> +; O0-NEXT: require<profile-summary> +; O0-NEXT: require<collector-metadata> +; O0-NEXT: require<runtime-libcall-info> +; O0-NEXT: require<libcall-lowering-info> +; O0-NEXT: pre-isel-intrinsic-lowering +; O0-NEXT: function +; O0-NEXT: expand-ir-insts<O0> +; O0-NEXT: atomic-expand +; O0-NEXT: verify +; O0-NEXT: gc-lowering +; O0-NEXT: shadow-stack-gc-lowering +; O0-NEXT: function +; O0-NEXT: unreachableblockelim +; O0-NEXT: ee-instrument<post-inline> +; O0-NEXT: scalarize-masked-mem-intrin +; O0-NEXT: expand-reductions +; O0-NEXT: sjlj-eh-prepare +; O0-NEXT: dwarf-eh-prepare +; O0-NEXT: inline-asm-prepare +; O0-NEXT: safe-stack +; O0-NEXT: stack-protector +; O0-NEXT: verify +; O0-NEXT: function +; O0-NEXT: machine-function +; O0-NEXT: systemz-isel +; O0-NEXT: finalize-isel +; O0-NEXT: localstackalloc +; O0-NEXT: phi-node-elimination +; O0-NEXT: regallocfast +; O0-NEXT: remove-redundant-debug-values +; O0-NEXT: fixup-statepoint-caller-saved +; O0-NEXT: prolog-epilog +; O0-NEXT: post-ra-pseudos +; O0-NEXT: fentry-insert +; O0-NEXT: xray-instrumentation +; O0-NEXT: patchable-function +; O0-NEXT: funclet-layout +; O0-NEXT: remove-loads-into-fake-uses +; O0-NEXT: StackMapLivenessPass +; O0-NEXT: live-debug-values +; O0-NEXT: machine-sanmd +; O0-NEXT: stack-frame-layout +; O0-NEXT: verify +; O0-NEXT: free-machine-function + +; O3: require<MachineModuleAnalysis> +; O3-NEXT: require<profile-summary> +; O3-NEXT: require<collector-metadata> +; O3-NEXT: require<runtime-libcall-info> +; O3-NEXT: require<libcall-lowering-info> +; O3-NEXT: function +; O3-NEXT: objc-arc-contract +; O3-NEXT: pre-isel-intrinsic-lowering +; O3-NEXT: function +; O3-NEXT: expand-ir-insts<O3> +; O3-NEXT: loop-data-prefetch +; O3-NEXT: atomic-expand +; O3-NEXT: verify +; O3-NEXT: loop +; O3-NEXT: canon-freeze +; O3-NEXT: loop-reduce +; O3-NEXT: gc-lowering +; O3-NEXT: shadow-stack-gc-lowering +; O3-NEXT: function +; O3-NEXT: unreachableblockelim +; O3-NEXT: consthoist +; O3-NEXT: replace-with-veclib +; O3-NEXT: partially-inline-libcalls +; O3-NEXT: ee-instrument<post-inline> +; O3-NEXT: scalarize-masked-mem-intrin +; O3-NEXT: expand-reductions +; O3-NEXT: codegenprepare +; O3-NEXT: sjlj-eh-prepare +; O3-NEXT: dwarf-eh-prepare +; O3-NEXT: inline-asm-prepare +; O3-NEXT: safe-stack +; O3-NEXT: stack-protector +; O3-NEXT: verify +; O3-NEXT: function +; O3-NEXT: machine-function +; O3-NEXT: systemz-isel +; O3-NEXT: finalize-isel +; O3-NEXT: early-tailduplication +; O3-NEXT: opt-phis +; O3-NEXT: stack-coloring +; O3-NEXT: localstackalloc +; O3-NEXT: dead-mi-elimination +; O3-NEXT: early-ifcvt +; O3-NEXT: machine-combiner +; O3-NEXT: early-machinelicm +; O3-NEXT: machine-cse +; O3-NEXT: machine-sink +; O3-NEXT: peephole-opt +; O3-NEXT: dead-mi-elimination +; O3-NEXT: detect-dead-lanes +; O3-NEXT: init-undef +; O3-NEXT: process-implicit-defs +; O3-NEXT: unreachable-mbb-elimination +; O3-NEXT: require<live-intervals> +; O3-NEXT: require<machine-loops> +; O3-NEXT: phi-node-elimination +; O3-NEXT: two-address-instruction +; O3-NEXT: register-coalescer +; O3-NEXT: rename-independent-subregs +; O3-NEXT: machine-scheduler +; O3-NEXT: greedy<all> +; O3-NEXT: virt-reg-rewriter +; O3-NEXT: stack-slot-coloring +; O3-NEXT: machine-cp +; O3-NEXT: machinelicm +; O3-NEXT: remove-redundant-debug-values +; O3-NEXT: fixup-statepoint-caller-saved +; O3-NEXT: postra-machine-sink +; O3-NEXT: shrink-wrap +; O3-NEXT: prolog-epilog +; O3-NEXT: machine-latecleanup +; O3-NEXT: branch-folder +; O3-NEXT: tailduplication +; O3-NEXT: machine-cp +; O3-NEXT: post-ra-pseudos +; O3-NEXT: block-placement +; O3-NEXT: fentry-insert +; O3-NEXT: xray-instrumentation +; O3-NEXT: patchable-function +; O3-NEXT: postmisched +; O3-NEXT: funclet-layout +; O3-NEXT: remove-loads-into-fake-uses +; O3-NEXT: StackMapLivenessPass +; O3-NEXT: live-debug-values +; O3-NEXT: machine-sanmd +; O3-NEXT: stack-frame-layout +; O3-NEXT: verify +; O3-NEXT: free-machine-function `````````` </details> https://github.com/llvm/llvm-project/pull/240268 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
