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 // 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. 13 // 14 //===----------------------------------------------------------------------===// 15 16 #include "llvm/Transforms/Scalar.h" 17 #include "llvm-c/Initialization.h" 18 #include "llvm-c/Transforms/Scalar.h" 19 #include "llvm/Analysis/Passes.h" 20 #include "llvm/Analysis/Verifier.h" 21 #include "llvm/IR/DataLayout.h" 22 #include "llvm/InitializePasses.h" 23 #include "llvm/PassManager.h" 24 25 using namespace llvm; 26 27 /// initializeScalarOptsPasses - Initialize all passes linked into the 28 /// ScalarOpts library. 29 void llvm::initializeScalarOpts(PassRegistry &Registry) { 30 initializeADCEPass(Registry); 31 initializeBlockPlacementPass(Registry); 32 initializeCodeGenPreparePass(Registry); 33 initializeConstantPropagationPass(Registry); 34 initializeCorrelatedValuePropagationPass(Registry); 35 initializeDCEPass(Registry); 36 initializeDeadInstEliminationPass(Registry); 37 initializeDSEPass(Registry); 38 initializeGVNPass(Registry); 39 initializeEarlyCSEPass(Registry); 40 initializeIndVarSimplifyPass(Registry); 41 initializeJumpThreadingPass(Registry); 42 initializeLICMPass(Registry); 43 initializeLoopDeletionPass(Registry); 44 initializeLoopInstSimplifyPass(Registry); 45 initializeLoopRotatePass(Registry); 46 initializeLoopStrengthReducePass(Registry); 47 initializeLoopUnrollPass(Registry); 48 initializeLoopUnswitchPass(Registry); 49 initializeLoopIdiomRecognizePass(Registry); 50 initializeLowerAtomicPass(Registry); 51 initializeLowerExpectIntrinsicPass(Registry); 52 initializeMemCpyOptPass(Registry); 53 initializeReassociatePass(Registry); 54 initializeRegToMemPass(Registry); 55 initializeSCCPPass(Registry); 56 initializeIPSCCPPass(Registry); 57 initializeSROAPass(Registry); 58 initializeSROA_DTPass(Registry); 59 initializeSROA_SSAUpPass(Registry); 60 initializeCFGSimplifyPassPass(Registry); 61 initializeStructurizeCFGPass(Registry); 62 initializeSinkingPass(Registry); 63 initializeTailCallElimPass(Registry); 64 } 65 66 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { 67 initializeScalarOpts(*unwrap(R)); 68 } 69 70 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { 71 unwrap(PM)->add(createAggressiveDCEPass()); 72 } 73 74 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { 75 unwrap(PM)->add(createCFGSimplificationPass()); 76 } 77 78 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { 79 unwrap(PM)->add(createDeadStoreEliminationPass()); 80 } 81 82 void LLVMAddGVNPass(LLVMPassManagerRef PM) { 83 unwrap(PM)->add(createGVNPass()); 84 } 85 86 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { 87 unwrap(PM)->add(createIndVarSimplifyPass()); 88 } 89 90 void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { 91 unwrap(PM)->add(createInstructionCombiningPass()); 92 } 93 94 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { 95 unwrap(PM)->add(createJumpThreadingPass()); 96 } 97 98 void LLVMAddLICMPass(LLVMPassManagerRef PM) { 99 unwrap(PM)->add(createLICMPass()); 100 } 101 102 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { 103 unwrap(PM)->add(createLoopDeletionPass()); 104 } 105 106 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { 107 unwrap(PM)->add(createLoopIdiomPass()); 108 } 109 110 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { 111 unwrap(PM)->add(createLoopRotatePass()); 112 } 113 114 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { 115 unwrap(PM)->add(createLoopUnrollPass()); 116 } 117 118 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { 119 unwrap(PM)->add(createLoopUnswitchPass()); 120 } 121 122 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { 123 unwrap(PM)->add(createMemCpyOptPass()); 124 } 125 126 void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { 127 unwrap(PM)->add(createPromoteMemoryToRegisterPass()); 128 } 129 130 void LLVMAddReassociatePass(LLVMPassManagerRef PM) { 131 unwrap(PM)->add(createReassociatePass()); 132 } 133 134 void LLVMAddSCCPPass(LLVMPassManagerRef PM) { 135 unwrap(PM)->add(createSCCPPass()); 136 } 137 138 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { 139 unwrap(PM)->add(createScalarReplAggregatesPass()); 140 } 141 142 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { 143 unwrap(PM)->add(createScalarReplAggregatesPass(-1, false)); 144 } 145 146 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, 147 int Threshold) { 148 unwrap(PM)->add(createScalarReplAggregatesPass(Threshold)); 149 } 150 151 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { 152 // NOTE: The simplify-libcalls pass has been removed. 153 } 154 155 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { 156 unwrap(PM)->add(createTailCallEliminationPass()); 157 } 158 159 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { 160 unwrap(PM)->add(createConstantPropagationPass()); 161 } 162 163 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { 164 unwrap(PM)->add(createDemoteRegisterToMemoryPass()); 165 } 166 167 void LLVMAddVerifierPass(LLVMPassManagerRef PM) { 168 unwrap(PM)->add(createVerifierPass()); 169 } 170 171 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { 172 unwrap(PM)->add(createCorrelatedValuePropagationPass()); 173 } 174 175 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { 176 unwrap(PM)->add(createEarlyCSEPass()); 177 } 178 179 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { 180 unwrap(PM)->add(createTypeBasedAliasAnalysisPass()); 181 } 182 183 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { 184 unwrap(PM)->add(createBasicAliasAnalysisPass()); 185 } 186 187 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { 188 unwrap(PM)->add(createLowerExpectIntrinsicPass()); 189 } 190