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/BasicAliasAnalysis.h" 20 #include "llvm/Analysis/Passes.h" 21 #include "llvm/Analysis/ScopedNoAliasAA.h" 22 #include "llvm/Analysis/TypeBasedAliasAnalysis.h" 23 #include "llvm/Transforms/Scalar/GVN.h" 24 #include "llvm/IR/DataLayout.h" 25 #include "llvm/IR/Verifier.h" 26 #include "llvm/InitializePasses.h" 27 #include "llvm/IR/LegacyPassManager.h" 28 29 using namespace llvm; 30 31 /// initializeScalarOptsPasses - Initialize all passes linked into the 32 /// ScalarOpts library. initializeScalarOpts(PassRegistry & Registry)33void llvm::initializeScalarOpts(PassRegistry &Registry) { 34 initializeADCELegacyPassPass(Registry); 35 initializeBDCELegacyPassPass(Registry); 36 initializeAlignmentFromAssumptionsPass(Registry); 37 initializeConstantHoistingLegacyPassPass(Registry); 38 initializeConstantPropagationPass(Registry); 39 initializeCorrelatedValuePropagationPass(Registry); 40 initializeDCELegacyPassPass(Registry); 41 initializeDeadInstEliminationPass(Registry); 42 initializeScalarizerPass(Registry); 43 initializeDSELegacyPassPass(Registry); 44 initializeGuardWideningLegacyPassPass(Registry); 45 initializeGVNLegacyPassPass(Registry); 46 initializeEarlyCSELegacyPassPass(Registry); 47 initializeFlattenCFGPassPass(Registry); 48 initializeInductiveRangeCheckEliminationPass(Registry); 49 initializeIndVarSimplifyLegacyPassPass(Registry); 50 initializeJumpThreadingPass(Registry); 51 initializeLegacyLICMPassPass(Registry); 52 initializeLoopDataPrefetchPass(Registry); 53 initializeLoopDeletionLegacyPassPass(Registry); 54 initializeLoopAccessLegacyAnalysisPass(Registry); 55 initializeLoopInstSimplifyPass(Registry); 56 initializeLoopInterchangePass(Registry); 57 initializeLoopRotateLegacyPassPass(Registry); 58 initializeLoopStrengthReducePass(Registry); 59 initializeLoopRerollPass(Registry); 60 initializeLoopUnrollPass(Registry); 61 initializeLoopUnswitchPass(Registry); 62 initializeLoopVersioningLICMPass(Registry); 63 initializeLoopIdiomRecognizeLegacyPassPass(Registry); 64 initializeLowerAtomicLegacyPassPass(Registry); 65 initializeLowerExpectIntrinsicPass(Registry); 66 initializeLowerGuardIntrinsicPass(Registry); 67 initializeMemCpyOptLegacyPassPass(Registry); 68 initializeMergedLoadStoreMotionLegacyPassPass(Registry); 69 initializeNaryReassociatePass(Registry); 70 initializePartiallyInlineLibCallsLegacyPassPass(Registry); 71 initializeReassociateLegacyPassPass(Registry); 72 initializeRegToMemPass(Registry); 73 initializeRewriteStatepointsForGCPass(Registry); 74 initializeSCCPLegacyPassPass(Registry); 75 initializeIPSCCPLegacyPassPass(Registry); 76 initializeSROALegacyPassPass(Registry); 77 initializeCFGSimplifyPassPass(Registry); 78 initializeStructurizeCFGPass(Registry); 79 initializeSinkingLegacyPassPass(Registry); 80 initializeTailCallElimPass(Registry); 81 initializeSeparateConstOffsetFromGEPPass(Registry); 82 initializeSpeculativeExecutionPass(Registry); 83 initializeStraightLineStrengthReducePass(Registry); 84 initializeLoadCombinePass(Registry); 85 initializePlaceBackedgeSafepointsImplPass(Registry); 86 initializePlaceSafepointsPass(Registry); 87 initializeFloat2IntLegacyPassPass(Registry); 88 initializeLoopDistributePass(Registry); 89 initializeLoopLoadEliminationPass(Registry); 90 initializeLoopSimplifyCFGLegacyPassPass(Registry); 91 initializeLoopVersioningPassPass(Registry); 92 } 93 LLVMInitializeScalarOpts(LLVMPassRegistryRef R)94void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { 95 initializeScalarOpts(*unwrap(R)); 96 } 97 LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)98void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { 99 unwrap(PM)->add(createAggressiveDCEPass()); 100 } 101 LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)102void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) { 103 unwrap(PM)->add(createBitTrackingDCEPass()); 104 } 105 LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM)106void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) { 107 unwrap(PM)->add(createAlignmentFromAssumptionsPass()); 108 } 109 LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)110void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { 111 unwrap(PM)->add(createCFGSimplificationPass()); 112 } 113 LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)114void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { 115 unwrap(PM)->add(createDeadStoreEliminationPass()); 116 } 117 LLVMAddScalarizerPass(LLVMPassManagerRef PM)118void LLVMAddScalarizerPass(LLVMPassManagerRef PM) { 119 unwrap(PM)->add(createScalarizerPass()); 120 } 121 LLVMAddGVNPass(LLVMPassManagerRef PM)122void LLVMAddGVNPass(LLVMPassManagerRef PM) { 123 unwrap(PM)->add(createGVNPass()); 124 } 125 LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)126void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) { 127 unwrap(PM)->add(createMergedLoadStoreMotionPass()); 128 } 129 LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)130void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { 131 unwrap(PM)->add(createIndVarSimplifyPass()); 132 } 133 LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM)134void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) { 135 unwrap(PM)->add(createInstructionCombiningPass()); 136 } 137 LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)138void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { 139 unwrap(PM)->add(createJumpThreadingPass()); 140 } 141 LLVMAddLICMPass(LLVMPassManagerRef PM)142void LLVMAddLICMPass(LLVMPassManagerRef PM) { 143 unwrap(PM)->add(createLICMPass()); 144 } 145 LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)146void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { 147 unwrap(PM)->add(createLoopDeletionPass()); 148 } 149 LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)150void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { 151 unwrap(PM)->add(createLoopIdiomPass()); 152 } 153 LLVMAddLoopRotatePass(LLVMPassManagerRef PM)154void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { 155 unwrap(PM)->add(createLoopRotatePass()); 156 } 157 LLVMAddLoopRerollPass(LLVMPassManagerRef PM)158void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) { 159 unwrap(PM)->add(createLoopRerollPass()); 160 } 161 LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM)162void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM) { 163 unwrap(PM)->add(createLoopSimplifyCFGPass()); 164 } 165 LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)166void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { 167 unwrap(PM)->add(createLoopUnrollPass()); 168 } 169 LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)170void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) { 171 unwrap(PM)->add(createLoopUnswitchPass()); 172 } 173 LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)174void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { 175 unwrap(PM)->add(createMemCpyOptPass()); 176 } 177 LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM)178void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) { 179 unwrap(PM)->add(createPartiallyInlineLibCallsPass()); 180 } 181 LLVMAddLowerSwitchPass(LLVMPassManagerRef PM)182void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM) { 183 unwrap(PM)->add(createLowerSwitchPass()); 184 } 185 LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM)186void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) { 187 unwrap(PM)->add(createPromoteMemoryToRegisterPass()); 188 } 189 LLVMAddReassociatePass(LLVMPassManagerRef PM)190void LLVMAddReassociatePass(LLVMPassManagerRef PM) { 191 unwrap(PM)->add(createReassociatePass()); 192 } 193 LLVMAddSCCPPass(LLVMPassManagerRef PM)194void LLVMAddSCCPPass(LLVMPassManagerRef PM) { 195 unwrap(PM)->add(createSCCPPass()); 196 } 197 LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)198void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { 199 unwrap(PM)->add(createSROAPass()); 200 } 201 LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)202void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { 203 unwrap(PM)->add(createSROAPass()); 204 } 205 LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,int Threshold)206void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, 207 int Threshold) { 208 unwrap(PM)->add(createSROAPass()); 209 } 210 LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)211void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { 212 // NOTE: The simplify-libcalls pass has been removed. 213 } 214 LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)215void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { 216 unwrap(PM)->add(createTailCallEliminationPass()); 217 } 218 LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)219void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { 220 unwrap(PM)->add(createConstantPropagationPass()); 221 } 222 LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM)223void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { 224 unwrap(PM)->add(createDemoteRegisterToMemoryPass()); 225 } 226 LLVMAddVerifierPass(LLVMPassManagerRef PM)227void LLVMAddVerifierPass(LLVMPassManagerRef PM) { 228 unwrap(PM)->add(createVerifierPass()); 229 } 230 LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)231void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { 232 unwrap(PM)->add(createCorrelatedValuePropagationPass()); 233 } 234 LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)235void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { 236 unwrap(PM)->add(createEarlyCSEPass()); 237 } 238 LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)239void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { 240 unwrap(PM)->add(createTypeBasedAAWrapperPass()); 241 } 242 LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM)243void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) { 244 unwrap(PM)->add(createScopedNoAliasAAWrapperPass()); 245 } 246 LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)247void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { 248 unwrap(PM)->add(createBasicAAWrapperPass()); 249 } 250 LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)251void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { 252 unwrap(PM)->add(createLowerExpectIntrinsicPass()); 253 } 254