blob: ed2823098ae931adc4b5015305a59b0643e77e67 [file] [log] [blame]
Chris Lattner259a9b22002-07-23 19:56:27 +00001//===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===//
Misha Brukmandf586aa2005-04-21 20:59:05 +00002//
John Criswellb6445982003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnere9cc7422007-12-29 19:59:42 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmandf586aa2005-04-21 20:59:05 +00007//
John Criswellb6445982003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattnerb3f4d1b2001-10-31 04:32:53 +00009//
Chris Lattner259a9b22002-07-23 19:56:27 +000010// This header file defines prototypes for accessor functions that expose passes
11// in the IPO transformations library.
Chris Lattnerb3f4d1b2001-10-31 04:32:53 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner86fa2262002-07-23 19:48:52 +000015#ifndef LLVM_TRANSFORMS_IPO_H
16#define LLVM_TRANSFORMS_IPO_H
Chris Lattnerb3f4d1b2001-10-31 04:32:53 +000017
Rafael Espindolaa92da5b2012-12-11 16:36:02 +000018#include "llvm/ADT/ArrayRef.h"
Chris Lattnerdf2ae522004-08-13 03:03:44 +000019
Brian Gaeke960707c2003-11-11 22:41:34 +000020namespace llvm {
21
Chris Lattner1556b272004-09-20 04:41:39 +000022class ModulePass;
Devang Patel13058a52007-01-26 00:47:38 +000023class Pass;
Chris Lattner58f90022002-11-19 18:42:59 +000024class Function;
Chris Lattnerdf2ae522004-08-13 03:03:44 +000025class BasicBlock;
Andrew Lenharth3f13b662008-03-07 19:51:57 +000026class GlobalValue;
Chris Lattner8e79dbf2002-04-10 20:31:22 +000027
Chris Lattner86fa2262002-07-23 19:48:52 +000028//===----------------------------------------------------------------------===//
Chris Lattner4459cb22004-12-02 21:24:19 +000029//
30// These functions removes symbols from functions and modules. If OnlyDebugInfo
31// is true, only debugging information is removed from the module.
32//
33ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
34
35//===----------------------------------------------------------------------===//
Devang Patelb5e867a2008-11-18 21:34:39 +000036//
Devang Patel66f84e72009-03-09 20:49:37 +000037// These functions strips symbols from functions and modules.
38// Only debugging information is not stripped.
Devang Patelb5e867a2008-11-18 21:34:39 +000039//
40ModulePass *createStripNonDebugSymbolsPass();
41
42//===----------------------------------------------------------------------===//
Devang Patel66f84e72009-03-09 20:49:37 +000043//
44// These pass removes llvm.dbg.declare intrinsics.
45ModulePass *createStripDebugDeclarePass();
46
47//===----------------------------------------------------------------------===//
Devang Patel2b434e12010-07-01 19:49:20 +000048//
49// These pass removes unused symbols' debug info.
50ModulePass *createStripDeadDebugInfoPass();
51
52//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +000053/// createConstantMergePass - This function returns a new pass that merges
54/// duplicate global constants together into a single constant that is shared.
55/// This is useful because some passes (ie TraceValues) insert a lot of string
56/// constants into the program, regardless of whether or not they duplicate an
57/// existing string.
58///
Chris Lattner1556b272004-09-20 04:41:39 +000059ModulePass *createConstantMergePass();
Chris Lattner259a9b22002-07-23 19:56:27 +000060
61
62//===----------------------------------------------------------------------===//
Chris Lattnerfa3cfd32004-10-07 04:12:02 +000063/// createGlobalOptimizerPass - This function returns a new pass that optimizes
64/// non-address taken internal globals.
Chris Lattnerf624c992004-03-14 20:00:37 +000065///
Chris Lattnerfa3cfd32004-10-07 04:12:02 +000066ModulePass *createGlobalOptimizerPass();
Chris Lattner14da4ea2004-02-25 21:34:51 +000067
68
69//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +000070/// createGlobalDCEPass - This transform is designed to eliminate unreachable
71/// internal globals (functions or global variables)
72///
Chris Lattner1556b272004-09-20 04:41:39 +000073ModulePass *createGlobalDCEPass();
Chris Lattner8cf6e102002-07-24 17:10:58 +000074
75
76//===----------------------------------------------------------------------===//
Jay Foad6a514022011-07-26 09:36:52 +000077/// createGVExtractionPass - If deleteFn is true, this pass deletes
Andrew Lenharth3f13b662008-03-07 19:51:57 +000078/// the specified global values. Otherwise, it deletes as much of the module as
79/// possible, except for the global values specified.
80///
81ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
Dan Gohman8f292e72010-08-26 00:22:55 +000082 deleteFn = false);
Chris Lattner58f90022002-11-19 18:42:59 +000083
84//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +000085/// createFunctionInliningPass - Return a new pass object that uses a heuristic
86/// to inline direct function calls to small functions.
87///
Jakob Stoklund Olesen31a7eb42010-11-02 23:40:26 +000088/// The -inline-threshold command line option takes precedence over the
89/// threshold given here.
Devang Patel13058a52007-01-26 00:47:38 +000090Pass *createFunctionInliningPass();
Chris Lattner22ad7ab2008-01-12 06:49:13 +000091Pass *createFunctionInliningPass(int Threshold);
Chris Lattner8cf6e102002-07-24 17:10:58 +000092
93//===----------------------------------------------------------------------===//
Devang Patelf58f96f2008-09-03 20:24:05 +000094/// createAlwaysInlinerPass - Return a new pass object that inlines only
95/// functions that are marked as "always_inline".
96Pass *createAlwaysInlinerPass();
Chad Rosier07d37bc2012-02-25 02:56:01 +000097Pass *createAlwaysInlinerPass(bool InsertLifetime);
Devang Patelf58f96f2008-09-03 20:24:05 +000098
99//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +0000100/// createPruneEHPass - Return a new pass object which transforms invoke
101/// instructions into calls, if the callee can _not_ unwind the stack.
102///
Devang Patel13058a52007-01-26 00:47:38 +0000103Pass *createPruneEHPass();
Chris Lattner994e7c22003-08-31 16:30:25 +0000104
105//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +0000106/// createInternalizePass - This pass loops over all of the functions in the
Rafael Espindolacda29112013-10-03 18:29:09 +0000107/// input module, internalizing all globals (functions and variables) it can.
108////
109/// The symbols in \p ExportList are never internalized.
110///
111/// The symbol in DSOList are internalized if it is safe to drop them from
112/// the symbol table.
113///
114/// For example of the difference, consider a dynamic library being built from
115/// two translation units. The first one compiled to a native object
116/// (ELF/MachO/COFF) and second one compiled to IL. Translation unit A has a
117/// copy of linkonce_odr unnamed_addr function F. The translation unit B has a
118/// copy of the linkonce_odr unnamed_addr functions F and G.
119///
120/// Assume the linker decides to keep the copy of F in B. This means that LLVM
121/// must produce F in the object file it passes to the linker, otherwise we
122/// will have an undefined reference. For G the situation is different. The
123/// linker puts the function in the DSOList, since it is only wanted for the
124/// symbol table. With this information internalize can now reason that since
125/// the function is a linkonce_odr and its address is not important, it can be
126/// omitted. Any other shared library needing this function will have a copy of
127/// it.
Matthijs Kooijman1b606212008-06-26 09:48:11 +0000128///
129/// Note that commandline options that are used with the above function are not
Rafael Espindola4253bd82012-10-26 18:47:48 +0000130/// used now!
Rafael Espindolacda29112013-10-03 18:29:09 +0000131ModulePass *createInternalizePass(ArrayRef<const char *> ExportList,
132 ArrayRef<const char *> DSOList);
Rafael Espindola4253bd82012-10-26 18:47:48 +0000133/// createInternalizePass - Same as above, but with an empty exportList.
134ModulePass *createInternalizePass();
Chris Lattner8cf6e102002-07-24 17:10:58 +0000135
Chris Lattner4ff07062003-06-16 12:16:52 +0000136//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +0000137/// createDeadArgEliminationPass - This pass removes arguments from functions
138/// which are not used by the body of the function.
139///
Chris Lattner1556b272004-09-20 04:41:39 +0000140ModulePass *createDeadArgEliminationPass();
Chris Lattnera2e48a82003-11-05 21:43:42 +0000141
Chris Lattnerf624c992004-03-14 20:00:37 +0000142/// 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.
Chris Lattner1556b272004-09-20 04:41:39 +0000145ModulePass *createDeadArgHackingPass();
Chris Lattner4ff07062003-06-16 12:16:52 +0000146
Chris Lattnere4511db2003-10-23 16:51:49 +0000147//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +0000148/// createArgumentPromotionPass - This pass promotes "by reference" arguments to
Chris Lattnereb6bb802008-04-19 19:50:01 +0000149/// be passed by value if the number of elements passed is smaller or
150/// equal to maxElements (maxElements == 0 means always promote).
Chris Lattnerf624c992004-03-14 20:00:37 +0000151///
Chris Lattnereb6bb802008-04-19 19:50:01 +0000152Pass *createArgumentPromotionPass(unsigned maxElements = 3);
Chris Lattner1f607f22004-03-07 21:30:08 +0000153
154//===----------------------------------------------------------------------===//
Chris Lattnerf624c992004-03-14 20:00:37 +0000155/// createIPConstantPropagationPass - This pass propagates constants from call
156/// sites into the bodies of functions.
157///
Chris Lattner1556b272004-09-20 04:41:39 +0000158ModulePass *createIPConstantPropagationPass();
Chris Lattnere4511db2003-10-23 16:51:49 +0000159
Chris Lattner3b33c7a2004-12-10 07:55:01 +0000160//===----------------------------------------------------------------------===//
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///
165ModulePass *createIPSCCPPass();
Chris Lattner8cf6e102002-07-24 17:10:58 +0000166
167//===----------------------------------------------------------------------===//
Chris Lattner6d24a7c2004-03-14 02:36:34 +0000168//
Jeff Cohen677babc2005-01-08 17:21:40 +0000169/// createLoopExtractorPass - This pass extracts all natural loops from the
170/// program into a function if it can.
171///
Dan Gohman9a7320c2009-09-28 14:37:51 +0000172Pass *createLoopExtractorPass();
Jeff Cohen677babc2005-01-08 17:21:40 +0000173
Chris Lattnerf624c992004-03-14 20:00:37 +0000174/// createSingleLoopExtractorPass - This pass extracts one natural loop from the
175/// program into a function if it can. This is used by bugpoint.
176///
Dan Gohman9a7320c2009-09-28 14:37:51 +0000177Pass *createSingleLoopExtractorPass();
Chris Lattner6d24a7c2004-03-14 02:36:34 +0000178
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000179/// createBlockExtractorPass - This pass extracts all blocks (except those
180/// specified in the argument list) from the functions in the module.
181///
Rafael Espindola40f18832010-07-31 00:32:17 +0000182ModulePass *createBlockExtractorPass();
Chris Lattnerdf2ae522004-08-13 03:03:44 +0000183
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000184/// createStripDeadPrototypesPass - This pass removes any function declarations
185/// (prototypes) that are not used.
186ModulePass *createStripDeadPrototypesPass();
187
Andrew Lenharth9fed8f52008-09-03 21:00:28 +0000188//===----------------------------------------------------------------------===//
Duncan Sands44c8cd92008-12-31 16:14:43 +0000189/// createFunctionAttrsPass - This pass discovers functions that do not access
Duncan Sandsaf25ee72008-09-19 08:17:05 +0000190/// memory, or only read memory, and gives them the readnone/readonly attribute.
Duncan Sands44c8cd92008-12-31 16:14:43 +0000191/// It also discovers function arguments that are not captured by the function
192/// and marks them with the nocapture attribute.
Duncan Sandsaf25ee72008-09-19 08:17:05 +0000193///
Duncan Sands44c8cd92008-12-31 16:14:43 +0000194Pass *createFunctionAttrsPass();
Nick Lewyckyd01d42e2008-11-02 05:52:50 +0000195
196//===----------------------------------------------------------------------===//
197/// createMergeFunctionsPass - This pass discovers identical functions and
198/// collapses them.
199///
200ModulePass *createMergeFunctionsPass();
Duncan Sandsaf25ee72008-09-19 08:17:05 +0000201
Owen Anderson2f82e272009-06-14 08:26:32 +0000202//===----------------------------------------------------------------------===//
203/// createPartialInliningPass - This pass inlines parts of functions.
204///
205ModulePass *createPartialInliningPass();
Alex Rosenberg04b43aa2012-09-11 02:46:18 +0000206
207//===----------------------------------------------------------------------===//
208// createMetaRenamerPass - Rename everything with metasyntatic names.
209//
210ModulePass *createMetaRenamerPass();
Owen Anderson2f82e272009-06-14 08:26:32 +0000211
Chandler Carruthe8479e12012-10-18 08:05:46 +0000212//===----------------------------------------------------------------------===//
213/// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
214/// manager.
215ModulePass *createBarrierNoopPass();
216
Brian Gaeke960707c2003-11-11 22:41:34 +0000217} // End llvm namespace
218
Chris Lattnerb3f4d1b2001-10-31 04:32:53 +0000219#endif