Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / include / llvm / Transforms / IPO.h
blob4f7a1bae12b99559c91d732c46dd416a263d4c7f
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);
186 /// createStripDeadPrototypesPass - This pass removes any function declarations
187 /// (prototypes) that are not used.
188 ModulePass *createStripDeadPrototypesPass();
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.
195 Pass *createReversePostOrderFunctionAttrsPass();
197 //===----------------------------------------------------------------------===//
198 /// createMergeFunctionsPass - This pass discovers identical functions and
199 /// collapses them.
201 ModulePass *createMergeFunctionsPass();
203 //===----------------------------------------------------------------------===//
204 /// createHotColdSplittingPass - This pass outlines cold blocks into a separate
205 /// function(s).
206 ModulePass *createHotColdSplittingPass();
208 //===----------------------------------------------------------------------===//
209 /// createPartialInliningPass - This pass inlines parts of functions.
211 ModulePass *createPartialInliningPass();
213 //===----------------------------------------------------------------------===//
214 /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
215 /// manager.
216 ModulePass *createBarrierNoopPass();
218 /// createCalledValuePropagationPass - Attach metadata to indirct call sites
219 /// indicating the set of functions they may target at run-time.
220 ModulePass *createCalledValuePropagationPass();
222 /// What to do with the summary when running passes that operate on it.
223 enum class PassSummaryAction {
224 None, ///< Do nothing.
225 Import, ///< Import information from summary.
226 Export, ///< Export information to summary.
229 /// This pass lowers type metadata and the llvm.type.test intrinsic to
230 /// bitsets.
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.
239 ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
240 const ModuleSummaryIndex *ImportSummary);
242 /// This pass export CFI checks for use by external modules.
243 ModulePass *createCrossDSOCFIPass();
245 /// This pass implements whole-program devirtualization using type
246 /// metadata.
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.
255 ModulePass *
256 createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
257 const ModuleSummaryIndex *ImportSummary);
259 /// This pass splits globals into pieces for the benefit of whole-program
260 /// devirtualization and control-flow integrity.
261 ModulePass *createGlobalSplitPass();
263 //===----------------------------------------------------------------------===//
264 // SampleProfilePass - Loads sample profile data from disk and generates
265 // IR metadata to reflect the profile.
266 ModulePass *createSampleProfileLoaderPass();
267 ModulePass *createSampleProfileLoaderPass(StringRef Name);
269 /// Write ThinLTO-ready bitcode to Str.
270 ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
271 raw_ostream *ThinLinkOS = nullptr);
273 } // End llvm namespace
275 #endif