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" |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 21 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 25 | void llvm::initializeIPO(PassRegistry &Registry) { |
| 26 | initializeArgPromotionPass(Registry); |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 27 | initializeConstantMergeLegacyPassPass(Registry); |
Evgeniy Stepanov | 67849d5 | 2015-12-15 23:00:08 +0000 | [diff] [blame] | 28 | initializeCrossDSOCFIPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 29 | initializeDAEPass(Registry); |
| 30 | initializeDAHPass(Registry); |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 31 | initializeForceFunctionAttrsLegacyPassPass(Registry); |
Davide Italiano | 66228c4 | 2016-05-03 19:39:15 +0000 | [diff] [blame] | 32 | initializeGlobalDCELegacyPassPass(Registry); |
Justin Bogner | 1a07501 | 2016-04-26 00:28:01 +0000 | [diff] [blame] | 33 | initializeGlobalOptLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 34 | initializeIPCPPass(Registry); |
| 35 | initializeAlwaysInlinerPass(Registry); |
| 36 | initializeSimpleInlinerPass(Registry); |
Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 37 | initializeInferFunctionAttrsLegacyPassPass(Registry); |
Justin Bogner | 4563a06 | 2016-04-26 20:15:52 +0000 | [diff] [blame] | 38 | initializeInternalizeLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 39 | initializeLoopExtractorPass(Registry); |
| 40 | initializeBlockExtractorPassPass(Registry); |
| 41 | initializeSingleLoopExtractorPass(Registry); |
Peter Collingbourne | e6909c8 | 2015-02-20 20:30:47 +0000 | [diff] [blame] | 42 | initializeLowerBitSetsPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 43 | initializeMergeFunctionsPass(Registry); |
| 44 | initializePartialInlinerPass(Registry); |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 45 | initializePostOrderFunctionAttrsLegacyPassPass(Registry); |
Sean Silva | f508019 | 2016-06-12 07:48:51 +0000 | [diff] [blame] | 46 | initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 47 | initializePruneEHPass(Registry); |
Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 48 | initializeStripDeadPrototypesLegacyPassPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 49 | initializeStripSymbolsPass(Registry); |
| 50 | initializeStripDebugDeclarePass(Registry); |
| 51 | initializeStripDeadDebugInfoPass(Registry); |
| 52 | initializeStripNonDebugSymbolsPass(Registry); |
Hal Finkel | 26fc4c2 | 2013-12-12 20:45:08 +0000 | [diff] [blame] | 53 | initializeBarrierNoopPass(Registry); |
Davide Italiano | 344e838 | 2016-05-05 02:37:32 +0000 | [diff] [blame] | 54 | initializeEliminateAvailableExternallyLegacyPassPass(Registry); |
Xinliang David Li | e897edb | 2016-05-27 22:30:44 +0000 | [diff] [blame] | 55 | initializeSampleProfileLoaderLegacyPassPass(Registry); |
Mehdi Amini | 42418ab | 2015-11-24 06:07:49 +0000 | [diff] [blame] | 56 | initializeFunctionImportPassPass(Registry); |
Peter Collingbourne | df49d1b | 2016-02-09 22:50:34 +0000 | [diff] [blame] | 57 | initializeWholeProgramDevirtPass(Registry); |
Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void LLVMInitializeIPO(LLVMPassRegistryRef R) { |
| 61 | initializeIPO(*unwrap(R)); |
| 62 | } |
| 63 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 64 | void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { |
| 65 | unwrap(PM)->add(createArgumentPromotionPass()); |
| 66 | } |
| 67 | |
| 68 | void LLVMAddConstantMergePass(LLVMPassManagerRef PM) { |
| 69 | unwrap(PM)->add(createConstantMergePass()); |
| 70 | } |
| 71 | |
| 72 | void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { |
| 73 | unwrap(PM)->add(createDeadArgEliminationPass()); |
| 74 | } |
| 75 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 76 | void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 77 | unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass()); |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { |
| 81 | unwrap(PM)->add(createFunctionInliningPass()); |
| 82 | } |
| 83 | |
Rafael Espindola | b84dc6b | 2011-07-26 15:23:23 +0000 | [diff] [blame] | 84 | void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { |
| 85 | unwrap(PM)->add(llvm::createAlwaysInlinerPass()); |
| 86 | } |
| 87 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 88 | void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { |
| 89 | unwrap(PM)->add(createGlobalDCEPass()); |
| 90 | } |
| 91 | |
| 92 | void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { |
| 93 | unwrap(PM)->add(createGlobalOptimizerPass()); |
| 94 | } |
| 95 | |
| 96 | void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { |
| 97 | unwrap(PM)->add(createIPConstantPropagationPass()); |
| 98 | } |
| 99 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 100 | void LLVMAddPruneEHPass(LLVMPassManagerRef PM) { |
| 101 | unwrap(PM)->add(createPruneEHPass()); |
| 102 | } |
| 103 | |
Wesley Peck | a2ca3fa | 2010-04-09 20:43:20 +0000 | [diff] [blame] | 104 | void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { |
| 105 | unwrap(PM)->add(createIPSCCPPass()); |
| 106 | } |
| 107 | |
| 108 | void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame] | 109 | auto PreserveMain = [=](const GlobalValue &GV) { |
| 110 | return AllButMain && GV.getName() == "main"; |
| 111 | }; |
| 112 | unwrap(PM)->add(createInternalizePass(PreserveMain)); |
Wesley Peck | a2ca3fa | 2010-04-09 20:43:20 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 115 | void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { |
| 116 | unwrap(PM)->add(createStripDeadPrototypesPass()); |
| 117 | } |
| 118 | |
| 119 | void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { |
| 120 | unwrap(PM)->add(createStripSymbolsPass()); |
| 121 | } |