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