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