[InstCombine] Signed saturation patterns
[llvm-core.git] / include / llvm / Transforms / IPO.h
blobde0c80f5b19accb5c131cc79d16fd9abd3e49741
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_IPO_H
15 #define LLVM_TRANSFORMS_IPO_H
17 #include "llvm/ADT/SmallVector.h"
18 #include <functional>
19 #include <vector>
21 namespace llvm {
23 struct InlineParams;
24 class StringRef;
25 class ModuleSummaryIndex;
26 class ModulePass;
27 class Pass;
28 class Function;
29 class BasicBlock;
30 class GlobalValue;
31 class raw_ostream;
33 //===----------------------------------------------------------------------===//
35 // These functions removes symbols from functions and modules. If OnlyDebugInfo
36 // is true, only debugging information is removed from the module.
38 ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
40 //===----------------------------------------------------------------------===//
42 // These functions strips symbols from functions and modules.
43 // Only debugging information is not stripped.
45 ModulePass *createStripNonDebugSymbolsPass();
47 //===----------------------------------------------------------------------===//
49 // This pass removes llvm.dbg.declare intrinsics.
50 ModulePass *createStripDebugDeclarePass();
52 //===----------------------------------------------------------------------===//
54 // This pass removes unused symbols' debug info.
55 ModulePass *createStripDeadDebugInfoPass();
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 ///
64 ModulePass *createConstantMergePass();
66 //===----------------------------------------------------------------------===//
67 /// createGlobalOptimizerPass - This function returns a new pass that optimizes
68 /// non-address taken internal globals.
69 ///
70 ModulePass *createGlobalOptimizerPass();
72 //===----------------------------------------------------------------------===//
73 /// createGlobalDCEPass - This transform is designed to eliminate unreachable
74 /// internal globals (functions or global variables)
75 ///
76 ModulePass *createGlobalDCEPass();
78 //===----------------------------------------------------------------------===//
79 /// This transform is designed to eliminate available external globals
80 /// (functions or global variables)
81 ///
82 ModulePass *createEliminateAvailableExternallyPass();
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 ///
89 ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
90 deleteFn = false);
92 //===----------------------------------------------------------------------===//
93 /// This pass performs iterative function importing from other modules.
94 Pass *createFunctionImportPass();
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.
103 /// The -inline-threshold command line option takes precedence over the
104 /// threshold given here.
105 Pass *createFunctionInliningPass();
106 Pass *createFunctionInliningPass(int Threshold);
107 Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel,
108 bool DisableInlineHotCallSite);
109 Pass *createFunctionInliningPass(InlineParams &Params);
111 //===----------------------------------------------------------------------===//
112 /// createPruneEHPass - Return a new pass object which transforms invoke
113 /// instructions into calls, if the callee can _not_ unwind the stack.
115 Pass *createPruneEHPass();
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.
124 /// The symbol in DSOList are internalized if it is safe to drop them from
125 /// the symbol table.
127 /// Note that commandline options that are used with the above function are not
128 /// used now!
129 ModulePass *
130 createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV);
132 /// createInternalizePass - Same as above, but with an empty exportList.
133 ModulePass *createInternalizePass();
135 //===----------------------------------------------------------------------===//
136 /// createDeadArgEliminationPass - This pass removes arguments from functions
137 /// which are not used by the body of the function.
139 ModulePass *createDeadArgEliminationPass();
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.
144 ModulePass *createDeadArgHackingPass();
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).
151 Pass *createArgumentPromotionPass(unsigned maxElements = 3);
153 //===----------------------------------------------------------------------===//
154 /// createIPConstantPropagationPass - This pass propagates constants from call
155 /// sites into the bodies of functions.
157 ModulePass *createIPConstantPropagationPass();
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.
164 ModulePass *createIPSCCPPass();
166 //===----------------------------------------------------------------------===//
168 /// createLoopExtractorPass - This pass extracts all natural loops from the
169 /// program into a function if it can.
171 Pass *createLoopExtractorPass();
173 /// createSingleLoopExtractorPass - This pass extracts one natural loop from the
174 /// program into a function if it can. This is used by bugpoint.
176 Pass *createSingleLoopExtractorPass();
178 /// createBlockExtractorPass - This pass extracts all the specified blocks
179 /// from the functions in the module.
181 ModulePass *createBlockExtractorPass();
182 ModulePass *
183 createBlockExtractorPass(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
184 bool EraseFunctions);
185 ModulePass *
186 createBlockExtractorPass(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
187 &GroupsOfBlocksToExtract,
188 bool EraseFunctions);
190 /// createStripDeadPrototypesPass - This pass removes any function declarations
191 /// (prototypes) that are not used.
192 ModulePass *createStripDeadPrototypesPass();
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.
199 Pass *createReversePostOrderFunctionAttrsPass();
201 //===----------------------------------------------------------------------===//
202 /// createMergeFunctionsPass - This pass discovers identical functions and
203 /// collapses them.
205 ModulePass *createMergeFunctionsPass();
207 //===----------------------------------------------------------------------===//
208 /// createHotColdSplittingPass - This pass outlines cold blocks into a separate
209 /// function(s).
210 ModulePass *createHotColdSplittingPass();
212 //===----------------------------------------------------------------------===//
213 /// createPartialInliningPass - This pass inlines parts of functions.
215 ModulePass *createPartialInliningPass();
217 //===----------------------------------------------------------------------===//
218 /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
219 /// manager.
220 ModulePass *createBarrierNoopPass();
222 /// createCalledValuePropagationPass - Attach metadata to indirct call sites
223 /// indicating the set of functions they may target at run-time.
224 ModulePass *createCalledValuePropagationPass();
226 /// What to do with the summary when running passes that operate on it.
227 enum class PassSummaryAction {
228 None, ///< Do nothing.
229 Import, ///< Import information from summary.
230 Export, ///< Export information to summary.
233 /// This pass lowers type metadata and the llvm.type.test intrinsic to
234 /// bitsets.
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.
243 ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
244 const ModuleSummaryIndex *ImportSummary);
246 /// This pass export CFI checks for use by external modules.
247 ModulePass *createCrossDSOCFIPass();
249 /// This pass implements whole-program devirtualization using type
250 /// metadata.
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.
259 ModulePass *
260 createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
261 const ModuleSummaryIndex *ImportSummary);
263 /// This pass splits globals into pieces for the benefit of whole-program
264 /// devirtualization and control-flow integrity.
265 ModulePass *createGlobalSplitPass();
267 //===----------------------------------------------------------------------===//
268 // SampleProfilePass - Loads sample profile data from disk and generates
269 // IR metadata to reflect the profile.
270 ModulePass *createSampleProfileLoaderPass();
271 ModulePass *createSampleProfileLoaderPass(StringRef Name);
273 /// Write ThinLTO-ready bitcode to Str.
274 ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
275 raw_ostream *ThinLinkOS = nullptr);
277 } // End llvm namespace
279 #endif