blob: 4f7a1bae12b99559c91d732c46dd416a263d4c7f [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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);
185
186/// createStripDeadPrototypesPass - This pass removes any function declarations
187/// (prototypes) that are not used.
188ModulePass *createStripDeadPrototypesPass();
189
190//===----------------------------------------------------------------------===//
191/// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call
192/// graph in RPO to deduce and propagate function attributes. Currently it
193/// only handles synthesizing norecurse attributes.
194///
195Pass *createReversePostOrderFunctionAttrsPass();
196
197//===----------------------------------------------------------------------===//
198/// createMergeFunctionsPass - This pass discovers identical functions and
199/// collapses them.
200///
201ModulePass *createMergeFunctionsPass();
202
203//===----------------------------------------------------------------------===//
Andrew Scull0372a572018-11-16 15:47:06 +0000204/// createHotColdSplittingPass - This pass outlines cold blocks into a separate
205/// function(s).
206ModulePass *createHotColdSplittingPass();
207
208//===----------------------------------------------------------------------===//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100209/// createPartialInliningPass - This pass inlines parts of functions.
210///
211ModulePass *createPartialInliningPass();
212
213//===----------------------------------------------------------------------===//
214/// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
215/// manager.
216ModulePass *createBarrierNoopPass();
217
218/// createCalledValuePropagationPass - Attach metadata to indirct call sites
219/// indicating the set of functions they may target at run-time.
220ModulePass *createCalledValuePropagationPass();
221
222/// What to do with the summary when running passes that operate on it.
223enum class PassSummaryAction {
224 None, ///< Do nothing.
225 Import, ///< Import information from summary.
226 Export, ///< Export information to summary.
227};
228
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100229/// This pass lowers type metadata and the llvm.type.test intrinsic to
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100230/// bitsets.
231///
232/// The behavior depends on the summary arguments:
233/// - If ExportSummary is non-null, this pass will export type identifiers to
234/// the given summary.
235/// - Otherwise, if ImportSummary is non-null, this pass will import type
236/// identifiers from the given summary.
237/// - Otherwise it does neither.
238/// It is invalid for both ExportSummary and ImportSummary to be non-null.
239ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
240 const ModuleSummaryIndex *ImportSummary);
241
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100242/// This pass export CFI checks for use by external modules.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100243ModulePass *createCrossDSOCFIPass();
244
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100245/// This pass implements whole-program devirtualization using type
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100246/// metadata.
247///
248/// The behavior depends on the summary arguments:
249/// - If ExportSummary is non-null, this pass will export type identifiers to
250/// the given summary.
251/// - Otherwise, if ImportSummary is non-null, this pass will import type
252/// identifiers from the given summary.
253/// - Otherwise it does neither.
254/// It is invalid for both ExportSummary and ImportSummary to be non-null.
255ModulePass *
256createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
257 const ModuleSummaryIndex *ImportSummary);
258
259/// This pass splits globals into pieces for the benefit of whole-program
260/// devirtualization and control-flow integrity.
261ModulePass *createGlobalSplitPass();
262
263//===----------------------------------------------------------------------===//
264// SampleProfilePass - Loads sample profile data from disk and generates
265// IR metadata to reflect the profile.
266ModulePass *createSampleProfileLoaderPass();
267ModulePass *createSampleProfileLoaderPass(StringRef Name);
268
269/// Write ThinLTO-ready bitcode to Str.
270ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
271 raw_ostream *ThinLinkOS = nullptr);
272
273} // End llvm namespace
274
275#endif