Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NewPM][CodeGen] Introduce CodeGenPassBuilder to help build codegen p…
…ipeline Following up on D67687. Please refer to the RFC here http://lists.llvm.org/pipermail/llvm-dev/2020-July/143309.html `CodeGenPassBuilder` is the NPM counterpart of `TargetPassConfig` with below differences. - Debugging features (MIR print/verify, disable pass, start/stop-before/after, etc.) living in `TargetPassConfig` are moved to use PassInstrument as much as possible. (Implementation also lives in `TargetPassConfig.cpp`) - `TargetPassConfig` is a polymorphic base (virtual inheritance) to build the target-dependent pipeline whereas `CodeGenPassBuilder` is the CRTP base/helper to implement the target-dependent pipeline. The motivation is flexibility for targets to customize the pipeline, inlining opportunity, and fits the overall NPM value semantics design. - `TargetPassConfig` is a legacy immutable pass to declare hooks for targets to customize some target-independent codegen layer behavior. This is partially ported to TargetMachine::options. The rest, such as `createMachineScheduler/createPostMachineScheduler`, are left out for now. They should be implemented in LLVMTargetMachine in the future. Reviewed By: arsenm, aeubanks Differential Revision: https://reviews.llvm.org/D83608
- Loading branch information
Yuanfang Chen
committed
Dec 29, 2020
1 parent
f782d5e
commit 4646de5
Showing
9 changed files
with
1,640 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
//===- MachinePassRegistry.def - Registry of passes -------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is used as the registry of passes that are for target-independent | ||
// code generator. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// NOTE: NO INCLUDE GUARD DESIRED! | ||
|
||
#ifndef MODULE_ANALYSIS | ||
#define MODULE_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
MODULE_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis, (PIC)) | ||
#undef MODULE_ANALYSIS | ||
|
||
#ifndef MODULE_PASS | ||
#define MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
MODULE_PASS("pre-isel-intrinsic-lowering", PreISelIntrinsicLoweringPass, ()) | ||
#undef MODULE_PASS | ||
|
||
#ifndef FUNCTION_ANALYSIS | ||
#define FUNCTION_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis, (PIC)) | ||
FUNCTION_ANALYSIS("targetir", TargetIRAnalysis, (std::move(TM.getTargetIRAnalysis()))) | ||
#undef FUNCTION_ANALYSIS | ||
|
||
#ifndef FUNCTION_PASS | ||
#define FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
FUNCTION_PASS("mergeicmps", MergeICmpsPass, ()) | ||
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass, ()) | ||
FUNCTION_PASS("unreachableblockelim", UnreachableBlockElimPass, ()) | ||
FUNCTION_PASS("consthoist", ConstantHoistingPass, ()) | ||
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass, ()) | ||
FUNCTION_PASS("ee-instrument", EntryExitInstrumenterPass, (false)) | ||
FUNCTION_PASS("post-inline-ee-instrument", EntryExitInstrumenterPass, (true)) | ||
FUNCTION_PASS("expand-reductions", ExpandReductionsPass, ()) | ||
FUNCTION_PASS("lowerinvoke", LowerInvokePass, ()) | ||
FUNCTION_PASS("verify", VerifierPass, ()) | ||
#undef FUNCTION_PASS | ||
|
||
#ifndef LOOP_PASS | ||
#define LOOP_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
LOOP_PASS("loop-reduce", LoopStrengthReducePass, ()) | ||
#undef LOOP_PASS | ||
|
||
#ifndef MACHINE_MODULE_PASS | ||
#define MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
#undef MACHINE_MODULE_PASS | ||
|
||
#ifndef MACHINE_FUNCTION_ANALYSIS | ||
#define MACHINE_FUNCTION_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis, (PIC)) | ||
// LiveVariables currently requires pure SSA form. | ||
// FIXME: Once TwoAddressInstruction pass no longer uses kill flags, | ||
// LiveVariables can be removed completely, and LiveIntervals can be directly | ||
// computed. (We still either need to regenerate kill flags after regalloc, or | ||
// preferably fix the scavenger to not depend on them). | ||
// MACHINE_FUNCTION_ANALYSIS("live-vars", LiveVariablesAnalysis()) | ||
|
||
// MACHINE_FUNCTION_ANALYSIS("live-stacks", LiveStacksPass()) | ||
// MACHINE_FUNCTION_ANALYSIS("slot-indexes", SlotIndexesAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("edge-bundles", EdgeBundlesAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("lazy-machine-bfi", LazyMachineBlockFrequencyInfoAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-bfi", MachineBlockFrequencyInfoAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopInfoAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-dom-frontier", MachineDominanceFrontierAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-ore", MachineOptimizationRemarkEmitterPassAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree", MachinePostDominatorTreeAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-region-info", MachineRegionInfoPassAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("machine-trace-metrics", MachineTraceMetricsAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("reaching-def", ReachingDefAnalysisAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("live-reg-matrix", LiveRegMatrixAnalysis()) | ||
// MACHINE_FUNCTION_ANALYSIS("gc-analysis", GCMachineCodeAnalysisPass()) | ||
#undef MACHINE_FUNCTION_ANALYSIS | ||
|
||
#ifndef MACHINE_FUNCTION_PASS | ||
#define MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
// MACHINE_FUNCTION_PASS("mir-printer", PrintMIRPass, ()) | ||
// MACHINE_FUNCTION_PASS("free-machine-function", FreeMachineFunctionPass, ()) | ||
#undef MACHINE_FUNCTION_PASS | ||
|
||
// After a pass is converted to new pass manager, its entry should be moved from | ||
// dummy table to the normal one. For example, for a machine function pass, | ||
// DUMMY_MACHINE_FUNCTION_PASS to MACHINE_FUNCTION_PASS. | ||
|
||
#ifndef DUMMY_FUNCTION_PASS | ||
#define DUMMY_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
DUMMY_FUNCTION_PASS("expandmemcmp", ExpandMemCmpPass, ()) | ||
DUMMY_FUNCTION_PASS("gc-lowering", GCLoweringPass, ()) | ||
DUMMY_FUNCTION_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass, ()) | ||
DUMMY_FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass, ()) | ||
DUMMY_FUNCTION_PASS("sjljehprepare", SjLjEHPreparePass, ()) | ||
DUMMY_FUNCTION_PASS("dwarfehprepare", DwarfEHPass, ()) | ||
DUMMY_FUNCTION_PASS("winehprepare", WinEHPass, ()) | ||
DUMMY_FUNCTION_PASS("wasmehprepare", WasmEHPass, ()) | ||
DUMMY_FUNCTION_PASS("codegenprepare", CodeGenPreparePass, ()) | ||
DUMMY_FUNCTION_PASS("safe-stack", SafeStackPass, ()) | ||
DUMMY_FUNCTION_PASS("stack-protector", StackProtectorPass, ()) | ||
DUMMY_FUNCTION_PASS("atomic-expand", AtomicExpandPass, ()) | ||
DUMMY_FUNCTION_PASS("interleaved-access", InterleavedAccessPass, ()) | ||
DUMMY_FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, ()) | ||
DUMMY_FUNCTION_PASS("cfguard-dispatch", CFGuardDispatchPass, ()) | ||
DUMMY_FUNCTION_PASS("cfguard-check", CFGuardCheckPass, ()) | ||
DUMMY_FUNCTION_PASS("gc-info-printer", GCInfoPrinterPass, ()) | ||
#undef DUMMY_FUNCTION_PASS | ||
|
||
#ifndef DUMMY_MODULE_PASS | ||
#define DUMMY_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
DUMMY_MODULE_PASS("lower-emutls", LowerEmuTLSPass, ()) | ||
#undef DUMMY_MODULE_PASS | ||
|
||
#ifndef DUMMY_MACHINE_MODULE_PASS | ||
#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
DUMMY_MACHINE_MODULE_PASS("machine-outliner", MachineOutlinerPass, ()) | ||
#undef DUMMY_MACHINE_MODULE_PASS | ||
|
||
#ifndef DUMMY_MACHINE_FUNCTION_PASS | ||
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) | ||
#endif | ||
DUMMY_MACHINE_FUNCTION_PASS("mir-printer", PrintMIRPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("free-machine-function", FreeMachineFunctionPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("localstackalloc", LocalStackSlotPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("shrink-wrap", ShrinkWrapPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("postrapseudos", ExpandPostRAPseudosPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("implicit-null-checks", ImplicitNullChecksPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("postmisched", PostMachineSchedulerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machine-scheduler", MachineSchedulerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("post-RA-sched", PostRASchedulerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("fentry-insert", FEntryInserterPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("stackmap-liveness", StackMapLivenessPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("livedebugvalues", LiveDebugValuesPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("early-tailduplication", EarlyTailDuplicatePass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("opt-phis", OptimizePHIsPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machinelicm", MachineLICMPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machine-sink", MachineSinkingPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("peephole-opt", PeepholeOptimizerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("virtregrewriter", VirtRegRewriterPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("stack-slot-coloring", StackSlotColoringPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("phi-node-elimination", PHIEliminationPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("twoaddressinstruction", TwoAddressInstructionPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("liveintervals", LiveIntervalsPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("simple-register-coalescing", RegisterCoalescerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("rename-independent-subregs", RenameIndependentSubregsPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("branch-folder", BranchFolderPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("tailduplication", TailDuplicatePass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("block-placement", MachineBlockPlacementPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machine-combiner", MachineCombinerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("ra-fast", RAFastPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("legalizer", LegalizerPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("irtranslator", IRTranslatorPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("reset-machine-function", ResetMachineFunctionPass, ()) | ||
DUMMY_MACHINE_FUNCTION_PASS("machineverifier", MachineVerifierPass, ()) | ||
#undef DUMMY_MACHINE_FUNCTION_PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//===- CGPassBuilderOption.h - Options for pass builder ---------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file declares the CCState and CCValAssign classes, used for lowering | ||
// and implementing calling conventions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CODEGEN_PASSBUILDER_OPTION_H | ||
#define LLVM_CODEGEN_PASSBUILDER_OPTION_H | ||
|
||
#include "llvm/ADT/Optional.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Target/TargetOptions.h" | ||
#include <vector> | ||
|
||
namespace llvm { | ||
class TargetMachine; | ||
|
||
enum class RunOutliner { TargetDefault, AlwaysOutline, NeverOutline }; | ||
enum class RegAllocType { Default, Basic, Fast, Greedy, PBQP }; | ||
enum class CFLAAType { None, Steensgaard, Andersen, Both }; | ||
|
||
// Not one-on-one but mostly corresponding to commandline options in | ||
// TargetPassConfig.cpp. | ||
struct CGPassBuilderOption { | ||
Optional<bool> OptimizeRegAlloc; | ||
Optional<bool> EnableIPRA; | ||
bool DebugPM = false; | ||
bool DisableVerify = false; | ||
bool EnableImplicitNullChecks = false; | ||
bool EnableBlockPlacementStats = false; | ||
bool MISchedPostRA = false; | ||
bool EarlyLiveIntervals = false; | ||
|
||
bool DisableLSR = false; | ||
bool DisableCGP = false; | ||
bool PrintLSR = false; | ||
bool DisableMergeICmps = false; | ||
bool DisablePartialLibcallInlining = false; | ||
bool DisableConstantHoisting = false; | ||
bool PrintISelInput = false; | ||
bool PrintGCInfo = false; | ||
bool RequiresCodeGenSCCOrder = false; | ||
|
||
RunOutliner EnableMachineOutliner = RunOutliner::TargetDefault; | ||
RegAllocType RegAlloc = RegAllocType::Default; | ||
CFLAAType UseCFLAA = CFLAAType::None; | ||
Optional<GlobalISelAbortMode> EnableGlobalISelAbort; | ||
|
||
Optional<bool> VerifyMachineCode; | ||
Optional<bool> EnableFastISelOption; | ||
Optional<bool> EnableGlobalISelOption; | ||
}; | ||
|
||
CGPassBuilderOption getCGPassBuilderOption(); | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_PASSBUILDER_OPTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===--- CodeGenPassBuilder.cpp --------------------------------------- ---===// | ||
// | ||
// 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 defines interfaces to access the target independent code | ||
// generation passes provided by the LLVM backend. | ||
// | ||
//===---------------------------------------------------------------------===// | ||
|
||
#include "llvm/CodeGen/CodeGenPassBuilder.h" | ||
|
||
using namespace llvm; | ||
|
||
namespace llvm { | ||
#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \ | ||
AnalysisKey PASS_NAME::Key; | ||
#include "llvm/CodeGen/MachinePassRegistry.def" | ||
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \ | ||
AnalysisKey PASS_NAME::Key; | ||
#include "llvm/CodeGen/MachinePassRegistry.def" | ||
} // namespace llvm |
Oops, something went wrong.