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" |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/Verifier.h" |
| 21 | #include "llvm/Target/TargetData.h" |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 22 | #include "llvm/Transforms/Scalar.h" |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 26 | /// initializeScalarOptsPasses - Initialize all passes linked into the |
| 27 | /// ScalarOpts library. |
| 28 | void llvm::initializeScalarOpts(PassRegistry &Registry) { |
| 29 | initializeADCEPass(Registry); |
| 30 | initializeBlockPlacementPass(Registry); |
| 31 | initializeCodeGenPreparePass(Registry); |
| 32 | initializeConstantPropagationPass(Registry); |
| 33 | initializeCorrelatedValuePropagationPass(Registry); |
| 34 | initializeDCEPass(Registry); |
| 35 | initializeDeadInstEliminationPass(Registry); |
| 36 | initializeDSEPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 37 | initializeGVNPass(Registry); |
Chris Lattner | 12be936 | 2011-01-02 21:47:05 +0000 | [diff] [blame] | 38 | initializeEarlyCSEPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 39 | initializeIndVarSimplifyPass(Registry); |
| 40 | initializeJumpThreadingPass(Registry); |
| 41 | initializeLICMPass(Registry); |
| 42 | initializeLoopDeletionPass(Registry); |
Cameron Zwarich | 832f611 | 2011-01-03 00:25:16 +0000 | [diff] [blame] | 43 | initializeLoopInstSimplifyPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 44 | initializeLoopRotatePass(Registry); |
| 45 | initializeLoopStrengthReducePass(Registry); |
| 46 | initializeLoopUnrollPass(Registry); |
| 47 | initializeLoopUnswitchPass(Registry); |
Chris Lattner | b0db161 | 2010-12-26 19:32:44 +0000 | [diff] [blame] | 48 | initializeLoopIdiomRecognizePass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 49 | initializeLowerAtomicPass(Registry); |
| 50 | initializeMemCpyOptPass(Registry); |
| 51 | initializeReassociatePass(Registry); |
| 52 | initializeRegToMemPass(Registry); |
| 53 | initializeSCCPPass(Registry); |
| 54 | initializeIPSCCPPass(Registry); |
Cameron Zwarich | b1686c3 | 2011-01-18 03:53:26 +0000 | [diff] [blame] | 55 | initializeSROA_DTPass(Registry); |
Chris Lattner | b352d6e | 2011-01-14 08:13:00 +0000 | [diff] [blame] | 56 | initializeSROA_SSAUpPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 57 | initializeCFGSimplifyPassPass(Registry); |
Owen Anderson | 1a3d233 | 2010-10-07 17:55:47 +0000 | [diff] [blame] | 58 | initializeSimplifyLibCallsPass(Registry); |
| 59 | initializeSinkingPass(Registry); |
| 60 | initializeTailDupPass(Registry); |
| 61 | initializeTailCallElimPass(Registry); |
| 62 | } |
| 63 | |
| 64 | void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { |
| 65 | initializeScalarOpts(*unwrap(R)); |
| 66 | } |
| 67 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 68 | void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { |
| 69 | unwrap(PM)->add(createAggressiveDCEPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 72 | void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { |
| 73 | unwrap(PM)->add(createCFGSimplificationPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 76 | void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { |
| 77 | unwrap(PM)->add(createDeadStoreEliminationPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void LLVMAddGVNPass(LLVMPassManagerRef PM) { |
| 81 | unwrap(PM)->add(createGVNPass()); |
| 82 | } |
| 83 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 84 | void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { |
| 85 | unwrap(PM)->add(createIndVarSimplifyPass()); |
| 86 | } |
| 87 | |
| 88 | void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { |
| 89 | unwrap(PM)->add(createInstructionCombiningPass()); |
| 90 | } |
| 91 | |
| 92 | void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { |
| 93 | unwrap(PM)->add(createJumpThreadingPass()); |
| 94 | } |
| 95 | |
| 96 | void LLVMAddLICMPass(LLVMPassManagerRef PM) { |
| 97 | unwrap(PM)->add(createLICMPass()); |
| 98 | } |
| 99 | |
| 100 | void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { |
| 101 | unwrap(PM)->add(createLoopDeletionPass()); |
| 102 | } |
| 103 | |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 104 | void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { |
| 105 | unwrap(PM)->add(createLoopIdiomPass()); |
| 106 | } |
| 107 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 108 | void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { |
| 109 | unwrap(PM)->add(createLoopRotatePass()); |
| 110 | } |
| 111 | |
| 112 | void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { |
| 113 | unwrap(PM)->add(createLoopUnrollPass()); |
| 114 | } |
| 115 | |
| 116 | void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { |
| 117 | unwrap(PM)->add(createLoopUnswitchPass()); |
| 118 | } |
| 119 | |
| 120 | void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { |
| 121 | unwrap(PM)->add(createMemCpyOptPass()); |
| 122 | } |
| 123 | |
| 124 | void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 125 | unwrap(PM)->add(createPromoteMemoryToRegisterPass()); |
| 126 | } |
| 127 | |
| 128 | void LLVMAddReassociatePass(LLVMPassManagerRef PM) { |
| 129 | unwrap(PM)->add(createReassociatePass()); |
| 130 | } |
| 131 | |
| 132 | void LLVMAddSCCPPass(LLVMPassManagerRef PM) { |
| 133 | unwrap(PM)->add(createSCCPPass()); |
| 134 | } |
| 135 | |
| 136 | void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { |
| 137 | unwrap(PM)->add(createScalarReplAggregatesPass()); |
| 138 | } |
| 139 | |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 140 | void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { |
| 141 | unwrap(PM)->add(createScalarReplAggregatesPass(-1, false)); |
| 142 | } |
| 143 | |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 144 | void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, |
| 145 | int Threshold) { |
| 146 | unwrap(PM)->add(createScalarReplAggregatesPass(Threshold)); |
| 147 | } |
| 148 | |
Chris Lattner | 57c0383 | 2009-03-06 16:52:18 +0000 | [diff] [blame] | 149 | void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { |
| 150 | unwrap(PM)->add(createSimplifyLibCallsPass()); |
| 151 | } |
| 152 | |
| 153 | void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { |
| 154 | unwrap(PM)->add(createTailCallEliminationPass()); |
| 155 | } |
| 156 | |
| 157 | void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { |
| 158 | unwrap(PM)->add(createConstantPropagationPass()); |
| 159 | } |
| 160 | |
| 161 | void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { |
| 162 | unwrap(PM)->add(createDemoteRegisterToMemoryPass()); |
Gordon Henriksen | 41ba154 | 2008-03-16 16:32:40 +0000 | [diff] [blame] | 163 | } |
Nate Begeman | 47a53a6 | 2010-03-11 23:06:07 +0000 | [diff] [blame] | 164 | |
| 165 | void LLVMAddVerifierPass(LLVMPassManagerRef PM) { |
| 166 | unwrap(PM)->add(createVerifierPass()); |
| 167 | } |
Rafael Espindola | 45e1a53 | 2011-04-07 18:20:46 +0000 | [diff] [blame] | 168 | |
| 169 | void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { |
| 170 | unwrap(PM)->add(createCorrelatedValuePropagationPass()); |
| 171 | } |
| 172 | |
| 173 | void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { |
| 174 | unwrap(PM)->add(createEarlyCSEPass()); |
| 175 | } |