12
12
// ===----------------------------------------------------------------------===//
13
13
14
14
#include " llvm-c/Transforms/PassBuilder.h"
15
+ #include " llvm/Analysis/AliasAnalysis.h"
15
16
#include " llvm/IR/Module.h"
16
17
#include " llvm/IR/Verifier.h"
17
18
#include " llvm/Passes/PassBuilder.h"
@@ -28,11 +29,14 @@ class LLVMPassBuilderOptions {
28
29
public:
29
30
explicit LLVMPassBuilderOptions (
30
31
bool DebugLogging = false , bool VerifyEach = false ,
32
+ const char *AAPipeline = nullptr ,
31
33
PipelineTuningOptions PTO = PipelineTuningOptions())
32
- : DebugLogging(DebugLogging), VerifyEach(VerifyEach), PTO(PTO) {}
34
+ : DebugLogging(DebugLogging), VerifyEach(VerifyEach),
35
+ AAPipeline(AAPipeline), PTO(PTO) {}
33
36
34
37
bool DebugLogging;
35
38
bool VerifyEach;
39
+ const char *AAPipeline;
36
40
PipelineTuningOptions PTO;
37
41
};
38
42
} // namespace llvm
@@ -60,6 +64,14 @@ LLVMErrorRef LLVMRunPasses(LLVMModuleRef M, const char *Passes,
60
64
FunctionAnalysisManager FAM;
61
65
CGSCCAnalysisManager CGAM;
62
66
ModuleAnalysisManager MAM;
67
+ if (PassOpts->AAPipeline ) {
68
+ // If we have a custom AA pipeline, we need to register it _before_ calling
69
+ // registerFunctionAnalyses, or the default alias analysis pipeline is used.
70
+ AAManager AA;
71
+ if (auto Err = PB.parseAAPipeline (AA, PassOpts->AAPipeline ))
72
+ return wrap (std::move (Err));
73
+ FAM.registerPass ([&] { return std::move (AA); });
74
+ }
63
75
PB.registerLoopAnalyses (LAM);
64
76
PB.registerFunctionAnalyses (FAM);
65
77
PB.registerCGSCCAnalyses (CGAM);
@@ -94,6 +106,11 @@ void LLVMPassBuilderOptionsSetDebugLogging(LLVMPassBuilderOptionsRef Options,
94
106
unwrap (Options)->DebugLogging = DebugLogging;
95
107
}
96
108
109
+ void LLVMPassBuilderOptionsSetAAPipeline (LLVMPassBuilderOptionsRef Options,
110
+ const char *AAPipeline) {
111
+ unwrap (Options)->AAPipeline = AAPipeline;
112
+ }
113
+
97
114
void LLVMPassBuilderOptionsSetLoopInterleaving (
98
115
LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving) {
99
116
unwrap (Options)->PTO .LoopInterleaving = LoopInterleaving;
0 commit comments