Skip to content

[AA] Change RunEarly to be a Boolean Flag in ExternalAAWrapper #139158

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

Merged
merged 3 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions llvm/include/llvm/Analysis/AliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,19 +1011,24 @@ struct ExternalAAWrapperPass : ImmutablePass {

ExternalAAWrapperPass();

explicit ExternalAAWrapperPass(CallbackT CB);
explicit ExternalAAWrapperPass(CallbackT CB, bool RunEarly = false);

/// Returns whether this external AA should run before Basic AA.
/// Flag indicating whether this external AA should run before Basic AA.
///
/// By default, external AA passes are run after Basic AA. If this returns
/// true, the external AA will be run before Basic AA during alias analysis.
/// This flag is for LegacyPassManager only. To run an external AA early
/// with the NewPassManager, override the registerEarlyDefaultAliasAnalyses
/// method on the target machine.
///
/// By default, external AA passes are run after Basic AA. If this flag is
/// set to true, the external AA will be run before Basic AA during alias
/// analysis.
///
/// For some targets, we prefer to run the external AA early to improve
/// compile time as it has more target-specific information. This is
/// particularly useful when the external AA can provide more precise results
/// than Basic AA so that Basic AA does not need to spend time recomputing
/// them.
virtual bool runEarly() { return false; }
bool RunEarly = false;

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ AnalysisKey AAManager::Key;

ExternalAAWrapperPass::ExternalAAWrapperPass() : ImmutablePass(ID) {}

ExternalAAWrapperPass::ExternalAAWrapperPass(CallbackT CB)
: ImmutablePass(ID), CB(std::move(CB)) {}
ExternalAAWrapperPass::ExternalAAWrapperPass(CallbackT CB, bool RunEarly)
: ImmutablePass(ID), CB(std::move(CB)), RunEarly(RunEarly) {}

char ExternalAAWrapperPass::ID = 0;

Expand Down Expand Up @@ -741,7 +741,7 @@ bool AAResultsWrapperPass::runOnFunction(Function &F) {

// Add any target-specific alias analyses that should be run early.
auto *ExtWrapperPass = getAnalysisIfAvailable<ExternalAAWrapperPass>();
if (ExtWrapperPass && ExtWrapperPass->runEarly() && ExtWrapperPass->CB) {
if (ExtWrapperPass && ExtWrapperPass->RunEarly && ExtWrapperPass->CB) {
LLVM_DEBUG(dbgs() << "AAResults register Early ExternalAA: "
<< ExtWrapperPass->getPassName() << "\n");
ExtWrapperPass->CB(*this, F, *AAR);
Expand Down Expand Up @@ -777,7 +777,7 @@ bool AAResultsWrapperPass::runOnFunction(Function &F) {

// If available, run an external AA providing callback over the results as
// well.
if (ExtWrapperPass && !ExtWrapperPass->runEarly() && ExtWrapperPass->CB) {
if (ExtWrapperPass && !ExtWrapperPass->RunEarly && ExtWrapperPass->CB) {
LLVM_DEBUG(dbgs() << "AAResults register Late ExternalAA: "
<< ExtWrapperPass->getPassName() << "\n");
ExtWrapperPass->CB(*this, F, *AAR);
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ class NVPTXExternalAAWrapper : public ExternalAAWrapperPass {
public:
static char ID;

bool runEarly() override { return true; }

NVPTXExternalAAWrapper()
: ExternalAAWrapperPass([](Pass &P, Function &, AAResults &AAR) {
if (auto *WrapperPass =
P.getAnalysisIfAvailable<NVPTXAAWrapperPass>())
AAR.addAAResult(WrapperPass->getResult());
}) {}
: ExternalAAWrapperPass(
[](Pass &P, Function &, AAResults &AAR) {
if (auto *WrapperPass =
P.getAnalysisIfAvailable<NVPTXAAWrapperPass>())
AAR.addAAResult(WrapperPass->getResult());
},
/*RunEarly=*/true) {}

StringRef getPassName() const override {
return "NVPTX Address space based Alias Analysis Wrapper";
Expand Down
Loading