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