1 //===-- Scalar.cpp --------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements common infrastructure for libLLVMScalarOpts.a, which 10 // implements several scalar transformations over the LLVM intermediate 11 // representation, including the C bindings for that library. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "llvm/Transforms/Scalar.h" 16 #include "llvm-c/Initialization.h" 17 #include "llvm-c/Transforms/Scalar.h" 18 #include "llvm/Analysis/BasicAliasAnalysis.h" 19 #include "llvm/Analysis/ScopedNoAliasAA.h" 20 #include "llvm/Analysis/TypeBasedAliasAnalysis.h" 21 #include "llvm/IR/LegacyPassManager.h" 22 #include "llvm/IR/Verifier.h" 23 #include "llvm/InitializePasses.h" 24 #include "llvm/Transforms/Scalar/GVN.h" 25 #include "llvm/Transforms/Scalar/Scalarizer.h" 26 #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h" 27 28 using namespace llvm; 29 30 /// initializeScalarOptsPasses - Initialize all passes linked into the 31 /// ScalarOpts library. 32 void llvm::initializeScalarOpts(PassRegistry &Registry) { 33 initializeADCELegacyPassPass(Registry); 34 initializeBDCELegacyPassPass(Registry); 35 initializeAlignmentFromAssumptionsPass(Registry); 36 initializeCallSiteSplittingLegacyPassPass(Registry); 37 initializeConstantHoistingLegacyPassPass(Registry); 38 initializeCorrelatedValuePropagationPass(Registry); 39 initializeDCELegacyPassPass(Registry); 40 initializeDivRemPairsLegacyPassPass(Registry); 41 initializeScalarizerLegacyPassPass(Registry); 42 initializeDSELegacyPassPass(Registry); 43 initializeGuardWideningLegacyPassPass(Registry); 44 initializeLoopGuardWideningLegacyPassPass(Registry); 45 initializeGVNLegacyPassPass(Registry); 46 initializeNewGVNLegacyPassPass(Registry); 47 initializeEarlyCSELegacyPassPass(Registry); 48 initializeEarlyCSEMemSSALegacyPassPass(Registry); 49 initializeMakeGuardsExplicitLegacyPassPass(Registry); 50 initializeGVNHoistLegacyPassPass(Registry); 51 initializeGVNSinkLegacyPassPass(Registry); 52 initializeFlattenCFGLegacyPassPass(Registry); 53 initializeIRCELegacyPassPass(Registry); 54 initializeIndVarSimplifyLegacyPassPass(Registry); 55 initializeInferAddressSpacesPass(Registry); 56 initializeInstSimplifyLegacyPassPass(Registry); 57 initializeJumpThreadingPass(Registry); 58 initializeDFAJumpThreadingLegacyPassPass(Registry); 59 initializeLegacyLICMPassPass(Registry); 60 initializeLegacyLoopSinkPassPass(Registry); 61 initializeLoopFuseLegacyPass(Registry); 62 initializeLoopDataPrefetchLegacyPassPass(Registry); 63 initializeLoopDeletionLegacyPassPass(Registry); 64 initializeLoopAccessLegacyAnalysisPass(Registry); 65 initializeLoopInstSimplifyLegacyPassPass(Registry); 66 initializeLoopInterchangeLegacyPassPass(Registry); 67 initializeLoopFlattenLegacyPassPass(Registry); 68 initializeLoopPredicationLegacyPassPass(Registry); 69 initializeLoopRotateLegacyPassPass(Registry); 70 initializeLoopStrengthReducePass(Registry); 71 initializeLoopRerollLegacyPassPass(Registry); 72 initializeLoopUnrollPass(Registry); 73 initializeLoopUnrollAndJamPass(Registry); 74 initializeWarnMissedTransformationsLegacyPass(Registry); 75 initializeLoopVersioningLICMLegacyPassPass(Registry); 76 initializeLoopIdiomRecognizeLegacyPassPass(Registry); 77 initializeLowerAtomicLegacyPassPass(Registry); 78 initializeLowerConstantIntrinsicsPass(Registry); 79 initializeLowerExpectIntrinsicPass(Registry); 80 initializeLowerGuardIntrinsicLegacyPassPass(Registry); 81 initializeLowerMatrixIntrinsicsLegacyPassPass(Registry); 82 initializeLowerMatrixIntrinsicsMinimalLegacyPassPass(Registry); 83 initializeLowerWidenableConditionLegacyPassPass(Registry); 84 initializeMemCpyOptLegacyPassPass(Registry); 85 initializeMergeICmpsLegacyPassPass(Registry); 86 initializeMergedLoadStoreMotionLegacyPassPass(Registry); 87 initializeNaryReassociateLegacyPassPass(Registry); 88 initializePartiallyInlineLibCallsLegacyPassPass(Registry); 89 initializeReassociateLegacyPassPass(Registry); 90 initializeRedundantDbgInstEliminationPass(Registry); 91 initializeRegToMemLegacyPass(Registry); 92 initializeRewriteStatepointsForGCLegacyPassPass(Registry); 93 initializeScalarizeMaskedMemIntrinLegacyPassPass(Registry); 94 initializeSCCPLegacyPassPass(Registry); 95 initializeSROALegacyPassPass(Registry); 96 initializeCFGSimplifyPassPass(Registry); 97 initializeStructurizeCFGLegacyPassPass(Registry); 98 initializeSimpleLoopUnswitchLegacyPassPass(Registry); 99 initializeSinkingLegacyPassPass(Registry); 100 initializeTailCallElimPass(Registry); 101 initializeTLSVariableHoistLegacyPassPass(Registry); 102 initializeSeparateConstOffsetFromGEPLegacyPassPass(Registry); 103 initializeSpeculativeExecutionLegacyPassPass(Registry); 104 initializeStraightLineStrengthReduceLegacyPassPass(Registry); 105 initializePlaceBackedgeSafepointsImplPass(Registry); 106 initializePlaceSafepointsPass(Registry); 107 initializeFloat2IntLegacyPassPass(Registry); 108 initializeLoopDistributeLegacyPass(Registry); 109 initializeLoopLoadEliminationPass(Registry); 110 initializeLoopSimplifyCFGLegacyPassPass(Registry); 111 initializeLoopVersioningLegacyPassPass(Registry); 112 } 113 114 void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM) { 115 unwrap(PM)->add(createLoopSimplifyCFGPass()); 116 } 117 118 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { 119 initializeScalarOpts(*unwrap(R)); 120 } 121 122 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { 123 unwrap(PM)->add(createAggressiveDCEPass()); 124 } 125 126 void LLVMAddDCEPass(LLVMPassManagerRef PM) { 127 unwrap(PM)->add(createDeadCodeEliminationPass()); 128 } 129 130 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) { 131 unwrap(PM)->add(createBitTrackingDCEPass()); 132 } 133 134 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) { 135 unwrap(PM)->add(createAlignmentFromAssumptionsPass()); 136 } 137 138 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { 139 unwrap(PM)->add(createCFGSimplificationPass()); 140 } 141 142 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { 143 unwrap(PM)->add(createDeadStoreEliminationPass()); 144 } 145 146 void LLVMAddScalarizerPass(LLVMPassManagerRef PM) { 147 unwrap(PM)->add(createScalarizerPass()); 148 } 149 150 void LLVMAddGVNPass(LLVMPassManagerRef PM) { 151 unwrap(PM)->add(createGVNPass()); 152 } 153 154 void LLVMAddNewGVNPass(LLVMPassManagerRef PM) { 155 unwrap(PM)->add(createNewGVNPass()); 156 } 157 158 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) { 159 unwrap(PM)->add(createMergedLoadStoreMotionPass()); 160 } 161 162 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { 163 unwrap(PM)->add(createIndVarSimplifyPass()); 164 } 165 166 void LLVMAddInstructionSimplifyPass(LLVMPassManagerRef PM) { 167 unwrap(PM)->add(createInstSimplifyLegacyPass()); 168 } 169 170 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { 171 unwrap(PM)->add(createJumpThreadingPass()); 172 } 173 174 void LLVMAddLoopSinkPass(LLVMPassManagerRef PM) { 175 unwrap(PM)->add(createLoopSinkPass()); 176 } 177 178 void LLVMAddLICMPass(LLVMPassManagerRef PM) { 179 unwrap(PM)->add(createLICMPass()); 180 } 181 182 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { 183 unwrap(PM)->add(createLoopDeletionPass()); 184 } 185 186 void LLVMAddLoopFlattenPass(LLVMPassManagerRef PM) { 187 unwrap(PM)->add(createLoopFlattenPass()); 188 } 189 190 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { 191 unwrap(PM)->add(createLoopIdiomPass()); 192 } 193 194 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { 195 unwrap(PM)->add(createLoopRotatePass()); 196 } 197 198 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) { 199 unwrap(PM)->add(createLoopRerollPass()); 200 } 201 202 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { 203 unwrap(PM)->add(createLoopUnrollPass()); 204 } 205 206 void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM) { 207 unwrap(PM)->add(createLoopUnrollAndJamPass()); 208 } 209 210 void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM) { 211 unwrap(PM)->add(createLowerAtomicPass()); 212 } 213 214 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { 215 unwrap(PM)->add(createMemCpyOptPass()); 216 } 217 218 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) { 219 unwrap(PM)->add(createPartiallyInlineLibCallsPass()); 220 } 221 222 void LLVMAddReassociatePass(LLVMPassManagerRef PM) { 223 unwrap(PM)->add(createReassociatePass()); 224 } 225 226 void LLVMAddSCCPPass(LLVMPassManagerRef PM) { 227 unwrap(PM)->add(createSCCPPass()); 228 } 229 230 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { 231 unwrap(PM)->add(createSROAPass()); 232 } 233 234 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { 235 unwrap(PM)->add(createSROAPass()); 236 } 237 238 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, 239 int Threshold) { 240 unwrap(PM)->add(createSROAPass()); 241 } 242 243 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { 244 // NOTE: The simplify-libcalls pass has been removed. 245 } 246 247 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { 248 unwrap(PM)->add(createTailCallEliminationPass()); 249 } 250 251 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { 252 unwrap(PM)->add(createDemoteRegisterToMemoryPass()); 253 } 254 255 void LLVMAddVerifierPass(LLVMPassManagerRef PM) { 256 unwrap(PM)->add(createVerifierPass()); 257 } 258 259 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { 260 unwrap(PM)->add(createCorrelatedValuePropagationPass()); 261 } 262 263 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { 264 unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/)); 265 } 266 267 void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM) { 268 unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/)); 269 } 270 271 void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM) { 272 unwrap(PM)->add(createGVNHoistPass()); 273 } 274 275 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { 276 unwrap(PM)->add(createTypeBasedAAWrapperPass()); 277 } 278 279 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) { 280 unwrap(PM)->add(createScopedNoAliasAAWrapperPass()); 281 } 282 283 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { 284 unwrap(PM)->add(createBasicAAWrapperPass()); 285 } 286 287 void LLVMAddLowerConstantIntrinsicsPass(LLVMPassManagerRef PM) { 288 unwrap(PM)->add(createLowerConstantIntrinsicsPass()); 289 } 290 291 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { 292 unwrap(PM)->add(createLowerExpectIntrinsicPass()); 293 } 294 295 void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM) { 296 unwrap(PM)->add(createUnifyFunctionExitNodesPass()); 297 } 298