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 | // |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 10 | // This file implements common infrastructure for libLLVMScalarOpts.a, which |
| 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 | |
| 16 | #include "llvm-c/Transforms/Scalar.h" |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 17 | #include "llvm-c/Initialization.h" |
| 18 | #include "llvm/InitializePasses.h" |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 19 | #include "llvm/PassManager.h" |
Rafael Espindola | 0d9874b | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/Passes.h" |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/Verifier.h" |
| 22 | #include "llvm/Target/TargetData.h" |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 23 | #include "llvm/Transforms/Scalar.h" |
| 24 | |
| 25 | using namespace llvm; |
| 26 | |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 27 | /// initializeScalarOptsPasses - Initialize all passes linked into the |
| 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); |
| 54 | initializeObjCARCExpandPass(Registry); |
| 55 | initializeObjCARCContractPass(Registry); |
| 56 | initializeObjCARCOptPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 57 | initializeReassociatePass(Registry); |
| 58 | initializeRegToMemPass(Registry); |
| 59 | initializeSCCPPass(Registry); |
| 60 | initializeIPSCCPPass(Registry); |
Cameron Zwarich | b1686c3 | 2011-01-18 03:53:26 +0000 | [diff] [blame] | 61 | initializeSROA_DTPass(Registry); |
Chris Lattner | b352d6e | 2011-01-14 08:13:00 +0000 | [diff] [blame] | 62 | initializeSROA_SSAUpPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 63 | initializeCFGSimplifyPassPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 64 | initializeSimplifyLibCallsPass(Registry); |
| 65 | initializeSinkingPass(Registry); |
| 66 | initializeTailDupPass(Registry); |
| 67 | initializeTailCallElimPass(Registry); |
| 68 | } |
| 69 | |
| 70 | void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { |
| 71 | initializeScalarOpts(*unwrap(R)); |
| 72 | } |
| 73 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 74 | void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { |
| 75 | unwrap(PM)->add(createAggressiveDCEPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 78 | void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { |
| 79 | unwrap(PM)->add(createCFGSimplificationPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 82 | void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { |
| 83 | unwrap(PM)->add(createDeadStoreEliminationPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void LLVMAddGVNPass(LLVMPassManagerRef PM) { |
| 87 | unwrap(PM)->add(createGVNPass()); |
| 88 | } |
| 89 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 90 | void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { |
| 91 | unwrap(PM)->add(createIndVarSimplifyPass()); |
| 92 | } |
| 93 | |
| 94 | void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { |
| 95 | unwrap(PM)->add(createInstructionCombiningPass()); |
| 96 | } |
| 97 | |
| 98 | void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { |
| 99 | unwrap(PM)->add(createJumpThreadingPass()); |
| 100 | } |
| 101 | |
| 102 | void LLVMAddLICMPass(LLVMPassManagerRef PM) { |
| 103 | unwrap(PM)->add(createLICMPass()); |
| 104 | } |
| 105 | |
| 106 | void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { |
| 107 | unwrap(PM)->add(createLoopDeletionPass()); |
| 108 | } |
| 109 | |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 110 | void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { |
| 111 | unwrap(PM)->add(createLoopIdiomPass()); |
| 112 | } |
| 113 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 114 | void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { |
| 115 | unwrap(PM)->add(createLoopRotatePass()); |
| 116 | } |
| 117 | |
| 118 | void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { |
| 119 | unwrap(PM)->add(createLoopUnrollPass()); |
| 120 | } |
| 121 | |
| 122 | void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { |
| 123 | unwrap(PM)->add(createLoopUnswitchPass()); |
| 124 | } |
| 125 | |
| 126 | void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { |
| 127 | unwrap(PM)->add(createMemCpyOptPass()); |
| 128 | } |
| 129 | |
| 130 | void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 131 | unwrap(PM)->add(createPromoteMemoryToRegisterPass()); |
| 132 | } |
| 133 | |
| 134 | void LLVMAddReassociatePass(LLVMPassManagerRef PM) { |
| 135 | unwrap(PM)->add(createReassociatePass()); |
| 136 | } |
| 137 | |
| 138 | void LLVMAddSCCPPass(LLVMPassManagerRef PM) { |
| 139 | unwrap(PM)->add(createSCCPPass()); |
| 140 | } |
| 141 | |
| 142 | void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { |
| 143 | unwrap(PM)->add(createScalarReplAggregatesPass()); |
| 144 | } |
| 145 | |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 146 | void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { |
| 147 | unwrap(PM)->add(createScalarReplAggregatesPass(-1, false)); |
| 148 | } |
| 149 | |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 150 | void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, |
| 151 | int Threshold) { |
| 152 | unwrap(PM)->add(createScalarReplAggregatesPass(Threshold)); |
| 153 | } |
| 154 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 155 | void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { |
| 156 | unwrap(PM)->add(createSimplifyLibCallsPass()); |
| 157 | } |
| 158 | |
| 159 | void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { |
| 160 | unwrap(PM)->add(createTailCallEliminationPass()); |
| 161 | } |
| 162 | |
| 163 | void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { |
| 164 | unwrap(PM)->add(createConstantPropagationPass()); |
| 165 | } |
| 166 | |
| 167 | void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 168 | unwrap(PM)->add(createDemoteRegisterToMemoryPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 169 | } |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 170 | |
| 171 | void LLVMAddVerifierPass(LLVMPassManagerRef PM) { |
| 172 | unwrap(PM)->add(createVerifierPass()); |
| 173 | } |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 174 | |
| 175 | void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { |
| 176 | unwrap(PM)->add(createCorrelatedValuePropagationPass()); |
| 177 | } |
| 178 | |
| 179 | void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { |
| 180 | unwrap(PM)->add(createEarlyCSEPass()); |
| 181 | } |
Rafael Espindola | 0d9874b | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 182 | |
| 183 | void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 184 | unwrap(PM)->add(createTypeBasedAliasAnalysisPass()); |
| 185 | } |
| 186 | |
| 187 | void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 188 | unwrap(PM)->add(createBasicAliasAnalysisPass()); |
| 189 | } |