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