| 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 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| Justin Bogner | 48f1f88 | 2015-10-30 23:02:38 +0000 | [diff] [blame] | 9 | // This file implements the common infrastructure (including C bindings) for |
| 10 | // libLLVMIPO.a, which implements several transformations over the LLVM |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 11 | // intermediate representation. |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm-c/Transforms/IPO.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "llvm-c/Initialization.h" |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 17 | #include "llvm/IR/LegacyPassManager.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 18 | #include "llvm/InitializePasses.h" |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 19 | #include "llvm/Transforms/IPO.h" |
| Chandler Carruth | 67fc52f | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 20 | #include "llvm/Transforms/IPO/AlwaysInliner.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); |
| Matthew Simpson | cb58558 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 27 | initializeCalledValuePropagationLegacyPassPass(Registry); |
| Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 28 | initializeConstantMergeLegacyPassPass(Registry); |
| Evgeniy Stepanov | 67849d5 | 2015-12-15 23:00:08 +0000 | [diff] [blame] | 29 | initializeCrossDSOCFIPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 30 | initializeDAEPass(Registry); |
| 31 | initializeDAHPass(Registry); |
| Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 32 | initializeForceFunctionAttrsLegacyPassPass(Registry); |
| Davide Italiano | 66228c4 | 2016-05-03 19:39:15 +0000 | [diff] [blame] | 33 | initializeGlobalDCELegacyPassPass(Registry); |
| Justin Bogner | 1a07501 | 2016-04-26 00:28:01 +0000 | [diff] [blame] | 34 | initializeGlobalOptLegacyPassPass(Registry); |
| Peter Collingbourne | f72a8d4 | 2016-11-16 23:40:26 +0000 | [diff] [blame] | 35 | initializeGlobalSplitPass(Registry); |
| Aditya Kumar | 801394a | 2018-09-07 15:03:49 +0000 | [diff] [blame] | 36 | initializeHotColdSplittingLegacyPassPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 37 | initializeIPCPPass(Registry); |
| Chandler Carruth | 67fc52f | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 38 | initializeAlwaysInlinerLegacyPassPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 39 | initializeSimpleInlinerPass(Registry); |
| Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 40 | initializeInferFunctionAttrsLegacyPassPass(Registry); |
| Justin Bogner | 4563a06 | 2016-04-26 20:15:52 +0000 | [diff] [blame] | 41 | initializeInternalizeLegacyPassPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 42 | initializeLoopExtractorPass(Registry); |
| Volkan Keles | dc40be7 | 2018-01-23 21:51:34 +0000 | [diff] [blame] | 43 | initializeBlockExtractorPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 44 | initializeSingleLoopExtractorPass(Registry); |
| Peter Collingbourne | 7efd750 | 2016-06-24 21:21:32 +0000 | [diff] [blame] | 45 | initializeLowerTypeTestsPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 46 | initializeMergeFunctionsPass(Registry); |
| Easwaran Raman | 1832bf6 | 2016-06-27 16:50:18 +0000 | [diff] [blame] | 47 | initializePartialInlinerLegacyPassPass(Registry); |
| Johannes Doerfert | aade782 | 2019-06-05 03:02:24 +0000 | [diff] [blame] | 48 | initializeAttributorLegacyPassPass(Registry); |
| Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 49 | initializePostOrderFunctionAttrsLegacyPassPass(Registry); |
| Sean Silva | f508019 | 2016-06-12 07:48:51 +0000 | [diff] [blame] | 50 | initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 51 | initializePruneEHPass(Registry); |
| David Blaikie | 376294c | 2018-03-22 22:07:53 +0000 | [diff] [blame] | 52 | initializeIPSCCPLegacyPassPass(Registry); |
| Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 53 | initializeStripDeadPrototypesLegacyPassPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 54 | initializeStripSymbolsPass(Registry); |
| 55 | initializeStripDebugDeclarePass(Registry); |
| 56 | initializeStripDeadDebugInfoPass(Registry); |
| 57 | initializeStripNonDebugSymbolsPass(Registry); |
| Hal Finkel | 26fc4c2 | 2013-12-12 20:45:08 +0000 | [diff] [blame] | 58 | initializeBarrierNoopPass(Registry); |
| Davide Italiano | 344e838 | 2016-05-05 02:37:32 +0000 | [diff] [blame] | 59 | initializeEliminateAvailableExternallyLegacyPassPass(Registry); |
| Xinliang David Li | e897edb | 2016-05-27 22:30:44 +0000 | [diff] [blame] | 60 | initializeSampleProfileLoaderLegacyPassPass(Registry); |
| Teresa Johnson | 2124157 | 2016-07-18 21:22:24 +0000 | [diff] [blame] | 61 | initializeFunctionImportLegacyPassPass(Registry); |
| Peter Collingbourne | df49d1b | 2016-02-09 22:50:34 +0000 | [diff] [blame] | 62 | initializeWholeProgramDevirtPass(Registry); |
| Owen Anderson | bf70a03 | 2010-10-07 18:09:59 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void LLVMInitializeIPO(LLVMPassRegistryRef R) { |
| 66 | initializeIPO(*unwrap(R)); |
| 67 | } |
| 68 | |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 69 | void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { |
| 70 | unwrap(PM)->add(createArgumentPromotionPass()); |
| 71 | } |
| 72 | |
| Matthew Simpson | cb58558 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 73 | void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) { |
| 74 | unwrap(PM)->add(createCalledValuePropagationPass()); |
| 75 | } |
| 76 | |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 77 | void LLVMAddConstantMergePass(LLVMPassManagerRef PM) { |
| 78 | unwrap(PM)->add(createConstantMergePass()); |
| 79 | } |
| 80 | |
| 81 | void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { |
| 82 | unwrap(PM)->add(createDeadArgEliminationPass()); |
| 83 | } |
| 84 | |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 85 | void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { |
| Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 86 | unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass()); |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { |
| 90 | unwrap(PM)->add(createFunctionInliningPass()); |
| 91 | } |
| 92 | |
| Rafael Espindola | b84dc6b | 2011-07-26 15:23:23 +0000 | [diff] [blame] | 93 | void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { |
| Chandler Carruth | 67fc52f | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 94 | unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass()); |
| Rafael Espindola | b84dc6b | 2011-07-26 15:23:23 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 97 | void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { |
| 98 | unwrap(PM)->add(createGlobalDCEPass()); |
| 99 | } |
| 100 | |
| 101 | void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { |
| 102 | unwrap(PM)->add(createGlobalOptimizerPass()); |
| 103 | } |
| 104 | |
| 105 | void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { |
| 106 | unwrap(PM)->add(createIPConstantPropagationPass()); |
| 107 | } |
| 108 | |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 109 | void LLVMAddPruneEHPass(LLVMPassManagerRef PM) { |
| 110 | unwrap(PM)->add(createPruneEHPass()); |
| 111 | } |
| 112 | |
| Wesley Peck | a2ca3fa | 2010-04-09 20:43:20 +0000 | [diff] [blame] | 113 | void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { |
| 114 | unwrap(PM)->add(createIPSCCPPass()); |
| 115 | } |
| 116 | |
| 117 | void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { |
| Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame] | 118 | auto PreserveMain = [=](const GlobalValue &GV) { |
| 119 | return AllButMain && GV.getName() == "main"; |
| 120 | }; |
| 121 | unwrap(PM)->add(createInternalizePass(PreserveMain)); |
| Wesley Peck | a2ca3fa | 2010-04-09 20:43:20 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| Robert Widmann | fcf3c55 | 2019-07-23 04:56:44 +0000 | [diff] [blame] | 124 | void LLVMAddInternalizePassWithMustPreservePredicate( |
| 125 | LLVMPassManagerRef PM, |
| 126 | void *Context, |
| 127 | LLVMBool (*Pred)(LLVMValueRef, void *)) { |
| 128 | unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) { |
| 129 | return Pred(wrap(&GV), Context) == 0 ? false : true; |
| 130 | })); |
| 131 | } |
| 132 | |
| Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 133 | void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { |
| 134 | unwrap(PM)->add(createStripDeadPrototypesPass()); |
| 135 | } |
| 136 | |
| 137 | void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { |
| 138 | unwrap(PM)->add(createStripSymbolsPass()); |
| 139 | } |