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 StringRef;
25 class ModuleSummaryIndex;
26 class ModulePass;
27 class Pass;
28 class BasicBlock;
29 class GlobalValue;
30 class raw_ostream;
31 
32 //===----------------------------------------------------------------------===//
33 //
34 // These functions removes symbols from functions and modules.  If OnlyDebugInfo
35 // is true, only debugging information is removed from the module.
36 //
37 ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
38 
39 //===----------------------------------------------------------------------===//
40 //
41 // These functions strips symbols from functions and modules.
42 // Only debugging information is not stripped.
43 //
44 ModulePass *createStripNonDebugSymbolsPass();
45 
46 //===----------------------------------------------------------------------===//
47 //
48 // This pass removes llvm.dbg.declare intrinsics.
49 ModulePass *createStripDebugDeclarePass();
50 
51 //===----------------------------------------------------------------------===//
52 //
53 // This pass removes unused symbols' debug info.
54 ModulePass *createStripDeadDebugInfoPass();
55 
56 //===----------------------------------------------------------------------===//
57 /// createConstantMergePass - This function returns a new pass that merges
58 /// duplicate global constants together into a single constant that is shared.
59 /// This is useful because some passes (ie TraceValues) insert a lot of string
60 /// constants into the program, regardless of whether or not they duplicate an
61 /// existing string.
62 ///
63 ModulePass *createConstantMergePass();
64 
65 //===----------------------------------------------------------------------===//
66 /// createGlobalOptimizerPass - This function returns a new pass that optimizes
67 /// non-address taken internal globals.
68 ///
69 ModulePass *createGlobalOptimizerPass();
70 
71 //===----------------------------------------------------------------------===//
72 /// createGlobalDCEPass - This transform is designed to eliminate unreachable
73 /// internal globals (functions or global variables)
74 ///
75 ModulePass *createGlobalDCEPass();
76 
77 //===----------------------------------------------------------------------===//
78 /// This transform is designed to eliminate available external globals
79 /// (functions or global variables)
80 ///
81 ModulePass *createEliminateAvailableExternallyPass();
82 
83 //===----------------------------------------------------------------------===//
84 /// createGVExtractionPass - If deleteFn is true, this pass deletes
85 /// the specified global values. Otherwise, it deletes as much of the module as
86 /// possible, except for the global values specified. If keepConstInit is true,
87 /// the initializers of global constants are not deleted even if they are
88 /// unused.
89 ///
90 ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
91                                   deleteFn = false, bool keepConstInit = 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 /// createOpenMPOptLegacyPass - OpenMP specific optimizations.
156 Pass *createOpenMPOptLegacyPass();
157 
158 //===----------------------------------------------------------------------===//
159 /// createIPConstantPropagationPass - This pass propagates constants from call
160 /// sites into the bodies of functions.
161 ///
162 ModulePass *createIPConstantPropagationPass();
163 
164 //===----------------------------------------------------------------------===//
165 /// createIPSCCPPass - This pass propagates constants from call sites into the
166 /// bodies of functions, and keeps track of whether basic blocks are executable
167 /// in the process.
168 ///
169 ModulePass *createIPSCCPPass();
170 
171 //===----------------------------------------------------------------------===//
172 //
173 /// createLoopExtractorPass - This pass extracts all natural loops from the
174 /// program into a function if it can.
175 ///
176 Pass *createLoopExtractorPass();
177 
178 /// createSingleLoopExtractorPass - This pass extracts one natural loop from the
179 /// program into a function if it can.  This is used by bugpoint.
180 ///
181 Pass *createSingleLoopExtractorPass();
182 
183 /// createBlockExtractorPass - This pass extracts all the specified blocks
184 /// from the functions in the module.
185 ///
186 ModulePass *createBlockExtractorPass();
187 ModulePass *
188 createBlockExtractorPass(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
189                          bool EraseFunctions);
190 ModulePass *
191 createBlockExtractorPass(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
192                              &GroupsOfBlocksToExtract,
193                          bool EraseFunctions);
194 
195 /// createStripDeadPrototypesPass - This pass removes any function declarations
196 /// (prototypes) that are not used.
197 ModulePass *createStripDeadPrototypesPass();
198 
199 //===----------------------------------------------------------------------===//
200 /// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call
201 /// graph in RPO to deduce and propagate function attributes. Currently it
202 /// only handles synthesizing norecurse attributes.
203 ///
204 Pass *createReversePostOrderFunctionAttrsPass();
205 
206 //===----------------------------------------------------------------------===//
207 /// createMergeFunctionsPass - This pass discovers identical functions and
208 /// collapses them.
209 ///
210 ModulePass *createMergeFunctionsPass();
211 
212 //===----------------------------------------------------------------------===//
213 /// createHotColdSplittingPass - This pass outlines cold blocks into a separate
214 /// function(s).
215 ModulePass *createHotColdSplittingPass();
216 
217 //===----------------------------------------------------------------------===//
218 /// createPartialInliningPass - This pass inlines parts of functions.
219 ///
220 ModulePass *createPartialInliningPass();
221 
222 //===----------------------------------------------------------------------===//
223 /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
224 /// manager.
225 ModulePass *createBarrierNoopPass();
226 
227 /// createCalledValuePropagationPass - Attach metadata to indirct call sites
228 /// indicating the set of functions they may target at run-time.
229 ModulePass *createCalledValuePropagationPass();
230 
231 /// What to do with the summary when running passes that operate on it.
232 enum class PassSummaryAction {
233   None,   ///< Do nothing.
234   Import, ///< Import information from summary.
235   Export, ///< Export information to summary.
236 };
237 
238 /// This pass lowers type metadata and the llvm.type.test intrinsic to
239 /// bitsets.
240 ///
241 /// The behavior depends on the summary arguments:
242 /// - If ExportSummary is non-null, this pass will export type identifiers to
243 ///   the given summary.
244 /// - If ImportSummary is non-null, this pass will import type identifiers from
245 ///   the given summary.
246 /// - Otherwise, if both are null and DropTypeTests is true, all type test
247 ///   assume sequences will be removed from the IR.
248 /// It is invalid for both ExportSummary and ImportSummary to be non-null
249 /// unless DropTypeTests is true.
250 ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
251                                      const ModuleSummaryIndex *ImportSummary,
252                                      bool DropTypeTests = false);
253 
254 /// This pass export CFI checks for use by external modules.
255 ModulePass *createCrossDSOCFIPass();
256 
257 /// This pass implements whole-program devirtualization using type
258 /// metadata.
259 ///
260 /// The behavior depends on the summary arguments:
261 /// - If ExportSummary is non-null, this pass will export type identifiers to
262 ///   the given summary.
263 /// - Otherwise, if ImportSummary is non-null, this pass will import type
264 ///   identifiers from the given summary.
265 /// - Otherwise it does neither.
266 /// It is invalid for both ExportSummary and ImportSummary to be non-null.
267 ModulePass *
268 createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
269                              const ModuleSummaryIndex *ImportSummary);
270 
271 /// This pass splits globals into pieces for the benefit of whole-program
272 /// devirtualization and control-flow integrity.
273 ModulePass *createGlobalSplitPass();
274 
275 //===----------------------------------------------------------------------===//
276 // SampleProfilePass - Loads sample profile data from disk and generates
277 // IR metadata to reflect the profile.
278 ModulePass *createSampleProfileLoaderPass();
279 ModulePass *createSampleProfileLoaderPass(StringRef Name);
280 
281 /// Write ThinLTO-ready bitcode to Str.
282 ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
283                                           raw_ostream *ThinLinkOS = nullptr);
284 
285 } // End llvm namespace
286 
287 #endif
288