Gordon Henriksen | 82a0e74 | 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 | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 10 | // This file implements common infrastructure for libLLVMScalarOpts.a, which |
Owen Anderson | 4698c5d | 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 | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/Transforms/Scalar.h" |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 17 | #include "llvm-c/Initialization.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm-c/Transforms/Scalar.h" |
Rafael Espindola | 6aafb64 | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/Passes.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/DataLayout.h" |
Chandler Carruth | 5ad5f15 | 2014-01-13 09:26:24 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/InitializePasses.h" |
Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 23 | #include "llvm/IR/LegacyPassManager.h" |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace llvm; |
| 26 | |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 27 | /// initializeScalarOptsPasses - Initialize all passes linked into the |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 28 | /// ScalarOpts library. |
| 29 | void llvm::initializeScalarOpts(PassRegistry &Registry) { |
| 30 | initializeADCEPass(Registry); |
Hal Finkel | 2bb61ba | 2015-02-17 01:36:59 +0000 | [diff] [blame] | 31 | initializeBDCEPass(Registry); |
Hal Finkel | d67e463 | 2014-09-07 20:05:11 +0000 | [diff] [blame] | 32 | initializeAlignmentFromAssumptionsPass(Registry); |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 33 | initializeSampleProfileLoaderPass(Registry); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 34 | initializeConstantHoistingPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 35 | initializeConstantPropagationPass(Registry); |
| 36 | initializeCorrelatedValuePropagationPass(Registry); |
| 37 | initializeDCEPass(Registry); |
| 38 | initializeDeadInstEliminationPass(Registry); |
Richard Sandiford | 8ee1b77 | 2013-11-22 16:58:05 +0000 | [diff] [blame] | 39 | initializeScalarizerPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 40 | initializeDSEPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 41 | initializeGVNPass(Registry); |
Chandler Carruth | d649c0a | 2015-01-27 01:34:14 +0000 | [diff] [blame] | 42 | initializeEarlyCSELegacyPassPass(Registry); |
Jan Vesely | 5a956d4 | 2014-08-13 20:31:52 +0000 | [diff] [blame] | 43 | initializeFlattenCFGPassPass(Registry); |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 44 | initializeInductiveRangeCheckEliminationPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 45 | initializeIndVarSimplifyPass(Registry); |
| 46 | initializeJumpThreadingPass(Registry); |
| 47 | initializeLICMPass(Registry); |
| 48 | initializeLoopDeletionPass(Registry); |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 49 | initializeLoopAccessAnalysisPass(Registry); |
Cameron Zwarich | cab9a0a | 2011-01-03 00:25:16 +0000 | [diff] [blame] | 50 | initializeLoopInstSimplifyPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 51 | initializeLoopRotatePass(Registry); |
| 52 | initializeLoopStrengthReducePass(Registry); |
Hal Finkel | bf45efd | 2013-11-16 23:59:05 +0000 | [diff] [blame] | 53 | initializeLoopRerollPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 54 | initializeLoopUnrollPass(Registry); |
| 55 | initializeLoopUnswitchPass(Registry); |
Chris Lattner | 2ef535a | 2010-12-26 19:32:44 +0000 | [diff] [blame] | 56 | initializeLoopIdiomRecognizePass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 57 | initializeLowerAtomicPass(Registry); |
Jakub Staszak | 3f158fd | 2011-07-06 18:22:43 +0000 | [diff] [blame] | 58 | initializeLowerExpectIntrinsicPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 59 | initializeMemCpyOptPass(Registry); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 60 | initializeMergedLoadStoreMotionPass(Registry); |
Richard Sandiford | 37cd6cf | 2013-08-23 10:27:02 +0000 | [diff] [blame] | 61 | initializePartiallyInlineLibCallsPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 62 | initializeReassociatePass(Registry); |
| 63 | initializeRegToMemPass(Registry); |
Philip Reames | d16a9b1 | 2015-02-20 01:06:44 +0000 | [diff] [blame^] | 64 | initializeRewriteStatepointsForGCPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 65 | initializeSCCPPass(Registry); |
| 66 | initializeIPSCCPPass(Registry); |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 67 | initializeSROAPass(Registry); |
Cameron Zwarich | 4694e69 | 2011-01-18 03:53:26 +0000 | [diff] [blame] | 68 | initializeSROA_DTPass(Registry); |
Chris Lattner | 9987a6f | 2011-01-14 08:13:00 +0000 | [diff] [blame] | 69 | initializeSROA_SSAUpPass(Registry); |
Tom Stellard | aa664d9 | 2013-08-06 02:43:45 +0000 | [diff] [blame] | 70 | initializeCFGSimplifyPassPass(Registry); |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 71 | initializeStructurizeCFGPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 72 | initializeSinkingPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 73 | initializeTailCallElimPass(Registry); |
Eli Bendersky | a108a65 | 2014-05-01 18:38:36 +0000 | [diff] [blame] | 74 | initializeSeparateConstOffsetFromGEPPass(Registry); |
Jingyue Wu | d7966ff | 2015-02-03 19:37:06 +0000 | [diff] [blame] | 75 | initializeStraightLineStrengthReducePass(Registry); |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 76 | initializeLoadCombinePass(Registry); |
Philip Reames | 47cc673 | 2015-02-04 00:37:33 +0000 | [diff] [blame] | 77 | initializePlaceBackedgeSafepointsImplPass(Registry); |
| 78 | initializePlaceSafepointsPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { |
| 82 | initializeScalarOpts(*unwrap(R)); |
| 83 | } |
| 84 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 85 | void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { |
| 86 | unwrap(PM)->add(createAggressiveDCEPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Hal Finkel | 2bb61ba | 2015-02-17 01:36:59 +0000 | [diff] [blame] | 89 | void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) { |
| 90 | unwrap(PM)->add(createBitTrackingDCEPass()); |
| 91 | } |
| 92 | |
Hal Finkel | d67e463 | 2014-09-07 20:05:11 +0000 | [diff] [blame] | 93 | void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) { |
| 94 | unwrap(PM)->add(createAlignmentFromAssumptionsPass()); |
| 95 | } |
| 96 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 97 | void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { |
| 98 | unwrap(PM)->add(createCFGSimplificationPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 101 | void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { |
| 102 | unwrap(PM)->add(createDeadStoreEliminationPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Richard Sandiford | 8ee1b77 | 2013-11-22 16:58:05 +0000 | [diff] [blame] | 105 | void LLVMAddScalarizerPass(LLVMPassManagerRef PM) { |
| 106 | unwrap(PM)->add(createScalarizerPass()); |
| 107 | } |
| 108 | |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 109 | void LLVMAddGVNPass(LLVMPassManagerRef PM) { |
| 110 | unwrap(PM)->add(createGVNPass()); |
| 111 | } |
| 112 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 113 | void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) { |
| 114 | unwrap(PM)->add(createMergedLoadStoreMotionPass()); |
| 115 | } |
| 116 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 117 | void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { |
| 118 | unwrap(PM)->add(createIndVarSimplifyPass()); |
| 119 | } |
| 120 | |
| 121 | void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { |
| 122 | unwrap(PM)->add(createInstructionCombiningPass()); |
| 123 | } |
| 124 | |
| 125 | void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { |
| 126 | unwrap(PM)->add(createJumpThreadingPass()); |
| 127 | } |
| 128 | |
| 129 | void LLVMAddLICMPass(LLVMPassManagerRef PM) { |
| 130 | unwrap(PM)->add(createLICMPass()); |
| 131 | } |
| 132 | |
| 133 | void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { |
| 134 | unwrap(PM)->add(createLoopDeletionPass()); |
| 135 | } |
| 136 | |
Rafael Espindola | e4e4e37 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 137 | void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { |
| 138 | unwrap(PM)->add(createLoopIdiomPass()); |
| 139 | } |
| 140 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 141 | void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { |
| 142 | unwrap(PM)->add(createLoopRotatePass()); |
| 143 | } |
| 144 | |
Hal Finkel | bf45efd | 2013-11-16 23:59:05 +0000 | [diff] [blame] | 145 | void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) { |
| 146 | unwrap(PM)->add(createLoopRerollPass()); |
| 147 | } |
| 148 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 149 | void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { |
| 150 | unwrap(PM)->add(createLoopUnrollPass()); |
| 151 | } |
| 152 | |
| 153 | void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { |
| 154 | unwrap(PM)->add(createLoopUnswitchPass()); |
| 155 | } |
| 156 | |
| 157 | void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { |
| 158 | unwrap(PM)->add(createMemCpyOptPass()); |
| 159 | } |
| 160 | |
Richard Sandiford | 37cd6cf | 2013-08-23 10:27:02 +0000 | [diff] [blame] | 161 | void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) { |
| 162 | unwrap(PM)->add(createPartiallyInlineLibCallsPass()); |
| 163 | } |
| 164 | |
Juergen Ributzka | 14ae604 | 2014-09-11 21:32:32 +0000 | [diff] [blame] | 165 | void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM) { |
| 166 | unwrap(PM)->add(createLowerSwitchPass()); |
| 167 | } |
| 168 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 169 | void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 170 | unwrap(PM)->add(createPromoteMemoryToRegisterPass()); |
| 171 | } |
| 172 | |
| 173 | void LLVMAddReassociatePass(LLVMPassManagerRef PM) { |
| 174 | unwrap(PM)->add(createReassociatePass()); |
| 175 | } |
| 176 | |
| 177 | void LLVMAddSCCPPass(LLVMPassManagerRef PM) { |
| 178 | unwrap(PM)->add(createSCCPPass()); |
| 179 | } |
| 180 | |
| 181 | void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { |
| 182 | unwrap(PM)->add(createScalarReplAggregatesPass()); |
| 183 | } |
| 184 | |
Rafael Espindola | e4e4e37 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 185 | void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { |
| 186 | unwrap(PM)->add(createScalarReplAggregatesPass(-1, false)); |
| 187 | } |
| 188 | |
Nate Begeman | 5daa235 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 189 | void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, |
| 190 | int Threshold) { |
| 191 | unwrap(PM)->add(createScalarReplAggregatesPass(Threshold)); |
| 192 | } |
| 193 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 194 | void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { |
Meador Inge | dfb08a2 | 2013-06-20 19:48:07 +0000 | [diff] [blame] | 195 | // NOTE: The simplify-libcalls pass has been removed. |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { |
| 199 | unwrap(PM)->add(createTailCallEliminationPass()); |
| 200 | } |
| 201 | |
| 202 | void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { |
| 203 | unwrap(PM)->add(createConstantPropagationPass()); |
| 204 | } |
| 205 | |
| 206 | void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 207 | unwrap(PM)->add(createDemoteRegisterToMemoryPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 208 | } |
Nate Begeman | 5daa235 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 209 | |
| 210 | void LLVMAddVerifierPass(LLVMPassManagerRef PM) { |
| 211 | unwrap(PM)->add(createVerifierPass()); |
Duncan P. N. Exon Smith | 6ef5f28 | 2014-04-15 16:27:38 +0000 | [diff] [blame] | 212 | // FIXME: should this also add createDebugInfoVerifierPass()? |
Nate Begeman | 5daa235 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 213 | } |
Rafael Espindola | e4e4e37 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 214 | |
| 215 | void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { |
| 216 | unwrap(PM)->add(createCorrelatedValuePropagationPass()); |
| 217 | } |
| 218 | |
| 219 | void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { |
| 220 | unwrap(PM)->add(createEarlyCSEPass()); |
| 221 | } |
Rafael Espindola | 6aafb64 | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 222 | |
| 223 | void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 224 | unwrap(PM)->add(createTypeBasedAliasAnalysisPass()); |
| 225 | } |
| 226 | |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 227 | void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) { |
| 228 | unwrap(PM)->add(createScopedNoAliasAAPass()); |
| 229 | } |
| 230 | |
Rafael Espindola | 6aafb64 | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 231 | void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 232 | unwrap(PM)->add(createBasicAliasAnalysisPass()); |
| 233 | } |
Rafael Espindola | 7281395 | 2011-07-25 20:57:59 +0000 | [diff] [blame] | 234 | |
| 235 | void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { |
| 236 | unwrap(PM)->add(createLowerExpectIntrinsicPass()); |
| 237 | } |