-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[SandboxIR] PassManager #107932
Merged
Merged
[SandboxIR] PassManager #107932
Changes from all commits
Commits
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 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,70 @@ | ||
//===- PassManager.h --------------------------------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Registers and executes the Sandbox IR passes. | ||
// | ||
// The pass manager contains an ordered sequence of passes that it runs in | ||
// order. The passes are owned by the PassRegistry, not by the PassManager. | ||
// | ||
// Note that in this design a pass manager is also a pass. So a pass manager | ||
// runs when it is it's turn to run in its parent pass-manager pass pipeline. | ||
// | ||
|
||
#ifndef LLVM_SANDBOXIR_PASSMANAGER_H | ||
#define LLVM_SANDBOXIR_PASSMANAGER_H | ||
|
||
#include "llvm/ADT/STLExtras.h" | ||
#include "llvm/SandboxIR/Pass.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
namespace llvm::sandboxir { | ||
|
||
class Value; | ||
|
||
/// Base class. | ||
template <typename ParentPass, typename ContainedPass> | ||
class PassManager : public ParentPass { | ||
protected: | ||
/// The list of passes that this pass manager will run. | ||
SmallVector<ContainedPass *> Passes; | ||
|
||
PassManager(StringRef Name) : ParentPass(Name) {} | ||
PassManager(const PassManager &) = delete; | ||
virtual ~PassManager() = default; | ||
PassManager &operator=(const PassManager &) = delete; | ||
|
||
public: | ||
/// Adds \p Pass to the pass pipeline. | ||
void addPass(ContainedPass *Pass) { | ||
// TODO: Check that Pass's class type works with this PassManager type. | ||
Passes.push_back(Pass); | ||
} | ||
#ifndef NDEBUG | ||
void print(raw_ostream &OS) const override { | ||
OS << this->getName(); | ||
OS << "("; | ||
interleave(Passes, OS, [&OS](auto *Pass) { OS << Pass->getName(); }, ","); | ||
OS << ")"; | ||
} | ||
LLVM_DUMP_METHOD void dump() const override { | ||
print(dbgs()); | ||
dbgs() << "\n"; | ||
} | ||
#endif | ||
}; | ||
|
||
class FunctionPassManager final | ||
: public PassManager<FunctionPass, FunctionPass> { | ||
public: | ||
FunctionPassManager(StringRef Name) : PassManager(Name) {} | ||
bool runOnFunction(Function &F) final; | ||
}; | ||
|
||
} // namespace llvm::sandboxir | ||
|
||
#endif // LLVM_SANDBOXIR_PASSMANAGER_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
add_llvm_component_library(LLVMSandboxIR | ||
Pass.cpp | ||
PassManager.cpp | ||
SandboxIR.cpp | ||
Tracker.cpp | ||
Type.cpp | ||
|
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,22 @@ | ||
//===- PassManager.cpp - Runs a pipeline of Sandbox IR passes -------------===// | ||
// | ||
// 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 "llvm/SandboxIR/PassManager.h" | ||
#include "llvm/SandboxIR/SandboxIR.h" | ||
|
||
using namespace llvm::sandboxir; | ||
|
||
bool FunctionPassManager::runOnFunction(Function &F) { | ||
bool Change = false; | ||
for (FunctionPass *Pass : Passes) { | ||
Change |= Pass->runOnFunction(F); | ||
// TODO: run the verifier. | ||
} | ||
// TODO: Check ChangeAll against hashes before/after. | ||
return Change; | ||
} |
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
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.
it seems error prone for the pass manager to not own the pass (e.g. stack references). e.g. in the new pass manager if you want to run a pass multiple times, you just create multiple instances of it
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.
The pass registry would own the passes and would also provide the name-to-pass lookup so that you can build the pipeline from a pipeline string like "pass1,pass2".
If the pass manager owns the passes, then how is the mapping from names to passes handled?
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.
see includes of
PassRegistry.def
, especially inPassBuilder.cpp
. it's basically a string comparison chainI think your way is fine, as long as your explanation of the registry owning passes is documented
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.
I see, it shouldn't be too hard to follow a similar design. Let me try it out.
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.
I think I will stick with this design for now. Using a PassRegistry.def complicates the design quite a bit and I am not sure it is worth it at this point. We can revisit it later if needed.