xref: /freebsd/contrib/llvm-project/llvm/lib/Transforms/IPO/IPO.cpp (revision 77013d11e6483b970af25e13c9b892075742f7e5)
1 //===-- IPO.cpp -----------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the common infrastructure (including C bindings) for
10 // libLLVMIPO.a, which implements several transformations over the LLVM
11 // intermediate representation.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm-c/Transforms/IPO.h"
16 #include "llvm-c/Initialization.h"
17 #include "llvm/IR/LegacyPassManager.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Transforms/IPO.h"
20 #include "llvm/Transforms/IPO/AlwaysInliner.h"
21 #include "llvm/Transforms/IPO/FunctionAttrs.h"
22 
23 using namespace llvm;
24 
25 void llvm::initializeIPO(PassRegistry &Registry) {
26   initializeOpenMPOptLegacyPassPass(Registry);
27   initializeArgPromotionPass(Registry);
28   initializeAnnotation2MetadataLegacyPass(Registry);
29   initializeCalledValuePropagationLegacyPassPass(Registry);
30   initializeConstantMergeLegacyPassPass(Registry);
31   initializeCrossDSOCFIPass(Registry);
32   initializeDAEPass(Registry);
33   initializeDAHPass(Registry);
34   initializeForceFunctionAttrsLegacyPassPass(Registry);
35   initializeGlobalDCELegacyPassPass(Registry);
36   initializeGlobalOptLegacyPassPass(Registry);
37   initializeGlobalSplitPass(Registry);
38   initializeHotColdSplittingLegacyPassPass(Registry);
39   initializeIROutlinerLegacyPassPass(Registry);
40   initializeAlwaysInlinerLegacyPassPass(Registry);
41   initializeSimpleInlinerPass(Registry);
42   initializeInferFunctionAttrsLegacyPassPass(Registry);
43   initializeInternalizeLegacyPassPass(Registry);
44   initializeLoopExtractorLegacyPassPass(Registry);
45   initializeBlockExtractorLegacyPassPass(Registry);
46   initializeSingleLoopExtractorPass(Registry);
47   initializeLowerTypeTestsPass(Registry);
48   initializeMergeFunctionsLegacyPassPass(Registry);
49   initializePartialInlinerLegacyPassPass(Registry);
50   initializeAttributorLegacyPassPass(Registry);
51   initializeAttributorCGSCCLegacyPassPass(Registry);
52   initializePostOrderFunctionAttrsLegacyPassPass(Registry);
53   initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
54   initializePruneEHPass(Registry);
55   initializeIPSCCPLegacyPassPass(Registry);
56   initializeStripDeadPrototypesLegacyPassPass(Registry);
57   initializeStripSymbolsPass(Registry);
58   initializeStripDebugDeclarePass(Registry);
59   initializeStripDeadDebugInfoPass(Registry);
60   initializeStripNonDebugSymbolsPass(Registry);
61   initializeBarrierNoopPass(Registry);
62   initializeEliminateAvailableExternallyLegacyPassPass(Registry);
63   initializeSampleProfileLoaderLegacyPassPass(Registry);
64   initializeFunctionImportLegacyPassPass(Registry);
65   initializeWholeProgramDevirtPass(Registry);
66 }
67 
68 void LLVMInitializeIPO(LLVMPassRegistryRef R) {
69   initializeIPO(*unwrap(R));
70 }
71 
72 void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) {
73   unwrap(PM)->add(createArgumentPromotionPass());
74 }
75 
76 void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) {
77   unwrap(PM)->add(createCalledValuePropagationPass());
78 }
79 
80 void LLVMAddConstantMergePass(LLVMPassManagerRef PM) {
81   unwrap(PM)->add(createConstantMergePass());
82 }
83 
84 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) {
85   unwrap(PM)->add(createDeadArgEliminationPass());
86 }
87 
88 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) {
89   unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass());
90 }
91 
92 void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) {
93   unwrap(PM)->add(createFunctionInliningPass());
94 }
95 
96 void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) {
97   unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass());
98 }
99 
100 void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) {
101   unwrap(PM)->add(createGlobalDCEPass());
102 }
103 
104 void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) {
105   unwrap(PM)->add(createGlobalOptimizerPass());
106 }
107 
108 void LLVMAddPruneEHPass(LLVMPassManagerRef PM) {
109   unwrap(PM)->add(createPruneEHPass());
110 }
111 
112 void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) {
113   unwrap(PM)->add(createIPSCCPPass());
114 }
115 
116 void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM) {
117   unwrap(PM)->add(createMergeFunctionsPass());
118 }
119 
120 void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
121   auto PreserveMain = [=](const GlobalValue &GV) {
122     return AllButMain && GV.getName() == "main";
123   };
124   unwrap(PM)->add(createInternalizePass(PreserveMain));
125 }
126 
127 void LLVMAddInternalizePassWithMustPreservePredicate(
128     LLVMPassManagerRef PM,
129     void *Context,
130     LLVMBool (*Pred)(LLVMValueRef, void *)) {
131   unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
132     return Pred(wrap(&GV), Context) == 0 ? false : true;
133   }));
134 }
135 
136 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
137   unwrap(PM)->add(createStripDeadPrototypesPass());
138 }
139 
140 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) {
141   unwrap(PM)->add(createStripSymbolsPass());
142 }
143