-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NewPM][CodeGen][WIP] Add callback style CodeGen pass pipeline builder #104725
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,14 +15,17 @@ | |
#ifndef LLVM_PASSES_PASSBUILDER_H | ||
#define LLVM_PASSES_PASSBUILDER_H | ||
|
||
#include "llvm/ADT/StringSet.h" | ||
#include "llvm/Analysis/CGSCCPassManager.h" | ||
#include "llvm/CodeGen/MachinePassManager.h" | ||
#include "llvm/CodeGen/RegAllocCommon.h" | ||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Passes/OptimizationLevel.h" | ||
#include "llvm/Support/CodeGen.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/PGOOptions.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "llvm/Target/CGPassBuilderOption.h" | ||
#include "llvm/Transforms/IPO/Inliner.h" | ||
#include "llvm/Transforms/IPO/ModuleInliner.h" | ||
#include "llvm/Transforms/Instrumentation.h" | ||
|
@@ -35,6 +38,7 @@ class StringRef; | |
class AAManager; | ||
class TargetMachine; | ||
class ModuleSummaryIndex; | ||
class MCContext; | ||
template <typename T> class IntrusiveRefCntPtr; | ||
namespace vfs { | ||
class FileSystem; | ||
|
@@ -307,6 +311,22 @@ class PassBuilder { | |
/// TargetMachine::registerDefaultAliasAnalyses(). | ||
AAManager buildDefaultAAPipeline(); | ||
|
||
/// Build CodeGen pass pipeline. | ||
/// | ||
/// {{@ | ||
Expected<ModulePassManager> | ||
buildDefaultCodeGenPipeline(raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, | ||
CodeGenFileType FileType, MCContext &Ctx); | ||
Error buildDefaultCodeGenPipeline(ModulePassManager &MPM, | ||
raw_pwrite_stream &Out, | ||
raw_pwrite_stream *DwoOut, | ||
CodeGenFileType FileType, MCContext &Ctx); | ||
Error addRegAllocPass(MachineFunctionPassManager &MFPM, StringRef Filter); | ||
template <typename... PassTs> void disablePass() { | ||
(DisabledPasses.insert(PassTs::name()), ...); | ||
} | ||
/// @}} | ||
|
||
/// Parse a textual pass pipeline description into a \c | ||
/// ModulePassManager. | ||
/// | ||
|
@@ -519,6 +539,106 @@ class PassBuilder { | |
FullLinkTimeOptimizationLastEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerGCLoweringEPCallback( | ||
const std::function<void(FunctionPassManager &)> C) { | ||
GCLoweringEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerISelPrepareEPCallback( | ||
const std::function<void(ModulePassManager &)> &C) { | ||
ISelPrepareEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerMachineSSAOptimizationEarlyEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
MachineSSAOptimizationEarlyEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerILPOptsEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
ILPOptsEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerMachineSSAOptimizationLastEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
MachineSSAOptimizationLastEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPreRegAllocEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PreRegAllocEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPostRegAllocEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PostRegAllocEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPreRegBankSelectEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PreRegBankSelectEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPreGlobalInstructionSelectEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PreGlobalInstructionSelectEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPostGlobalInstructionSelectEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PostGlobalInstructionSelectEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerMachineLateOptimizationEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
MachineLateOptimizationEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPreSched2EPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PreSched2EPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPostRewriteEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PostRewriteEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPreEmitEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PreEmitEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerPostBBSectionsEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
PostBBSectionsEPCallbacks.push_back(C); | ||
} | ||
|
||
void registerMIEmitEPCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
MIEmitEPCallbacks.push_back(C); | ||
} | ||
|
||
void setAddInstSelectorCallback( | ||
const std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
&C) { | ||
AddInstSelectorCallback = C; | ||
} | ||
|
||
/// Register a callback for parsing an AliasAnalysis Name to populate | ||
/// the given AAManager \p AA | ||
void registerParseAACallback( | ||
|
@@ -639,6 +759,39 @@ class PassBuilder { | |
OptimizationLevel Level); | ||
void invokePipelineEarlySimplificationEPCallbacks(ModulePassManager &MPM, | ||
OptimizationLevel Level); | ||
void invokeGCLoweringEPCallbacks(FunctionPassManager &FPM); | ||
void invokeISelPrepareEPCallbacks(ModulePassManager &MPM); | ||
void | ||
invokeMachineSSAOptimizationEarlyEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void | ||
invokeMachineSSAOptimizationLastEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokePreRegAllocEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokePostRegAllocEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokePreRegBankSelectEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void | ||
invokePreGlobalInstructionSelectEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void | ||
invokePostGlobalInstructionSelectEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokeILPOptsEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void | ||
invokeMachineLateOptimizationEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokePreEmitEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokePostBBSectionsEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokeMIEmitEPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
void invokePreSched2EPCallbacks(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
|
||
static bool checkParametrizedPassName(StringRef Name, StringRef PassName) { | ||
if (!Name.consume_front(PassName)) | ||
|
@@ -704,6 +857,19 @@ class PassBuilder { | |
void addVectorPasses(OptimizationLevel Level, FunctionPassManager &FPM, | ||
bool IsFullLTO); | ||
|
||
Error addExceptionHandlingPasses(FunctionPassManager &FPM); | ||
|
||
Error addInstructionSelectorPasses(MachineFunctionPassManager &MFPM, | ||
const CGPassBuilderOption &Options); | ||
|
||
void addMachineSSAOptimizationPasses(MachineFunctionPassManager &MFPM, | ||
CodeGenOptLevel Level); | ||
|
||
Error addRegisterAllocatorPasses(MachineFunctionPassManager &MFPM, | ||
const CGPassBuilderOption &Options); | ||
|
||
Error setStartStop(ModulePassManager &MPM); | ||
|
||
static std::optional<std::vector<PipelineElement>> | ||
parsePipelineText(StringRef Text); | ||
|
||
|
@@ -766,6 +932,63 @@ class PassBuilder { | |
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2> | ||
PipelineEarlySimplificationEPCallbacks; | ||
|
||
// CodeGen extension point callbacks | ||
SmallVector<std::function<void(FunctionPassManager &)>, 2> | ||
GCLoweringEPCallbacks; | ||
SmallVector<std::function<void(ModulePassManager &)>, 2> | ||
ISelPrepareEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
MachineSSAOptimizationEarlyEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
MachineSSAOptimizationLastEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PreRegAllocEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PostRegAllocEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PreRegBankSelectEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PreGlobalInstructionSelectEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PostGlobalInstructionSelectEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
ILPOptsEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
MachineLateOptimizationEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PreSched2EPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PostRewriteEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
PreEmitEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a typedef for all of these repeated function types |
||
PostBBSectionsEPCallbacks; | ||
SmallVector< | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)>, 2> | ||
MIEmitEPCallbacks; | ||
|
||
std::function<void(CGPassBuilderOption &)> | ||
CodeGenPassPipelineTunningCallback = [](CGPassBuilderOption &) {}; | ||
std::function<void(MachineFunctionPassManager &, CodeGenOptLevel)> | ||
AddInstSelectorCallback; | ||
std::function<void(MachineFunctionPassManager &)> AddFastRegAllocCallback; | ||
std::function<void(PassBuilder &, MachineFunctionPassManager &)> | ||
AddOptimizedRegAllocCallback; | ||
StringSet<> DisabledPasses; | ||
|
||
SmallVector<std::function<void(ModuleAnalysisManager &)>, 2> | ||
ModuleAnalysisRegistrationCallbacks; | ||
SmallVector<std::function<bool(StringRef, ModulePassManager &, | ||
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for exactly? I'd hope we don't have to prune out unwanted pre-added passes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1