@@ -48,24 +48,12 @@ static TargetMachine *unwrap(LLVMTargetMachineRef P) {
48
48
DEFINE_SIMPLE_CONVERSION_FUNCTIONS (LLVMPassBuilderOptions,
49
49
LLVMPassBuilderOptionsRef)
50
50
51
- LLVMErrorRef RunPasses(LLVMModuleRef M, LLVMValueRef F, const char *Passes,
52
- LLVMTargetMachineRef TM,
53
- LLVMPassBuilderOptionsRef Options) {
54
- TargetMachine *Machine = unwrap (TM);
55
- LLVMPassBuilderOptions *PassOpts = unwrap (Options);
51
+ static LLVMErrorRef runPasses(Module *Mod, Function *Fun, const char *Passes,
52
+ TargetMachine *Machine,
53
+ LLVMPassBuilderOptions *PassOpts) {
56
54
bool Debug = PassOpts->DebugLogging ;
57
55
bool VerifyEach = PassOpts->VerifyEach ;
58
56
59
- // Determine what to run passes on.
60
- Module *Mod;
61
- Function *Fun = nullptr ;
62
- if (F) {
63
- Fun = unwrap<Function>(F);
64
- Mod = Fun->getParent ();
65
- } else {
66
- Mod = unwrap (M);
67
- }
68
-
69
57
PassInstrumentationCallbacks PIC;
70
58
PassBuilder PB (Machine, PassOpts->PTO , std::nullopt, &PIC);
71
59
@@ -113,13 +101,19 @@ LLVMErrorRef RunPasses(LLVMModuleRef M, LLVMValueRef F, const char *Passes,
113
101
LLVMErrorRef LLVMRunPasses (LLVMModuleRef M, const char *Passes,
114
102
LLVMTargetMachineRef TM,
115
103
LLVMPassBuilderOptionsRef Options) {
116
- return RunPasses (M, nullptr , Passes, TM, Options);
104
+ TargetMachine *Machine = unwrap (TM);
105
+ LLVMPassBuilderOptions *PassOpts = unwrap (Options);
106
+ Module *Mod = unwrap (M);
107
+ return runPasses (Mod, nullptr , Passes, Machine, PassOpts);
117
108
}
118
109
119
110
LLVMErrorRef LLVMRunPassesOnFunction (LLVMValueRef F, const char *Passes,
120
111
LLVMTargetMachineRef TM,
121
112
LLVMPassBuilderOptionsRef Options) {
122
- return RunPasses (nullptr , F, Passes, TM, Options);
113
+ TargetMachine *Machine = unwrap (TM);
114
+ LLVMPassBuilderOptions *PassOpts = unwrap (Options);
115
+ Function *Fun = unwrap<Function>(F);
116
+ return runPasses (Fun->getParent (), Fun, Passes, Machine, PassOpts);
123
117
}
124
118
125
119
LLVMPassBuilderOptionsRef LLVMCreatePassBuilderOptions () {
0 commit comments