1 //===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header file defines prototypes for accessor functions that expose passes
11 // in the IPO transformations library.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_IPO_H
16 #define LLVM_TRANSFORMS_IPO_H
18 #include "llvm/ADT/SmallVector.h"
26 class ModuleSummaryIndex;
34 //===----------------------------------------------------------------------===//
36 // These functions removes symbols from functions and modules. If OnlyDebugInfo
37 // is true, only debugging information is removed from the module.
39 ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
41 //===----------------------------------------------------------------------===//
43 // These functions strips symbols from functions and modules.
44 // Only debugging information is not stripped.
46 ModulePass *createStripNonDebugSymbolsPass();
48 //===----------------------------------------------------------------------===//
50 // This pass removes llvm.dbg.declare intrinsics.
51 ModulePass *createStripDebugDeclarePass();
53 //===----------------------------------------------------------------------===//
55 // This pass removes unused symbols' debug info.
56 ModulePass *createStripDeadDebugInfoPass();
58 //===----------------------------------------------------------------------===//
59 /// createConstantMergePass - This function returns a new pass that merges
60 /// duplicate global constants together into a single constant that is shared.
61 /// This is useful because some passes (ie TraceValues) insert a lot of string
62 /// constants into the program, regardless of whether or not they duplicate an
65 ModulePass *createConstantMergePass();
67 //===----------------------------------------------------------------------===//
68 /// createGlobalOptimizerPass - This function returns a new pass that optimizes
69 /// non-address taken internal globals.
71 ModulePass *createGlobalOptimizerPass();
73 //===----------------------------------------------------------------------===//
74 /// createGlobalDCEPass - This transform is designed to eliminate unreachable
75 /// internal globals (functions or global variables)
77 ModulePass *createGlobalDCEPass();
79 //===----------------------------------------------------------------------===//
80 /// This transform is designed to eliminate available external globals
81 /// (functions or global variables)
83 ModulePass *createEliminateAvailableExternallyPass();
85 //===----------------------------------------------------------------------===//
86 /// createGVExtractionPass - If deleteFn is true, this pass deletes
87 /// the specified global values. Otherwise, it deletes as much of the module as
88 /// possible, except for the global values specified.
90 ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
93 //===----------------------------------------------------------------------===//
94 /// This pass performs iterative function importing from other modules.
95 Pass *createFunctionImportPass();
97 //===----------------------------------------------------------------------===//
98 /// createFunctionInliningPass - Return a new pass object that uses a heuristic
99 /// to inline direct function calls to small functions.
101 /// The Threshold can be passed directly, or asked to be computed from the
102 /// given optimization and size optimization arguments.
104 /// The -inline-threshold command line option takes precedence over the
105 /// threshold given here.
106 Pass *createFunctionInliningPass();
107 Pass *createFunctionInliningPass(int Threshold);
108 Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel,
109 bool DisableInlineHotCallSite);
110 Pass *createFunctionInliningPass(InlineParams &Params);
112 //===----------------------------------------------------------------------===//
113 /// createPruneEHPass - Return a new pass object which transforms invoke
114 /// instructions into calls, if the callee can _not_ unwind the stack.
116 Pass *createPruneEHPass();
118 //===----------------------------------------------------------------------===//
119 /// createInternalizePass - This pass loops over all of the functions in the
120 /// input module, internalizing all globals (functions and variables) it can.
122 /// Before internalizing a symbol, the callback \p MustPreserveGV is invoked and
123 /// gives to the client the ability to prevent internalizing specific symbols.
125 /// The symbol in DSOList are internalized if it is safe to drop them from
126 /// the symbol table.
128 /// Note that commandline options that are used with the above function are not
131 createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV);
133 /// createInternalizePass - Same as above, but with an empty exportList.
134 ModulePass *createInternalizePass();
136 //===----------------------------------------------------------------------===//
137 /// createDeadArgEliminationPass - This pass removes arguments from functions
138 /// which are not used by the body of the function.
140 ModulePass *createDeadArgEliminationPass();
142 /// DeadArgHacking pass - Same as DAE, but delete arguments of external
143 /// functions as well. This is definitely not safe, and should only be used by
145 ModulePass *createDeadArgHackingPass();
147 //===----------------------------------------------------------------------===//
148 /// createArgumentPromotionPass - This pass promotes "by reference" arguments to
149 /// be passed by value if the number of elements passed is smaller or
150 /// equal to maxElements (maxElements == 0 means always promote).
152 Pass *createArgumentPromotionPass(unsigned maxElements = 3);
154 //===----------------------------------------------------------------------===//
155 /// createIPConstantPropagationPass - This pass propagates constants from call
156 /// sites into the bodies of functions.
158 ModulePass *createIPConstantPropagationPass();
160 //===----------------------------------------------------------------------===//
161 /// createIPSCCPPass - This pass propagates constants from call sites into the
162 /// bodies of functions, and keeps track of whether basic blocks are executable
165 ModulePass *createIPSCCPPass();
167 //===----------------------------------------------------------------------===//
169 /// createLoopExtractorPass - This pass extracts all natural loops from the
170 /// program into a function if it can.
172 Pass *createLoopExtractorPass();
174 /// createSingleLoopExtractorPass - This pass extracts one natural loop from the
175 /// program into a function if it can. This is used by bugpoint.
177 Pass *createSingleLoopExtractorPass();
179 /// createBlockExtractorPass - This pass extracts all the specified blocks
180 /// from the functions in the module.
182 ModulePass *createBlockExtractorPass();
184 createBlockExtractorPass(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
185 bool EraseFunctions);
187 /// createStripDeadPrototypesPass - This pass removes any function declarations
188 /// (prototypes) that are not used.
189 ModulePass *createStripDeadPrototypesPass();
191 //===----------------------------------------------------------------------===//
192 /// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call
193 /// graph in RPO to deduce and propagate function attributes. Currently it
194 /// only handles synthesizing norecurse attributes.
196 Pass *createReversePostOrderFunctionAttrsPass();
198 //===----------------------------------------------------------------------===//
199 /// createMergeFunctionsPass - This pass discovers identical functions and
202 ModulePass *createMergeFunctionsPass();
204 //===----------------------------------------------------------------------===//
205 /// createHotColdSplittingPass - This pass outlines cold blocks into a separate
207 ModulePass *createHotColdSplittingPass();
209 //===----------------------------------------------------------------------===//
210 /// createPartialInliningPass - This pass inlines parts of functions.
212 ModulePass *createPartialInliningPass();
214 //===----------------------------------------------------------------------===//
215 /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
217 ModulePass *createBarrierNoopPass();
219 /// createCalledValuePropagationPass - Attach metadata to indirct call sites
220 /// indicating the set of functions they may target at run-time.
221 ModulePass *createCalledValuePropagationPass();
223 /// What to do with the summary when running passes that operate on it.
224 enum class PassSummaryAction {
225 None, ///< Do nothing.
226 Import, ///< Import information from summary.
227 Export, ///< Export information to summary.
230 /// This pass lowers type metadata and the llvm.type.test intrinsic to
233 /// The behavior depends on the summary arguments:
234 /// - If ExportSummary is non-null, this pass will export type identifiers to
235 /// the given summary.
236 /// - Otherwise, if ImportSummary is non-null, this pass will import type
237 /// identifiers from the given summary.
238 /// - Otherwise it does neither.
239 /// It is invalid for both ExportSummary and ImportSummary to be non-null.
240 ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
241 const ModuleSummaryIndex *ImportSummary);
243 /// This pass export CFI checks for use by external modules.
244 ModulePass *createCrossDSOCFIPass();
246 /// This pass implements whole-program devirtualization using type
249 /// The behavior depends on the summary arguments:
250 /// - If ExportSummary is non-null, this pass will export type identifiers to
251 /// the given summary.
252 /// - Otherwise, if ImportSummary is non-null, this pass will import type
253 /// identifiers from the given summary.
254 /// - Otherwise it does neither.
255 /// It is invalid for both ExportSummary and ImportSummary to be non-null.
257 createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
258 const ModuleSummaryIndex *ImportSummary);
260 /// This pass splits globals into pieces for the benefit of whole-program
261 /// devirtualization and control-flow integrity.
262 ModulePass *createGlobalSplitPass();
264 //===----------------------------------------------------------------------===//
265 // SampleProfilePass - Loads sample profile data from disk and generates
266 // IR metadata to reflect the profile.
267 ModulePass *createSampleProfileLoaderPass();
268 ModulePass *createSampleProfileLoaderPass(StringRef Name);
270 /// Write ThinLTO-ready bitcode to Str.
271 ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
272 raw_ostream *ThinLinkOS = nullptr);
274 } // End llvm namespace