Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 1 | //===-- Scalar.cpp --------------------------------------------------------===// |
| 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 | // |
Nadav Rotem | a94d6e8 | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 10 | // This file implements common infrastructure for libLLVMScalarOpts.a, which |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 11 | // implements several scalar transformations over the LLVM intermediate |
| 12 | // representation, including the C bindings for that library. |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/Transforms/Scalar.h" |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 17 | #include "llvm-c/Initialization.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm-c/Transforms/Scalar.h" |
Rafael Espindola | 0d9874b | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/Passes.h" |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/Verifier.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DataLayout.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/InitializePasses.h" |
| 23 | #include "llvm/PassManager.h" |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace llvm; |
| 26 | |
Nadav Rotem | a94d6e8 | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 27 | /// initializeScalarOptsPasses - Initialize all passes linked into the |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 28 | /// ScalarOpts library. |
| 29 | void llvm::initializeScalarOpts(PassRegistry &Registry) { |
| 30 | initializeADCEPass(Registry); |
| 31 | initializeBlockPlacementPass(Registry); |
| 32 | initializeCodeGenPreparePass(Registry); |
| 33 | initializeConstantPropagationPass(Registry); |
| 34 | initializeCorrelatedValuePropagationPass(Registry); |
| 35 | initializeDCEPass(Registry); |
| 36 | initializeDeadInstEliminationPass(Registry); |
| 37 | initializeDSEPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 38 | initializeGVNPass(Registry); |
Chris Lattner | 12be936 | 2011-01-02 21:47:05 +0000 | [diff] [blame] | 39 | initializeEarlyCSEPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 40 | initializeIndVarSimplifyPass(Registry); |
| 41 | initializeJumpThreadingPass(Registry); |
| 42 | initializeLICMPass(Registry); |
| 43 | initializeLoopDeletionPass(Registry); |
Cameron Zwarich | 832f611 | 2011-01-03 00:25:16 +0000 | [diff] [blame] | 44 | initializeLoopInstSimplifyPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 45 | initializeLoopRotatePass(Registry); |
| 46 | initializeLoopStrengthReducePass(Registry); |
| 47 | initializeLoopUnrollPass(Registry); |
| 48 | initializeLoopUnswitchPass(Registry); |
Chris Lattner | b0db161 | 2010-12-26 19:32:44 +0000 | [diff] [blame] | 49 | initializeLoopIdiomRecognizePass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 50 | initializeLowerAtomicPass(Registry); |
Jakub Staszak | 9da9934 | 2011-07-06 18:22:43 +0000 | [diff] [blame] | 51 | initializeLowerExpectIntrinsicPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 52 | initializeMemCpyOptPass(Registry); |
John McCall | 9fbd318 | 2011-06-15 23:37:01 +0000 | [diff] [blame] | 53 | initializeObjCARCAliasAnalysisPass(Registry); |
Dan Gohman | 2f6263c | 2012-01-17 20:52:24 +0000 | [diff] [blame] | 54 | initializeObjCARCAPElimPass(Registry); |
John McCall | 9fbd318 | 2011-06-15 23:37:01 +0000 | [diff] [blame] | 55 | initializeObjCARCExpandPass(Registry); |
| 56 | initializeObjCARCContractPass(Registry); |
| 57 | initializeObjCARCOptPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 58 | initializeReassociatePass(Registry); |
| 59 | initializeRegToMemPass(Registry); |
| 60 | initializeSCCPPass(Registry); |
| 61 | initializeIPSCCPPass(Registry); |
Chandler Carruth | 713aa94 | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 62 | initializeSROAPass(Registry); |
Cameron Zwarich | b1686c3 | 2011-01-18 03:53:26 +0000 | [diff] [blame] | 63 | initializeSROA_DTPass(Registry); |
Chris Lattner | b352d6e | 2011-01-14 08:13:00 +0000 | [diff] [blame] | 64 | initializeSROA_SSAUpPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 65 | initializeCFGSimplifyPassPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 66 | initializeSimplifyLibCallsPass(Registry); |
| 67 | initializeSinkingPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 68 | initializeTailCallElimPass(Registry); |
| 69 | } |
| 70 | |
| 71 | void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { |
| 72 | initializeScalarOpts(*unwrap(R)); |
| 73 | } |
| 74 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 75 | void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { |
| 76 | unwrap(PM)->add(createAggressiveDCEPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 79 | void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { |
| 80 | unwrap(PM)->add(createCFGSimplificationPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 83 | void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { |
| 84 | unwrap(PM)->add(createDeadStoreEliminationPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void LLVMAddGVNPass(LLVMPassManagerRef PM) { |
| 88 | unwrap(PM)->add(createGVNPass()); |
| 89 | } |
| 90 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 91 | void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { |
| 92 | unwrap(PM)->add(createIndVarSimplifyPass()); |
| 93 | } |
| 94 | |
| 95 | void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { |
| 96 | unwrap(PM)->add(createInstructionCombiningPass()); |
| 97 | } |
| 98 | |
| 99 | void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { |
| 100 | unwrap(PM)->add(createJumpThreadingPass()); |
| 101 | } |
| 102 | |
| 103 | void LLVMAddLICMPass(LLVMPassManagerRef PM) { |
| 104 | unwrap(PM)->add(createLICMPass()); |
| 105 | } |
| 106 | |
| 107 | void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { |
| 108 | unwrap(PM)->add(createLoopDeletionPass()); |
| 109 | } |
| 110 | |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 111 | void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { |
| 112 | unwrap(PM)->add(createLoopIdiomPass()); |
| 113 | } |
| 114 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 115 | void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { |
| 116 | unwrap(PM)->add(createLoopRotatePass()); |
| 117 | } |
| 118 | |
| 119 | void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { |
| 120 | unwrap(PM)->add(createLoopUnrollPass()); |
| 121 | } |
| 122 | |
| 123 | void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { |
| 124 | unwrap(PM)->add(createLoopUnswitchPass()); |
| 125 | } |
| 126 | |
| 127 | void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { |
| 128 | unwrap(PM)->add(createMemCpyOptPass()); |
| 129 | } |
| 130 | |
| 131 | void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 132 | unwrap(PM)->add(createPromoteMemoryToRegisterPass()); |
| 133 | } |
| 134 | |
| 135 | void LLVMAddReassociatePass(LLVMPassManagerRef PM) { |
| 136 | unwrap(PM)->add(createReassociatePass()); |
| 137 | } |
| 138 | |
| 139 | void LLVMAddSCCPPass(LLVMPassManagerRef PM) { |
| 140 | unwrap(PM)->add(createSCCPPass()); |
| 141 | } |
| 142 | |
| 143 | void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { |
| 144 | unwrap(PM)->add(createScalarReplAggregatesPass()); |
| 145 | } |
| 146 | |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 147 | void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { |
| 148 | unwrap(PM)->add(createScalarReplAggregatesPass(-1, false)); |
| 149 | } |
| 150 | |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 151 | void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, |
| 152 | int Threshold) { |
| 153 | unwrap(PM)->add(createScalarReplAggregatesPass(Threshold)); |
| 154 | } |
| 155 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 156 | void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { |
| 157 | unwrap(PM)->add(createSimplifyLibCallsPass()); |
| 158 | } |
| 159 | |
| 160 | void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { |
| 161 | unwrap(PM)->add(createTailCallEliminationPass()); |
| 162 | } |
| 163 | |
| 164 | void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { |
| 165 | unwrap(PM)->add(createConstantPropagationPass()); |
| 166 | } |
| 167 | |
| 168 | void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 169 | unwrap(PM)->add(createDemoteRegisterToMemoryPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 170 | } |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 171 | |
| 172 | void LLVMAddVerifierPass(LLVMPassManagerRef PM) { |
| 173 | unwrap(PM)->add(createVerifierPass()); |
| 174 | } |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 175 | |
| 176 | void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { |
| 177 | unwrap(PM)->add(createCorrelatedValuePropagationPass()); |
| 178 | } |
| 179 | |
| 180 | void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { |
| 181 | unwrap(PM)->add(createEarlyCSEPass()); |
| 182 | } |
Rafael Espindola | 0d9874b | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 183 | |
| 184 | void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 185 | unwrap(PM)->add(createTypeBasedAliasAnalysisPass()); |
| 186 | } |
| 187 | |
| 188 | void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 189 | unwrap(PM)->add(createBasicAliasAnalysisPass()); |
| 190 | } |
Rafael Espindola | 0335a14 | 2011-07-25 20:57:59 +0000 | [diff] [blame] | 191 | |
| 192 | void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { |
| 193 | unwrap(PM)->add(createLowerExpectIntrinsicPass()); |
| 194 | } |