1 //===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===//
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 header file defines prototypes for accessor functions that expose passes
10 // in the IPO transformations library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_IPO_H
15 #define LLVM_TRANSFORMS_IPO_H
16 
17 #include "llvm/ADT/SmallVector.h"
18 #include <functional>
19 #include <vector>
20 
21 namespace llvm {
22 
23 struct InlineParams;
24 class ModulePass;
25 class Pass;
26 class BasicBlock;
27 class GlobalValue;
28 class raw_ostream;
29 
30 //===----------------------------------------------------------------------===//
31 //
32 // This pass adds !annotation metadata to entries in the
33 // @llvm.global.annotations global constant.
34 //
35 ModulePass *createAnnotation2MetadataLegacyPass();
36 
37 //===----------------------------------------------------------------------===//
38 //
39 // These functions removes symbols from functions and modules.  If OnlyDebugInfo
40 // is true, only debugging information is removed from the module.
41 //
42 ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
43 
44 //===----------------------------------------------------------------------===//
45 //
46 // These functions strips symbols from functions and modules.
47 // Only debugging information is not stripped.
48 //
49 ModulePass *createStripNonDebugSymbolsPass();
50 
51 //===----------------------------------------------------------------------===//
52 //
53 // This pass removes llvm.dbg.declare intrinsics.
54 ModulePass *createStripDebugDeclarePass();
55 
56 //===----------------------------------------------------------------------===//
57 //
58 // This pass removes unused symbols' debug info.
59 ModulePass *createStripDeadDebugInfoPass();
60 
61 //===----------------------------------------------------------------------===//
62 /// createConstantMergePass - This function returns a new pass that merges
63 /// duplicate global constants together into a single constant that is shared.
64 /// This is useful because some passes (ie TraceValues) insert a lot of string
65 /// constants into the program, regardless of whether or not they duplicate an
66 /// existing string.
67 ///
68 ModulePass *createConstantMergePass();
69 
70 //===----------------------------------------------------------------------===//
71 /// createGlobalOptimizerPass - This function returns a new pass that optimizes
72 /// non-address taken internal globals.
73 ///
74 ModulePass *createGlobalOptimizerPass();
75 
76 //===----------------------------------------------------------------------===//
77 /// createGlobalDCEPass - This transform is designed to eliminate unreachable
78 /// internal globals (functions or global variables)
79 ///
80 ModulePass *createGlobalDCEPass();
81 
82 //===----------------------------------------------------------------------===//
83 /// This transform is designed to eliminate available external globals
84 /// (functions or global variables)
85 ///
86 ModulePass *createEliminateAvailableExternallyPass();
87 
88 //===----------------------------------------------------------------------===//
89 /// createGVExtractionPass - If deleteFn is true, this pass deletes
90 /// the specified global values. Otherwise, it deletes as much of the module as
91 /// possible, except for the global values specified. If keepConstInit is true,
92 /// the initializers of global constants are not deleted even if they are
93 /// unused.
94 ///
95 ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
96                                   deleteFn = false, bool keepConstInit = false);
97 
98 //===----------------------------------------------------------------------===//
99 /// createFunctionInliningPass - Return a new pass object that uses a heuristic
100 /// to inline direct function calls to small functions.
101 ///
102 /// The Threshold can be passed directly, or asked to be computed from the
103 /// given optimization and size optimization arguments.
104 ///
105 /// The -inline-threshold command line option takes precedence over the
106 /// threshold given here.
107 Pass *createFunctionInliningPass();
108 Pass *createFunctionInliningPass(int Threshold);
109 Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel,
110                                  bool DisableInlineHotCallSite);
111 Pass *createFunctionInliningPass(InlineParams &Params);
112 
113 //===----------------------------------------------------------------------===//
114 /// createInternalizePass - This pass loops over all of the functions in the
115 /// input module, internalizing all globals (functions and variables) it can.
116 ////
117 /// Before internalizing a symbol, the callback \p MustPreserveGV is invoked and
118 /// gives to the client the ability to prevent internalizing specific symbols.
119 ///
120 /// The symbol in DSOList are internalized if it is safe to drop them from
121 /// the symbol table.
122 ///
123 /// Note that commandline options that are used with the above function are not
124 /// used now!
125 ModulePass *
126 createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV);
127 
128 /// createInternalizePass - Same as above, but with an empty exportList.
129 ModulePass *createInternalizePass();
130 
131 //===----------------------------------------------------------------------===//
132 /// createDeadArgEliminationPass - This pass removes arguments from functions
133 /// which are not used by the body of the function.
134 ///
135 ModulePass *createDeadArgEliminationPass();
136 
137 /// DeadArgHacking pass - Same as DAE, but delete arguments of external
138 /// functions as well.  This is definitely not safe, and should only be used by
139 /// bugpoint.
140 ModulePass *createDeadArgHackingPass();
141 
142 //===----------------------------------------------------------------------===//
143 /// createIPSCCPPass - This pass propagates constants from call sites into the
144 /// bodies of functions, and keeps track of whether basic blocks are executable
145 /// in the process.
146 ///
147 ModulePass *createIPSCCPPass();
148 
149 //===----------------------------------------------------------------------===//
150 //
151 /// createLoopExtractorPass - This pass extracts all natural loops from the
152 /// program into a function if it can.
153 ///
154 Pass *createLoopExtractorPass();
155 
156 /// createSingleLoopExtractorPass - This pass extracts one natural loop from the
157 /// program into a function if it can.  This is used by bugpoint.
158 ///
159 Pass *createSingleLoopExtractorPass();
160 
161 /// createStripDeadPrototypesPass - This pass removes any function declarations
162 /// (prototypes) that are not used.
163 ModulePass *createStripDeadPrototypesPass();
164 
165 //===----------------------------------------------------------------------===//
166 /// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call
167 /// graph in RPO to deduce and propagate function attributes. Currently it
168 /// only handles synthesizing norecurse attributes.
169 ///
170 Pass *createReversePostOrderFunctionAttrsPass();
171 
172 //===----------------------------------------------------------------------===//
173 /// createMergeFunctionsPass - This pass discovers identical functions and
174 /// collapses them.
175 ///
176 ModulePass *createMergeFunctionsPass();
177 
178 //===----------------------------------------------------------------------===//
179 /// createHotColdSplittingPass - This pass outlines cold blocks into a separate
180 /// function(s).
181 ModulePass *createHotColdSplittingPass();
182 
183 //===----------------------------------------------------------------------===//
184 /// createIROutlinerPass - This pass finds similar code regions and factors
185 /// those regions out into functions.
186 ModulePass *createIROutlinerPass();
187 
188 //===----------------------------------------------------------------------===//
189 /// createPartialInliningPass - This pass inlines parts of functions.
190 ///
191 ModulePass *createPartialInliningPass();
192 
193 //===----------------------------------------------------------------------===//
194 /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
195 /// manager.
196 ModulePass *createBarrierNoopPass();
197 
198 /// createCalledValuePropagationPass - Attach metadata to indirct call sites
199 /// indicating the set of functions they may target at run-time.
200 ModulePass *createCalledValuePropagationPass();
201 
202 /// What to do with the summary when running passes that operate on it.
203 enum class PassSummaryAction {
204   None,   ///< Do nothing.
205   Import, ///< Import information from summary.
206   Export, ///< Export information to summary.
207 };
208 
209 /// This pass export CFI checks for use by external modules.
210 ModulePass *createCrossDSOCFIPass();
211 
212 /// This pass splits globals into pieces for the benefit of whole-program
213 /// devirtualization and control-flow integrity.
214 ModulePass *createGlobalSplitPass();
215 
216 } // End llvm namespace
217 
218 #endif
219