• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header file defines prototypes for accessor functions that expose passes
11 // in the IPO transformations library.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_IPO_H
16 #define LLVM_TRANSFORMS_IPO_H
17 
18 #include "llvm/ADT/SmallVector.h"
19 #include <functional>
20 #include <vector>
21 
22 namespace llvm {
23 
24 struct InlineParams;
25 class StringRef;
26 class ModuleSummaryIndex;
27 class ModulePass;
28 class Pass;
29 class Function;
30 class BasicBlock;
31 class GlobalValue;
32 class raw_ostream;
33 
34 //===----------------------------------------------------------------------===//
35 //
36 // These functions removes symbols from functions and modules.  If OnlyDebugInfo
37 // is true, only debugging information is removed from the module.
38 //
39 ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
40 
41 //===----------------------------------------------------------------------===//
42 //
43 // These functions strips symbols from functions and modules.
44 // Only debugging information is not stripped.
45 //
46 ModulePass *createStripNonDebugSymbolsPass();
47 
48 //===----------------------------------------------------------------------===//
49 //
50 // This pass removes llvm.dbg.declare intrinsics.
51 ModulePass *createStripDebugDeclarePass();
52 
53 //===----------------------------------------------------------------------===//
54 //
55 // This pass removes unused symbols' debug info.
56 ModulePass *createStripDeadDebugInfoPass();
57 
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
63 /// existing string.
64 ///
65 ModulePass *createConstantMergePass();
66 
67 //===----------------------------------------------------------------------===//
68 /// createGlobalOptimizerPass - This function returns a new pass that optimizes
69 /// non-address taken internal globals.
70 ///
71 ModulePass *createGlobalOptimizerPass();
72 
73 //===----------------------------------------------------------------------===//
74 /// createGlobalDCEPass - This transform is designed to eliminate unreachable
75 /// internal globals (functions or global variables)
76 ///
77 ModulePass *createGlobalDCEPass();
78 
79 //===----------------------------------------------------------------------===//
80 /// This transform is designed to eliminate available external globals
81 /// (functions or global variables)
82 ///
83 ModulePass *createEliminateAvailableExternallyPass();
84 
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.
89 ///
90 ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
91                                    deleteFn = false);
92 
93 //===----------------------------------------------------------------------===//
94 /// This pass performs iterative function importing from other modules.
95 Pass *createFunctionImportPass();
96 
97 //===----------------------------------------------------------------------===//
98 /// createFunctionInliningPass - Return a new pass object that uses a heuristic
99 /// to inline direct function calls to small functions.
100 ///
101 /// The Threshold can be passed directly, or asked to be computed from the
102 /// given optimization and size optimization arguments.
103 ///
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);
111 
112 //===----------------------------------------------------------------------===//
113 /// createPruneEHPass - Return a new pass object which transforms invoke
114 /// instructions into calls, if the callee can _not_ unwind the stack.
115 ///
116 Pass *createPruneEHPass();
117 
118 //===----------------------------------------------------------------------===//
119 /// createInternalizePass - This pass loops over all of the functions in the
120 /// input module, internalizing all globals (functions and variables) it can.
121 ////
122 /// Before internalizing a symbol, the callback \p MustPreserveGV is invoked and
123 /// gives to the client the ability to prevent internalizing specific symbols.
124 ///
125 /// The symbol in DSOList are internalized if it is safe to drop them from
126 /// the symbol table.
127 ///
128 /// Note that commandline options that are used with the above function are not
129 /// used now!
130 ModulePass *
131 createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV);
132 
133 /// createInternalizePass - Same as above, but with an empty exportList.
134 ModulePass *createInternalizePass();
135 
136 //===----------------------------------------------------------------------===//
137 /// createDeadArgEliminationPass - This pass removes arguments from functions
138 /// which are not used by the body of the function.
139 ///
140 ModulePass *createDeadArgEliminationPass();
141 
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
144 /// bugpoint.
145 ModulePass *createDeadArgHackingPass();
146 
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).
151 ///
152 Pass *createArgumentPromotionPass(unsigned maxElements = 3);
153 
154 //===----------------------------------------------------------------------===//
155 /// createIPConstantPropagationPass - This pass propagates constants from call
156 /// sites into the bodies of functions.
157 ///
158 ModulePass *createIPConstantPropagationPass();
159 
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
163 /// in the process.
164 ///
165 ModulePass *createIPSCCPPass();
166 
167 //===----------------------------------------------------------------------===//
168 //
169 /// createLoopExtractorPass - This pass extracts all natural loops from the
170 /// program into a function if it can.
171 ///
172 Pass *createLoopExtractorPass();
173 
174 /// createSingleLoopExtractorPass - This pass extracts one natural loop from the
175 /// program into a function if it can.  This is used by bugpoint.
176 ///
177 Pass *createSingleLoopExtractorPass();
178 
179 /// createBlockExtractorPass - This pass extracts all the specified blocks
180 /// from the functions in the module.
181 ///
182 ModulePass *createBlockExtractorPass();
183 ModulePass *
184 createBlockExtractorPass(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
185                          bool EraseFunctions);
186 
187 /// createStripDeadPrototypesPass - This pass removes any function declarations
188 /// (prototypes) that are not used.
189 ModulePass *createStripDeadPrototypesPass();
190 
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.
195 ///
196 Pass *createReversePostOrderFunctionAttrsPass();
197 
198 //===----------------------------------------------------------------------===//
199 /// createMergeFunctionsPass - This pass discovers identical functions and
200 /// collapses them.
201 ///
202 ModulePass *createMergeFunctionsPass();
203 
204 //===----------------------------------------------------------------------===//
205 /// createPartialInliningPass - This pass inlines parts of functions.
206 ///
207 ModulePass *createPartialInliningPass();
208 
209 //===----------------------------------------------------------------------===//
210 /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
211 /// manager.
212 ModulePass *createBarrierNoopPass();
213 
214 /// createCalledValuePropagationPass - Attach metadata to indirct call sites
215 /// indicating the set of functions they may target at run-time.
216 ModulePass *createCalledValuePropagationPass();
217 
218 /// What to do with the summary when running passes that operate on it.
219 enum class PassSummaryAction {
220   None,   ///< Do nothing.
221   Import, ///< Import information from summary.
222   Export, ///< Export information to summary.
223 };
224 
225 /// This pass lowers type metadata and the llvm.type.test intrinsic to
226 /// bitsets.
227 ///
228 /// The behavior depends on the summary arguments:
229 /// - If ExportSummary is non-null, this pass will export type identifiers to
230 ///   the given summary.
231 /// - Otherwise, if ImportSummary is non-null, this pass will import type
232 ///   identifiers from the given summary.
233 /// - Otherwise it does neither.
234 /// It is invalid for both ExportSummary and ImportSummary to be non-null.
235 ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
236                                      const ModuleSummaryIndex *ImportSummary);
237 
238 /// This pass export CFI checks for use by external modules.
239 ModulePass *createCrossDSOCFIPass();
240 
241 /// This pass implements whole-program devirtualization using type
242 /// metadata.
243 ///
244 /// The behavior depends on the summary arguments:
245 /// - If ExportSummary is non-null, this pass will export type identifiers to
246 ///   the given summary.
247 /// - Otherwise, if ImportSummary is non-null, this pass will import type
248 ///   identifiers from the given summary.
249 /// - Otherwise it does neither.
250 /// It is invalid for both ExportSummary and ImportSummary to be non-null.
251 ModulePass *
252 createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
253                              const ModuleSummaryIndex *ImportSummary);
254 
255 /// This pass splits globals into pieces for the benefit of whole-program
256 /// devirtualization and control-flow integrity.
257 ModulePass *createGlobalSplitPass();
258 
259 //===----------------------------------------------------------------------===//
260 // SampleProfilePass - Loads sample profile data from disk and generates
261 // IR metadata to reflect the profile.
262 ModulePass *createSampleProfileLoaderPass();
263 ModulePass *createSampleProfileLoaderPass(StringRef Name);
264 
265 /// Write ThinLTO-ready bitcode to Str.
266 ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
267                                           raw_ostream *ThinLinkOS = nullptr);
268 
269 } // End llvm namespace
270 
271 #endif
272