Chris Lattner | 259a9b2 | 2002-07-23 19:56:27 +0000 | [diff] [blame] | 1 | //===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===// |
Misha Brukman | df586aa | 2005-04-21 20:59:05 +0000 | [diff] [blame] | 2 | // |
John Criswell | b644598 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | e9cc742 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | df586aa | 2005-04-21 20:59:05 +0000 | [diff] [blame] | 7 | // |
John Criswell | b644598 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | b3f4d1b | 2001-10-31 04:32:53 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 259a9b2 | 2002-07-23 19:56:27 +0000 | [diff] [blame] | 10 | // This header file defines prototypes for accessor functions that expose passes |
| 11 | // in the IPO transformations library. |
Chris Lattner | b3f4d1b | 2001-10-31 04:32:53 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 86fa226 | 2002-07-23 19:48:52 +0000 | [diff] [blame] | 15 | #ifndef LLVM_TRANSFORMS_IPO_H |
| 16 | #define LLVM_TRANSFORMS_IPO_H |
Chris Lattner | b3f4d1b | 2001-10-31 04:32:53 +0000 | [diff] [blame] | 17 | |
Rafael Espindola | a92da5b | 2012-12-11 16:36:02 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/ArrayRef.h" |
Chris Lattner | df2ae52 | 2004-08-13 03:03:44 +0000 | [diff] [blame] | 19 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | |
Chris Lattner | 1556b27 | 2004-09-20 04:41:39 +0000 | [diff] [blame] | 22 | class ModulePass; |
Devang Patel | 13058a5 | 2007-01-26 00:47:38 +0000 | [diff] [blame] | 23 | class Pass; |
Chris Lattner | 58f9002 | 2002-11-19 18:42:59 +0000 | [diff] [blame] | 24 | class Function; |
Chris Lattner | df2ae52 | 2004-08-13 03:03:44 +0000 | [diff] [blame] | 25 | class BasicBlock; |
Andrew Lenharth | 3f13b66 | 2008-03-07 19:51:57 +0000 | [diff] [blame] | 26 | class GlobalValue; |
Chris Lattner | 8e79dbf | 2002-04-10 20:31:22 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 86fa226 | 2002-07-23 19:48:52 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4459cb2 | 2004-12-02 21:24:19 +0000 | [diff] [blame] | 29 | // |
| 30 | // These functions removes symbols from functions and modules. If OnlyDebugInfo |
| 31 | // is true, only debugging information is removed from the module. |
| 32 | // |
| 33 | ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false); |
| 34 | |
| 35 | //===----------------------------------------------------------------------===// |
Devang Patel | b5e867a | 2008-11-18 21:34:39 +0000 | [diff] [blame] | 36 | // |
Devang Patel | 66f84e7 | 2009-03-09 20:49:37 +0000 | [diff] [blame] | 37 | // These functions strips symbols from functions and modules. |
| 38 | // Only debugging information is not stripped. |
Devang Patel | b5e867a | 2008-11-18 21:34:39 +0000 | [diff] [blame] | 39 | // |
| 40 | ModulePass *createStripNonDebugSymbolsPass(); |
| 41 | |
| 42 | //===----------------------------------------------------------------------===// |
Devang Patel | 66f84e7 | 2009-03-09 20:49:37 +0000 | [diff] [blame] | 43 | // |
| 44 | // These pass removes llvm.dbg.declare intrinsics. |
| 45 | ModulePass *createStripDebugDeclarePass(); |
| 46 | |
| 47 | //===----------------------------------------------------------------------===// |
Devang Patel | 2b434e1 | 2010-07-01 19:49:20 +0000 | [diff] [blame] | 48 | // |
| 49 | // These pass removes unused symbols' debug info. |
| 50 | ModulePass *createStripDeadDebugInfoPass(); |
| 51 | |
| 52 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 53 | /// 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 Lattner | 1556b27 | 2004-09-20 04:41:39 +0000 | [diff] [blame] | 59 | ModulePass *createConstantMergePass(); |
Chris Lattner | 259a9b2 | 2002-07-23 19:56:27 +0000 | [diff] [blame] | 60 | |
| 61 | |
| 62 | //===----------------------------------------------------------------------===// |
Chris Lattner | fa3cfd3 | 2004-10-07 04:12:02 +0000 | [diff] [blame] | 63 | /// createGlobalOptimizerPass - This function returns a new pass that optimizes |
| 64 | /// non-address taken internal globals. |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 65 | /// |
Chris Lattner | fa3cfd3 | 2004-10-07 04:12:02 +0000 | [diff] [blame] | 66 | ModulePass *createGlobalOptimizerPass(); |
Chris Lattner | 14da4ea | 2004-02-25 21:34:51 +0000 | [diff] [blame] | 67 | |
| 68 | |
| 69 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 70 | /// createGlobalDCEPass - This transform is designed to eliminate unreachable |
| 71 | /// internal globals (functions or global variables) |
| 72 | /// |
Chris Lattner | 1556b27 | 2004-09-20 04:41:39 +0000 | [diff] [blame] | 73 | ModulePass *createGlobalDCEPass(); |
Chris Lattner | 8cf6e10 | 2002-07-24 17:10:58 +0000 | [diff] [blame] | 74 | |
| 75 | |
| 76 | //===----------------------------------------------------------------------===// |
Jay Foad | 6a51402 | 2011-07-26 09:36:52 +0000 | [diff] [blame] | 77 | /// createGVExtractionPass - If deleteFn is true, this pass deletes |
Andrew Lenharth | 3f13b66 | 2008-03-07 19:51:57 +0000 | [diff] [blame] | 78 | /// the specified global values. Otherwise, it deletes as much of the module as |
| 79 | /// possible, except for the global values specified. |
| 80 | /// |
| 81 | ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool |
Dan Gohman | 8f292e7 | 2010-08-26 00:22:55 +0000 | [diff] [blame] | 82 | deleteFn = false); |
Chris Lattner | 58f9002 | 2002-11-19 18:42:59 +0000 | [diff] [blame] | 83 | |
| 84 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 85 | /// createFunctionInliningPass - Return a new pass object that uses a heuristic |
| 86 | /// to inline direct function calls to small functions. |
| 87 | /// |
Jakob Stoklund Olesen | 31a7eb4 | 2010-11-02 23:40:26 +0000 | [diff] [blame] | 88 | /// The -inline-threshold command line option takes precedence over the |
| 89 | /// threshold given here. |
Devang Patel | 13058a5 | 2007-01-26 00:47:38 +0000 | [diff] [blame] | 90 | Pass *createFunctionInliningPass(); |
Chris Lattner | 22ad7ab | 2008-01-12 06:49:13 +0000 | [diff] [blame] | 91 | Pass *createFunctionInliningPass(int Threshold); |
Chris Lattner | 8cf6e10 | 2002-07-24 17:10:58 +0000 | [diff] [blame] | 92 | |
| 93 | //===----------------------------------------------------------------------===// |
Devang Patel | f58f96f | 2008-09-03 20:24:05 +0000 | [diff] [blame] | 94 | /// createAlwaysInlinerPass - Return a new pass object that inlines only |
| 95 | /// functions that are marked as "always_inline". |
| 96 | Pass *createAlwaysInlinerPass(); |
Chad Rosier | 07d37bc | 2012-02-25 02:56:01 +0000 | [diff] [blame] | 97 | Pass *createAlwaysInlinerPass(bool InsertLifetime); |
Devang Patel | f58f96f | 2008-09-03 20:24:05 +0000 | [diff] [blame] | 98 | |
| 99 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 100 | /// createPruneEHPass - Return a new pass object which transforms invoke |
| 101 | /// instructions into calls, if the callee can _not_ unwind the stack. |
| 102 | /// |
Devang Patel | 13058a5 | 2007-01-26 00:47:38 +0000 | [diff] [blame] | 103 | Pass *createPruneEHPass(); |
Chris Lattner | 994e7c2 | 2003-08-31 16:30:25 +0000 | [diff] [blame] | 104 | |
| 105 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 106 | /// createInternalizePass - This pass loops over all of the functions in the |
Rafael Espindola | cda2911 | 2013-10-03 18:29:09 +0000 | [diff] [blame^] | 107 | /// 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 Kooijman | 1b60621 | 2008-06-26 09:48:11 +0000 | [diff] [blame] | 128 | /// |
| 129 | /// Note that commandline options that are used with the above function are not |
Rafael Espindola | 4253bd8 | 2012-10-26 18:47:48 +0000 | [diff] [blame] | 130 | /// used now! |
Rafael Espindola | cda2911 | 2013-10-03 18:29:09 +0000 | [diff] [blame^] | 131 | ModulePass *createInternalizePass(ArrayRef<const char *> ExportList, |
| 132 | ArrayRef<const char *> DSOList); |
Rafael Espindola | 4253bd8 | 2012-10-26 18:47:48 +0000 | [diff] [blame] | 133 | /// createInternalizePass - Same as above, but with an empty exportList. |
| 134 | ModulePass *createInternalizePass(); |
Chris Lattner | 8cf6e10 | 2002-07-24 17:10:58 +0000 | [diff] [blame] | 135 | |
Chris Lattner | 4ff0706 | 2003-06-16 12:16:52 +0000 | [diff] [blame] | 136 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 137 | /// createDeadArgEliminationPass - This pass removes arguments from functions |
| 138 | /// which are not used by the body of the function. |
| 139 | /// |
Chris Lattner | 1556b27 | 2004-09-20 04:41:39 +0000 | [diff] [blame] | 140 | ModulePass *createDeadArgEliminationPass(); |
Chris Lattner | a2e48a8 | 2003-11-05 21:43:42 +0000 | [diff] [blame] | 141 | |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 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. |
Chris Lattner | 1556b27 | 2004-09-20 04:41:39 +0000 | [diff] [blame] | 145 | ModulePass *createDeadArgHackingPass(); |
Chris Lattner | 4ff0706 | 2003-06-16 12:16:52 +0000 | [diff] [blame] | 146 | |
Chris Lattner | e4511db | 2003-10-23 16:51:49 +0000 | [diff] [blame] | 147 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 148 | /// createArgumentPromotionPass - This pass promotes "by reference" arguments to |
Chris Lattner | eb6bb80 | 2008-04-19 19:50:01 +0000 | [diff] [blame] | 149 | /// be passed by value if the number of elements passed is smaller or |
| 150 | /// equal to maxElements (maxElements == 0 means always promote). |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 151 | /// |
Chris Lattner | eb6bb80 | 2008-04-19 19:50:01 +0000 | [diff] [blame] | 152 | Pass *createArgumentPromotionPass(unsigned maxElements = 3); |
Chris Lattner | 1f607f2 | 2004-03-07 21:30:08 +0000 | [diff] [blame] | 153 | |
| 154 | //===----------------------------------------------------------------------===// |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 155 | /// createIPConstantPropagationPass - This pass propagates constants from call |
| 156 | /// sites into the bodies of functions. |
| 157 | /// |
Chris Lattner | 1556b27 | 2004-09-20 04:41:39 +0000 | [diff] [blame] | 158 | ModulePass *createIPConstantPropagationPass(); |
Chris Lattner | e4511db | 2003-10-23 16:51:49 +0000 | [diff] [blame] | 159 | |
Chris Lattner | 3b33c7a | 2004-12-10 07:55:01 +0000 | [diff] [blame] | 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(); |
Chris Lattner | 8cf6e10 | 2002-07-24 17:10:58 +0000 | [diff] [blame] | 166 | |
| 167 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6d24a7c | 2004-03-14 02:36:34 +0000 | [diff] [blame] | 168 | // |
Jeff Cohen | 677babc | 2005-01-08 17:21:40 +0000 | [diff] [blame] | 169 | /// createLoopExtractorPass - This pass extracts all natural loops from the |
| 170 | /// program into a function if it can. |
| 171 | /// |
Dan Gohman | 9a7320c | 2009-09-28 14:37:51 +0000 | [diff] [blame] | 172 | Pass *createLoopExtractorPass(); |
Jeff Cohen | 677babc | 2005-01-08 17:21:40 +0000 | [diff] [blame] | 173 | |
Chris Lattner | f624c99 | 2004-03-14 20:00:37 +0000 | [diff] [blame] | 174 | /// createSingleLoopExtractorPass - This pass extracts one natural loop from the |
| 175 | /// program into a function if it can. This is used by bugpoint. |
| 176 | /// |
Dan Gohman | 9a7320c | 2009-09-28 14:37:51 +0000 | [diff] [blame] | 177 | Pass *createSingleLoopExtractorPass(); |
Chris Lattner | 6d24a7c | 2004-03-14 02:36:34 +0000 | [diff] [blame] | 178 | |
Reid Spencer | 3aaaa0b | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 179 | /// createBlockExtractorPass - This pass extracts all blocks (except those |
| 180 | /// specified in the argument list) from the functions in the module. |
| 181 | /// |
Rafael Espindola | 40f1883 | 2010-07-31 00:32:17 +0000 | [diff] [blame] | 182 | ModulePass *createBlockExtractorPass(); |
Chris Lattner | df2ae52 | 2004-08-13 03:03:44 +0000 | [diff] [blame] | 183 | |
Reid Spencer | 3aaaa0b | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 184 | /// createStripDeadPrototypesPass - This pass removes any function declarations |
| 185 | /// (prototypes) that are not used. |
| 186 | ModulePass *createStripDeadPrototypesPass(); |
| 187 | |
Andrew Lenharth | 9fed8f5 | 2008-09-03 21:00:28 +0000 | [diff] [blame] | 188 | //===----------------------------------------------------------------------===// |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 189 | /// createFunctionAttrsPass - This pass discovers functions that do not access |
Duncan Sands | af25ee7 | 2008-09-19 08:17:05 +0000 | [diff] [blame] | 190 | /// memory, or only read memory, and gives them the readnone/readonly attribute. |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 191 | /// It also discovers function arguments that are not captured by the function |
| 192 | /// and marks them with the nocapture attribute. |
Duncan Sands | af25ee7 | 2008-09-19 08:17:05 +0000 | [diff] [blame] | 193 | /// |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 194 | Pass *createFunctionAttrsPass(); |
Nick Lewycky | d01d42e | 2008-11-02 05:52:50 +0000 | [diff] [blame] | 195 | |
| 196 | //===----------------------------------------------------------------------===// |
| 197 | /// createMergeFunctionsPass - This pass discovers identical functions and |
| 198 | /// collapses them. |
| 199 | /// |
| 200 | ModulePass *createMergeFunctionsPass(); |
Duncan Sands | af25ee7 | 2008-09-19 08:17:05 +0000 | [diff] [blame] | 201 | |
Owen Anderson | 2f82e27 | 2009-06-14 08:26:32 +0000 | [diff] [blame] | 202 | //===----------------------------------------------------------------------===// |
| 203 | /// createPartialInliningPass - This pass inlines parts of functions. |
| 204 | /// |
| 205 | ModulePass *createPartialInliningPass(); |
Alex Rosenberg | 04b43aa | 2012-09-11 02:46:18 +0000 | [diff] [blame] | 206 | |
| 207 | //===----------------------------------------------------------------------===// |
| 208 | // createMetaRenamerPass - Rename everything with metasyntatic names. |
| 209 | // |
| 210 | ModulePass *createMetaRenamerPass(); |
Owen Anderson | 2f82e27 | 2009-06-14 08:26:32 +0000 | [diff] [blame] | 211 | |
Chandler Carruth | e8479e1 | 2012-10-18 08:05:46 +0000 | [diff] [blame] | 212 | //===----------------------------------------------------------------------===// |
| 213 | /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass |
| 214 | /// manager. |
| 215 | ModulePass *createBarrierNoopPass(); |
| 216 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 217 | } // End llvm namespace |
| 218 | |
Chris Lattner | b3f4d1b | 2001-10-31 04:32:53 +0000 | [diff] [blame] | 219 | #endif |