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