1 | //===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===// |
2 | // |
3 | // The LLVM Compiler Infrastructure |
4 | // |
5 | // This file is distributed under the University of Illinois Open Source |
6 | // License. See LICENSE.TXT for details. |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | // |
10 | // This header file defines prototypes for accessor functions that expose passes |
11 | // in the IPO transformations library. |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_TRANSFORMS_IPO_H |
16 | #define LLVM_TRANSFORMS_IPO_H |
17 | |
18 | #include "llvm/ADT/SmallVector.h" |
19 | #include <functional> |
20 | #include <vector> |
21 | |
22 | namespace llvm { |
23 | |
24 | struct InlineParams; |
25 | class StringRef; |
26 | class ModuleSummaryIndex; |
27 | class ModulePass; |
28 | class Pass; |
29 | class Function; |
30 | class BasicBlock; |
31 | class GlobalValue; |
32 | class raw_ostream; |
33 | |
34 | //===----------------------------------------------------------------------===// |
35 | // |
36 | // These functions removes symbols from functions and modules. If OnlyDebugInfo |
37 | // is true, only debugging information is removed from the module. |
38 | // |
39 | ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false); |
40 | |
41 | //===----------------------------------------------------------------------===// |
42 | // |
43 | // These functions strips symbols from functions and modules. |
44 | // Only debugging information is not stripped. |
45 | // |
46 | ModulePass *createStripNonDebugSymbolsPass(); |
47 | |
48 | //===----------------------------------------------------------------------===// |
49 | // |
50 | // This pass removes llvm.dbg.declare intrinsics. |
51 | ModulePass *createStripDebugDeclarePass(); |
52 | |
53 | //===----------------------------------------------------------------------===// |
54 | // |
55 | // This pass removes unused symbols' debug info. |
56 | ModulePass *createStripDeadDebugInfoPass(); |
57 | |
58 | //===----------------------------------------------------------------------===// |
59 | /// createConstantMergePass - This function returns a new pass that merges |
60 | /// duplicate global constants together into a single constant that is shared. |
61 | /// This is useful because some passes (ie TraceValues) insert a lot of string |
62 | /// constants into the program, regardless of whether or not they duplicate an |
63 | /// existing string. |
64 | /// |
65 | ModulePass *createConstantMergePass(); |
66 | |
67 | //===----------------------------------------------------------------------===// |
68 | /// createGlobalOptimizerPass - This function returns a new pass that optimizes |
69 | /// non-address taken internal globals. |
70 | /// |
71 | ModulePass *createGlobalOptimizerPass(); |
72 | |
73 | //===----------------------------------------------------------------------===// |
74 | /// createGlobalDCEPass - This transform is designed to eliminate unreachable |
75 | /// internal globals (functions or global variables) |
76 | /// |
77 | ModulePass *createGlobalDCEPass(); |
78 | |
79 | //===----------------------------------------------------------------------===// |
80 | /// This transform is designed to eliminate available external globals |
81 | /// (functions or global variables) |
82 | /// |
83 | ModulePass *createEliminateAvailableExternallyPass(); |
84 | |
85 | //===----------------------------------------------------------------------===// |
86 | /// createGVExtractionPass - If deleteFn is true, this pass deletes |
87 | /// the specified global values. Otherwise, it deletes as much of the module as |
88 | /// possible, except for the global values specified. |
89 | /// |
90 | ModulePass *(std::vector<GlobalValue*>& GVs, bool |
91 | deleteFn = false); |
92 | |
93 | //===----------------------------------------------------------------------===// |
94 | /// This pass performs iterative function importing from other modules. |
95 | Pass *createFunctionImportPass(); |
96 | |
97 | //===----------------------------------------------------------------------===// |
98 | /// createFunctionInliningPass - Return a new pass object that uses a heuristic |
99 | /// to inline direct function calls to small functions. |
100 | /// |
101 | /// The Threshold can be passed directly, or asked to be computed from the |
102 | /// given optimization and size optimization arguments. |
103 | /// |
104 | /// The -inline-threshold command line option takes precedence over the |
105 | /// threshold given here. |
106 | Pass *createFunctionInliningPass(); |
107 | Pass *createFunctionInliningPass(int Threshold); |
108 | Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel, |
109 | bool DisableInlineHotCallSite); |
110 | Pass *createFunctionInliningPass(InlineParams &Params); |
111 | |
112 | //===----------------------------------------------------------------------===// |
113 | /// createPruneEHPass - Return a new pass object which transforms invoke |
114 | /// instructions into calls, if the callee can _not_ unwind the stack. |
115 | /// |
116 | Pass *createPruneEHPass(); |
117 | |
118 | //===----------------------------------------------------------------------===// |
119 | /// createInternalizePass - This pass loops over all of the functions in the |
120 | /// input module, internalizing all globals (functions and variables) it can. |
121 | //// |
122 | /// Before internalizing a symbol, the callback \p MustPreserveGV is invoked and |
123 | /// gives to the client the ability to prevent internalizing specific symbols. |
124 | /// |
125 | /// The symbol in DSOList are internalized if it is safe to drop them from |
126 | /// the symbol table. |
127 | /// |
128 | /// Note that commandline options that are used with the above function are not |
129 | /// used now! |
130 | ModulePass * |
131 | createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV); |
132 | |
133 | /// createInternalizePass - Same as above, but with an empty exportList. |
134 | ModulePass *createInternalizePass(); |
135 | |
136 | //===----------------------------------------------------------------------===// |
137 | /// createDeadArgEliminationPass - This pass removes arguments from functions |
138 | /// which are not used by the body of the function. |
139 | /// |
140 | ModulePass *createDeadArgEliminationPass(); |
141 | |
142 | /// DeadArgHacking pass - Same as DAE, but delete arguments of external |
143 | /// functions as well. This is definitely not safe, and should only be used by |
144 | /// bugpoint. |
145 | ModulePass *createDeadArgHackingPass(); |
146 | |
147 | //===----------------------------------------------------------------------===// |
148 | /// createArgumentPromotionPass - This pass promotes "by reference" arguments to |
149 | /// be passed by value if the number of elements passed is smaller or |
150 | /// equal to maxElements (maxElements == 0 means always promote). |
151 | /// |
152 | Pass *createArgumentPromotionPass(unsigned maxElements = 3); |
153 | |
154 | //===----------------------------------------------------------------------===// |
155 | /// createIPConstantPropagationPass - This pass propagates constants from call |
156 | /// sites into the bodies of functions. |
157 | /// |
158 | ModulePass *createIPConstantPropagationPass(); |
159 | |
160 | //===----------------------------------------------------------------------===// |
161 | /// createIPSCCPPass - This pass propagates constants from call sites into the |
162 | /// bodies of functions, and keeps track of whether basic blocks are executable |
163 | /// in the process. |
164 | /// |
165 | ModulePass *createIPSCCPPass(); |
166 | |
167 | //===----------------------------------------------------------------------===// |
168 | // |
169 | /// createLoopExtractorPass - This pass extracts all natural loops from the |
170 | /// program into a function if it can. |
171 | /// |
172 | Pass *(); |
173 | |
174 | /// createSingleLoopExtractorPass - This pass extracts one natural loop from the |
175 | /// program into a function if it can. This is used by bugpoint. |
176 | /// |
177 | Pass *(); |
178 | |
179 | /// createBlockExtractorPass - This pass extracts all the specified blocks |
180 | /// from the functions in the module. |
181 | /// |
182 | ModulePass *(); |
183 | ModulePass * |
184 | (const SmallVectorImpl<BasicBlock *> &, |
185 | bool EraseFunctions); |
186 | |
187 | /// createStripDeadPrototypesPass - This pass removes any function declarations |
188 | /// (prototypes) that are not used. |
189 | ModulePass *createStripDeadPrototypesPass(); |
190 | |
191 | //===----------------------------------------------------------------------===// |
192 | /// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call |
193 | /// graph in RPO to deduce and propagate function attributes. Currently it |
194 | /// only handles synthesizing norecurse attributes. |
195 | /// |
196 | Pass *createReversePostOrderFunctionAttrsPass(); |
197 | |
198 | //===----------------------------------------------------------------------===// |
199 | /// createMergeFunctionsPass - This pass discovers identical functions and |
200 | /// collapses them. |
201 | /// |
202 | ModulePass *createMergeFunctionsPass(); |
203 | |
204 | //===----------------------------------------------------------------------===// |
205 | /// createHotColdSplittingPass - This pass outlines cold blocks into a separate |
206 | /// function(s). |
207 | ModulePass *createHotColdSplittingPass(); |
208 | |
209 | //===----------------------------------------------------------------------===// |
210 | /// createPartialInliningPass - This pass inlines parts of functions. |
211 | /// |
212 | ModulePass *createPartialInliningPass(); |
213 | |
214 | //===----------------------------------------------------------------------===// |
215 | /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass |
216 | /// manager. |
217 | ModulePass *createBarrierNoopPass(); |
218 | |
219 | /// createCalledValuePropagationPass - Attach metadata to indirct call sites |
220 | /// indicating the set of functions they may target at run-time. |
221 | ModulePass *createCalledValuePropagationPass(); |
222 | |
223 | /// What to do with the summary when running passes that operate on it. |
224 | enum class PassSummaryAction { |
225 | None, ///< Do nothing. |
226 | Import, ///< Import information from summary. |
227 | Export, ///< Export information to summary. |
228 | }; |
229 | |
230 | /// This pass lowers type metadata and the llvm.type.test intrinsic to |
231 | /// bitsets. |
232 | /// |
233 | /// The behavior depends on the summary arguments: |
234 | /// - If ExportSummary is non-null, this pass will export type identifiers to |
235 | /// the given summary. |
236 | /// - Otherwise, if ImportSummary is non-null, this pass will import type |
237 | /// identifiers from the given summary. |
238 | /// - Otherwise it does neither. |
239 | /// It is invalid for both ExportSummary and ImportSummary to be non-null. |
240 | ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary, |
241 | const ModuleSummaryIndex *ImportSummary); |
242 | |
243 | /// This pass export CFI checks for use by external modules. |
244 | ModulePass *createCrossDSOCFIPass(); |
245 | |
246 | /// This pass implements whole-program devirtualization using type |
247 | /// metadata. |
248 | /// |
249 | /// The behavior depends on the summary arguments: |
250 | /// - If ExportSummary is non-null, this pass will export type identifiers to |
251 | /// the given summary. |
252 | /// - Otherwise, if ImportSummary is non-null, this pass will import type |
253 | /// identifiers from the given summary. |
254 | /// - Otherwise it does neither. |
255 | /// It is invalid for both ExportSummary and ImportSummary to be non-null. |
256 | ModulePass * |
257 | createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary, |
258 | const ModuleSummaryIndex *ImportSummary); |
259 | |
260 | /// This pass splits globals into pieces for the benefit of whole-program |
261 | /// devirtualization and control-flow integrity. |
262 | ModulePass *createGlobalSplitPass(); |
263 | |
264 | //===----------------------------------------------------------------------===// |
265 | // SampleProfilePass - Loads sample profile data from disk and generates |
266 | // IR metadata to reflect the profile. |
267 | ModulePass *createSampleProfileLoaderPass(); |
268 | ModulePass *createSampleProfileLoaderPass(StringRef Name); |
269 | |
270 | /// Write ThinLTO-ready bitcode to Str. |
271 | ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str, |
272 | raw_ostream *ThinLinkOS = nullptr); |
273 | |
274 | } // End llvm namespace |
275 | |
276 | #endif |
277 | |