Craig Topper | c74b600 | 2012-10-16 02:21:30 +0000 | [diff] [blame] | 1 | //===-- IPO.cpp -----------------------------------------------------------===// |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 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 | // |
Justin Bogner | 48f1f88 | 2015-10-30 23:02:38 +0000 | [diff] [blame] | 10 | // This file implements the common infrastructure (including C bindings) for |
| 11 | // libLLVMIPO.a, which implements several transformations over the LLVM |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 12 | // intermediate representation. |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Benjamin Kramer | 5a656883 | 2011-08-19 01:36:54 +0000 | [diff] [blame] | 16 | #include "llvm-c/Initialization.h" |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 17 | #include "llvm-c/Transforms/IPO.h" |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 18 | #include "llvm/InitializePasses.h" |
Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 19 | #include "llvm/IR/LegacyPassManager.h" |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 20 | #include "llvm/Transforms/IPO.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 24 | void llvm::initializeIPO(PassRegistry &Registry) { |
| 25 | initializeArgPromotionPass(Registry); |
| 26 | initializeConstantMergePass(Registry); |
Evgeniy Stepanov | 67849d5 | 2015-12-15 23:00:08 +0000 | [diff] [blame] | 27 | initializeCrossDSOCFIPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 28 | initializeDAEPass(Registry); |
| 29 | initializeDAHPass(Registry); |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 30 | initializeForceFunctionAttrsLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 31 | initializeGlobalDCEPass(Registry); |
| 32 | initializeGlobalOptPass(Registry); |
| 33 | initializeIPCPPass(Registry); |
| 34 | initializeAlwaysInlinerPass(Registry); |
| 35 | initializeSimpleInlinerPass(Registry); |
Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 36 | initializeInferFunctionAttrsLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 37 | initializeInternalizePassPass(Registry); |
| 38 | initializeLoopExtractorPass(Registry); |
| 39 | initializeBlockExtractorPassPass(Registry); |
| 40 | initializeSingleLoopExtractorPass(Registry); |
Peter Collingbourne | e6909c8 | 2015-02-20 20:30:47 +0000 | [diff] [blame] | 41 | initializeLowerBitSetsPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 42 | initializeMergeFunctionsPass(Registry); |
| 43 | initializePartialInlinerPass(Registry); |
Chandler Carruth | 1926b70 | 2016-01-08 10:55:52 +0000 | [diff] [blame^] | 44 | initializePostOrderFunctionAttrsPass(Registry); |
| 45 | initializeReversePostOrderFunctionAttrsPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 46 | initializePruneEHPass(Registry); |
Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 47 | initializeStripDeadPrototypesLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 48 | initializeStripSymbolsPass(Registry); |
| 49 | initializeStripDebugDeclarePass(Registry); |
| 50 | initializeStripDeadDebugInfoPass(Registry); |
| 51 | initializeStripNonDebugSymbolsPass(Registry); |
Hal Finkel | 26fc4c2 | 2013-12-12 20:45:08 +0000 | [diff] [blame] | 52 | initializeBarrierNoopPass(Registry); |
Rafael Espindola | 237c3a6 | 2015-07-13 14:18:22 +0000 | [diff] [blame] | 53 | initializeEliminateAvailableExternallyPass(Registry); |
Diego Novillo | 4d71113 | 2015-08-25 15:25:11 +0000 | [diff] [blame] | 54 | initializeSampleProfileLoaderPass(Registry); |
Mehdi Amini | 42418ab | 2015-11-24 06:07:49 +0000 | [diff] [blame] | 55 | initializeFunctionImportPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void LLVMInitializeIPO(LLVMPassRegistryRef R) { |
| 59 | initializeIPO(*unwrap(R)); |
| 60 | } |
| 61 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 62 | void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { |
| 63 | unwrap(PM)->add(createArgumentPromotionPass()); |
| 64 | } |
| 65 | |
| 66 | void LLVMAddConstantMergePass(LLVMPassManagerRef PM) { |
| 67 | unwrap(PM)->add(createConstantMergePass()); |
| 68 | } |
| 69 | |
| 70 | void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { |
| 71 | unwrap(PM)->add(createDeadArgEliminationPass()); |
| 72 | } |
| 73 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 74 | void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { |
Chandler Carruth | 1926b70 | 2016-01-08 10:55:52 +0000 | [diff] [blame^] | 75 | unwrap(PM)->add(createPostOrderFunctionAttrsPass()); |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { |
| 79 | unwrap(PM)->add(createFunctionInliningPass()); |
| 80 | } |
| 81 | |
Rafael Espindola | b84dc6b | 2011-07-26 15:23:23 +0000 | [diff] [blame] | 82 | void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { |
| 83 | unwrap(PM)->add(llvm::createAlwaysInlinerPass()); |
| 84 | } |
| 85 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 86 | void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { |
| 87 | unwrap(PM)->add(createGlobalDCEPass()); |
| 88 | } |
| 89 | |
| 90 | void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { |
| 91 | unwrap(PM)->add(createGlobalOptimizerPass()); |
| 92 | } |
| 93 | |
| 94 | void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { |
| 95 | unwrap(PM)->add(createIPConstantPropagationPass()); |
| 96 | } |
| 97 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 98 | void LLVMAddPruneEHPass(LLVMPassManagerRef PM) { |
| 99 | unwrap(PM)->add(createPruneEHPass()); |
| 100 | } |
| 101 | |
Wesley Peck | a2ca3fa | 2010-04-09 20:43:20 +0000 | [diff] [blame] | 102 | void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { |
| 103 | unwrap(PM)->add(createIPSCCPPass()); |
| 104 | } |
| 105 | |
| 106 | void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { |
Rafael Espindola | 4253bd8 | 2012-10-26 18:47:48 +0000 | [diff] [blame] | 107 | std::vector<const char *> Export; |
| 108 | if (AllButMain) |
| 109 | Export.push_back("main"); |
Rafael Espindola | 282a470 | 2013-10-31 20:51:58 +0000 | [diff] [blame] | 110 | unwrap(PM)->add(createInternalizePass(Export)); |
Wesley Peck | a2ca3fa | 2010-04-09 20:43:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 113 | void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { |
| 114 | unwrap(PM)->add(createStripDeadPrototypesPass()); |
| 115 | } |
| 116 | |
| 117 | void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { |
| 118 | unwrap(PM)->add(createStripSymbolsPass()); |
| 119 | } |