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" |
| 23 | #include "llvm/PassManager.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); |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 31 | initializeSampleProfileLoaderPass(Registry); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 32 | initializeConstantHoistingPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 33 | initializeConstantPropagationPass(Registry); |
| 34 | initializeCorrelatedValuePropagationPass(Registry); |
| 35 | initializeDCEPass(Registry); |
| 36 | initializeDeadInstEliminationPass(Registry); |
Richard Sandiford | 8ee1b77 | 2013-11-22 16:58:05 +0000 | [diff] [blame] | 37 | initializeScalarizerPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 38 | initializeDSEPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 39 | initializeGVNPass(Registry); |
Chris Lattner | 704541b | 2011-01-02 21:47:05 +0000 | [diff] [blame] | 40 | initializeEarlyCSEPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 41 | initializeIndVarSimplifyPass(Registry); |
| 42 | initializeJumpThreadingPass(Registry); |
| 43 | initializeLICMPass(Registry); |
| 44 | initializeLoopDeletionPass(Registry); |
Cameron Zwarich | cab9a0a | 2011-01-03 00:25:16 +0000 | [diff] [blame] | 45 | initializeLoopInstSimplifyPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 46 | initializeLoopRotatePass(Registry); |
| 47 | initializeLoopStrengthReducePass(Registry); |
Hal Finkel | bf45efd | 2013-11-16 23:59:05 +0000 | [diff] [blame] | 48 | initializeLoopRerollPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 49 | initializeLoopUnrollPass(Registry); |
| 50 | initializeLoopUnswitchPass(Registry); |
Chris Lattner | 2ef535a | 2010-12-26 19:32:44 +0000 | [diff] [blame] | 51 | initializeLoopIdiomRecognizePass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 52 | initializeLowerAtomicPass(Registry); |
Jakub Staszak | 3f158fd | 2011-07-06 18:22:43 +0000 | [diff] [blame] | 53 | initializeLowerExpectIntrinsicPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 54 | initializeMemCpyOptPass(Registry); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 55 | initializeMergedLoadStoreMotionPass(Registry); |
Richard Sandiford | 37cd6cf | 2013-08-23 10:27:02 +0000 | [diff] [blame] | 56 | initializePartiallyInlineLibCallsPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 57 | initializeReassociatePass(Registry); |
| 58 | initializeRegToMemPass(Registry); |
| 59 | initializeSCCPPass(Registry); |
| 60 | initializeIPSCCPPass(Registry); |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 61 | initializeSROAPass(Registry); |
Cameron Zwarich | 4694e69 | 2011-01-18 03:53:26 +0000 | [diff] [blame] | 62 | initializeSROA_DTPass(Registry); |
Chris Lattner | 9987a6f | 2011-01-14 08:13:00 +0000 | [diff] [blame] | 63 | initializeSROA_SSAUpPass(Registry); |
Tom Stellard | aa664d9 | 2013-08-06 02:43:45 +0000 | [diff] [blame] | 64 | initializeCFGSimplifyPassPass(Registry); |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 65 | initializeStructurizeCFGPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 66 | initializeSinkingPass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 67 | initializeTailCallElimPass(Registry); |
Eli Bendersky | a108a65 | 2014-05-01 18:38:36 +0000 | [diff] [blame] | 68 | initializeSeparateConstOffsetFromGEPPass(Registry); |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 69 | initializeLoadCombinePass(Registry); |
Owen Anderson | 4698c5d | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { |
| 73 | initializeScalarOpts(*unwrap(R)); |
| 74 | } |
| 75 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 76 | void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { |
| 77 | unwrap(PM)->add(createAggressiveDCEPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 80 | void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { |
| 81 | unwrap(PM)->add(createCFGSimplificationPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 84 | void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { |
| 85 | unwrap(PM)->add(createDeadStoreEliminationPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Richard Sandiford | 8ee1b77 | 2013-11-22 16:58:05 +0000 | [diff] [blame] | 88 | void LLVMAddScalarizerPass(LLVMPassManagerRef PM) { |
| 89 | unwrap(PM)->add(createScalarizerPass()); |
| 90 | } |
| 91 | |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 92 | void LLVMAddGVNPass(LLVMPassManagerRef PM) { |
| 93 | unwrap(PM)->add(createGVNPass()); |
| 94 | } |
| 95 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 96 | void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) { |
| 97 | unwrap(PM)->add(createMergedLoadStoreMotionPass()); |
| 98 | } |
| 99 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 100 | void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { |
| 101 | unwrap(PM)->add(createIndVarSimplifyPass()); |
| 102 | } |
| 103 | |
| 104 | void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { |
| 105 | unwrap(PM)->add(createInstructionCombiningPass()); |
| 106 | } |
| 107 | |
| 108 | void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { |
| 109 | unwrap(PM)->add(createJumpThreadingPass()); |
| 110 | } |
| 111 | |
| 112 | void LLVMAddLICMPass(LLVMPassManagerRef PM) { |
| 113 | unwrap(PM)->add(createLICMPass()); |
| 114 | } |
| 115 | |
| 116 | void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { |
| 117 | unwrap(PM)->add(createLoopDeletionPass()); |
| 118 | } |
| 119 | |
Rafael Espindola | e4e4e37 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 120 | void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { |
| 121 | unwrap(PM)->add(createLoopIdiomPass()); |
| 122 | } |
| 123 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 124 | void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { |
| 125 | unwrap(PM)->add(createLoopRotatePass()); |
| 126 | } |
| 127 | |
Hal Finkel | bf45efd | 2013-11-16 23:59:05 +0000 | [diff] [blame] | 128 | void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) { |
| 129 | unwrap(PM)->add(createLoopRerollPass()); |
| 130 | } |
| 131 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 132 | void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { |
| 133 | unwrap(PM)->add(createLoopUnrollPass()); |
| 134 | } |
| 135 | |
| 136 | void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { |
| 137 | unwrap(PM)->add(createLoopUnswitchPass()); |
| 138 | } |
| 139 | |
| 140 | void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { |
| 141 | unwrap(PM)->add(createMemCpyOptPass()); |
| 142 | } |
| 143 | |
Richard Sandiford | 37cd6cf | 2013-08-23 10:27:02 +0000 | [diff] [blame] | 144 | void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) { |
| 145 | unwrap(PM)->add(createPartiallyInlineLibCallsPass()); |
| 146 | } |
| 147 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 148 | void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 149 | unwrap(PM)->add(createPromoteMemoryToRegisterPass()); |
| 150 | } |
| 151 | |
| 152 | void LLVMAddReassociatePass(LLVMPassManagerRef PM) { |
| 153 | unwrap(PM)->add(createReassociatePass()); |
| 154 | } |
| 155 | |
| 156 | void LLVMAddSCCPPass(LLVMPassManagerRef PM) { |
| 157 | unwrap(PM)->add(createSCCPPass()); |
| 158 | } |
| 159 | |
| 160 | void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { |
| 161 | unwrap(PM)->add(createScalarReplAggregatesPass()); |
| 162 | } |
| 163 | |
Rafael Espindola | e4e4e37 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 164 | void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { |
| 165 | unwrap(PM)->add(createScalarReplAggregatesPass(-1, false)); |
| 166 | } |
| 167 | |
Nate Begeman | 5daa235 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 168 | void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, |
| 169 | int Threshold) { |
| 170 | unwrap(PM)->add(createScalarReplAggregatesPass(Threshold)); |
| 171 | } |
| 172 | |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 173 | void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { |
Meador Inge | dfb08a2 | 2013-06-20 19:48:07 +0000 | [diff] [blame] | 174 | // NOTE: The simplify-libcalls pass has been removed. |
Chris Lattner | e48f897 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { |
| 178 | unwrap(PM)->add(createTailCallEliminationPass()); |
| 179 | } |
| 180 | |
| 181 | void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { |
| 182 | unwrap(PM)->add(createConstantPropagationPass()); |
| 183 | } |
| 184 | |
| 185 | void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 186 | unwrap(PM)->add(createDemoteRegisterToMemoryPass()); |
Gordon Henriksen | 82a0e74 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 187 | } |
Nate Begeman | 5daa235 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 188 | |
| 189 | void LLVMAddVerifierPass(LLVMPassManagerRef PM) { |
| 190 | unwrap(PM)->add(createVerifierPass()); |
Duncan P. N. Exon Smith | 6ef5f28 | 2014-04-15 16:27:38 +0000 | [diff] [blame] | 191 | // FIXME: should this also add createDebugInfoVerifierPass()? |
Nate Begeman | 5daa235 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 192 | } |
Rafael Espindola | e4e4e37 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 193 | |
| 194 | void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { |
| 195 | unwrap(PM)->add(createCorrelatedValuePropagationPass()); |
| 196 | } |
| 197 | |
| 198 | void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { |
| 199 | unwrap(PM)->add(createEarlyCSEPass()); |
| 200 | } |
Rafael Espindola | 6aafb64 | 2011-04-13 15:44:58 +0000 | [diff] [blame] | 201 | |
| 202 | void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 203 | unwrap(PM)->add(createTypeBasedAliasAnalysisPass()); |
| 204 | } |
| 205 | |
| 206 | void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { |
| 207 | unwrap(PM)->add(createBasicAliasAnalysisPass()); |
| 208 | } |
Rafael Espindola | 7281395 | 2011-07-25 20:57:59 +0000 | [diff] [blame] | 209 | |
| 210 | void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { |
| 211 | unwrap(PM)->add(createLowerExpectIntrinsicPass()); |
| 212 | } |