Skip to content
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

[LLVM][NewPM] Add a C API for setting the PassBuilder AA pipeline. #102482

Merged
merged 1 commit into from
Aug 14, 2024
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
8 changes: 8 additions & 0 deletions llvm/include/llvm-c/Transforms/PassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ void LLVMPassBuilderOptionsSetVerifyEach(LLVMPassBuilderOptionsRef Options,
void LLVMPassBuilderOptionsSetDebugLogging(LLVMPassBuilderOptionsRef Options,
LLVMBool DebugLogging);

/**
* Specify a custom alias analysis pipeline for the PassBuilder to be used
* instead of the default one. The string argument is not copied; the caller
* is responsible for ensuring it outlives the PassBuilderOptions instance.
*/
void LLVMPassBuilderOptionsSetAAPipeline(LLVMPassBuilderOptionsRef Options,
const char *AAPipeline);

void LLVMPassBuilderOptionsSetLoopInterleaving(
LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving);

Expand Down
19 changes: 18 additions & 1 deletion llvm/lib/Passes/PassBuilderBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//

#include "llvm-c/Transforms/PassBuilder.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Passes/PassBuilder.h"
Expand All @@ -28,11 +29,14 @@ class LLVMPassBuilderOptions {
public:
explicit LLVMPassBuilderOptions(
bool DebugLogging = false, bool VerifyEach = false,
const char *AAPipeline = nullptr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVMPassBuilderOptions is never constructed with params. the constructor shouldn't take any arguments.

I'll do this in a followup patch

PipelineTuningOptions PTO = PipelineTuningOptions())
: DebugLogging(DebugLogging), VerifyEach(VerifyEach), PTO(PTO) {}
: DebugLogging(DebugLogging), VerifyEach(VerifyEach),
AAPipeline(AAPipeline), PTO(PTO) {}

bool DebugLogging;
bool VerifyEach;
const char *AAPipeline;
PipelineTuningOptions PTO;
};
} // namespace llvm
Expand Down Expand Up @@ -60,6 +64,14 @@ LLVMErrorRef LLVMRunPasses(LLVMModuleRef M, const char *Passes,
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
if (PassOpts->AAPipeline) {
maleadt marked this conversation as resolved.
Show resolved Hide resolved
// If we have a custom AA pipeline, we need to register it _before_ calling
// registerFunctionAnalyses, or the default alias analysis pipeline is used.
AAManager AA;
if (auto Err = PB.parseAAPipeline(AA, PassOpts->AAPipeline))
return wrap(std::move(Err));
FAM.registerPass([&] { return std::move(AA); });
}
PB.registerLoopAnalyses(LAM);
PB.registerFunctionAnalyses(FAM);
PB.registerCGSCCAnalyses(CGAM);
Expand Down Expand Up @@ -94,6 +106,11 @@ void LLVMPassBuilderOptionsSetDebugLogging(LLVMPassBuilderOptionsRef Options,
unwrap(Options)->DebugLogging = DebugLogging;
}

void LLVMPassBuilderOptionsSetAAPipeline(LLVMPassBuilderOptionsRef Options,
const char *AAPipeline) {
unwrap(Options)->AAPipeline = AAPipeline;
}

void LLVMPassBuilderOptionsSetLoopInterleaving(
LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving) {
unwrap(Options)->PTO.LoopInterleaving = LoopInterleaving;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TEST_F(PassBuilderCTest, Basic) {
LLVMPassBuilderOptionsSetLoopUnrolling(Options, 1);
LLVMPassBuilderOptionsSetVerifyEach(Options, 1);
LLVMPassBuilderOptionsSetDebugLogging(Options, 0);
LLVMPassBuilderOptionsSetAAPipeline(Options, "basic-aa");
if (LLVMErrorRef E = LLVMRunPasses(Module, "default<O2>", TM, Options)) {
char *Msg = LLVMGetErrorMessage(E);
LLVMConsumeError(E);
Expand Down
Loading