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 initializeAnnotationRemarksLegacyPass(Registry); 35 initializeBDCELegacyPassPass(Registry); 36 initializeAlignmentFromAssumptionsPass(Registry); 37 initializeCallSiteSplittingLegacyPassPass(Registry); 38 initializeConstantHoistingLegacyPassPass(Registry); 39 initializeConstraintEliminationPass(Registry); 40 initializeCorrelatedValuePropagationPass(Registry); 41 initializeDCELegacyPassPass(Registry); 42 initializeDivRemPairsLegacyPassPass(Registry); 43 initializeScalarizerLegacyPassPass(Registry); 44 initializeDSELegacyPassPass(Registry); 45 initializeGuardWideningLegacyPassPass(Registry); 46 initializeLoopGuardWideningLegacyPassPass(Registry); 47 initializeGVNLegacyPassPass(Registry); 48 initializeNewGVNLegacyPassPass(Registry); 49 initializeEarlyCSELegacyPassPass(Registry); 50 initializeEarlyCSEMemSSALegacyPassPass(Registry); 51 initializeMakeGuardsExplicitLegacyPassPass(Registry); 52 initializeGVNHoistLegacyPassPass(Registry); 53 initializeGVNSinkLegacyPassPass(Registry); 54 initializeFlattenCFGLegacyPassPass(Registry); 55 initializeIRCELegacyPassPass(Registry); 56 initializeIndVarSimplifyLegacyPassPass(Registry); 57 initializeInferAddressSpacesPass(Registry); 58 initializeInstSimplifyLegacyPassPass(Registry); 59 initializeJumpThreadingPass(Registry); 60 initializeDFAJumpThreadingLegacyPassPass(Registry); 61 initializeLegacyLICMPassPass(Registry); 62 initializeLegacyLoopSinkPassPass(Registry); 63 initializeLoopFuseLegacyPass(Registry); 64 initializeLoopDataPrefetchLegacyPassPass(Registry); 65 initializeLoopDeletionLegacyPassPass(Registry); 66 initializeLoopAccessLegacyAnalysisPass(Registry); 67 initializeLoopInstSimplifyLegacyPassPass(Registry); 68 initializeLoopInterchangeLegacyPassPass(Registry); 69 initializeLoopFlattenLegacyPassPass(Registry); 70 initializeLoopPredicationLegacyPassPass(Registry); 71 initializeLoopRotateLegacyPassPass(Registry); 72 initializeLoopStrengthReducePass(Registry); 73 initializeLoopRerollLegacyPassPass(Registry); 74 initializeLoopUnrollPass(Registry); 75 initializeLoopUnrollAndJamPass(Registry); 76 initializeWarnMissedTransformationsLegacyPass(Registry); 77 initializeLoopVersioningLICMLegacyPassPass(Registry); 78 initializeLoopIdiomRecognizeLegacyPassPass(Registry); 79 initializeLowerAtomicLegacyPassPass(Registry); 80 initializeLowerConstantIntrinsicsPass(Registry); 81 initializeLowerExpectIntrinsicPass(Registry); 82 initializeLowerGuardIntrinsicLegacyPassPass(Registry); 83 initializeLowerMatrixIntrinsicsLegacyPassPass(Registry); 84 initializeLowerMatrixIntrinsicsMinimalLegacyPassPass(Registry); 85 initializeLowerWidenableConditionLegacyPassPass(Registry); 86 initializeMemCpyOptLegacyPassPass(Registry); 87 initializeMergeICmpsLegacyPassPass(Registry); 88 initializeMergedLoadStoreMotionLegacyPassPass(Registry); 89 initializeNaryReassociateLegacyPassPass(Registry); 90 initializePartiallyInlineLibCallsLegacyPassPass(Registry); 91 initializeReassociateLegacyPassPass(Registry); 92 initializeRedundantDbgInstEliminationPass(Registry); 93 initializeRegToMemLegacyPass(Registry); 94 initializeRewriteStatepointsForGCLegacyPassPass(Registry); 95 initializeScalarizeMaskedMemIntrinLegacyPassPass(Registry); 96 initializeSCCPLegacyPassPass(Registry); 97 initializeSROALegacyPassPass(Registry); 98 initializeCFGSimplifyPassPass(Registry); 99 initializeStructurizeCFGLegacyPassPass(Registry); 100 initializeSimpleLoopUnswitchLegacyPassPass(Registry); 101 initializeSinkingLegacyPassPass(Registry); 102 initializeTailCallElimPass(Registry); 103 initializeTLSVariableHoistLegacyPassPass(Registry); 104 initializeSeparateConstOffsetFromGEPLegacyPassPass(Registry); 105 initializeSpeculativeExecutionLegacyPassPass(Registry); 106 initializeStraightLineStrengthReduceLegacyPassPass(Registry); 107 initializePlaceBackedgeSafepointsImplPass(Registry); 108 initializePlaceSafepointsPass(Registry); 109 initializeFloat2IntLegacyPassPass(Registry); 110 initializeLoopDistributeLegacyPass(Registry); 111 initializeLoopLoadEliminationPass(Registry); 112 initializeLoopSimplifyCFGLegacyPassPass(Registry); 113 initializeLoopVersioningLegacyPassPass(Registry); 114 } 115 116 void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM) { 117 unwrap(PM)->add(createLoopSimplifyCFGPass()); 118 } 119 120 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) { 121 initializeScalarOpts(*unwrap(R)); 122 } 123 124 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) { 125 unwrap(PM)->add(createAggressiveDCEPass()); 126 } 127 128 void LLVMAddDCEPass(LLVMPassManagerRef PM) { 129 unwrap(PM)->add(createDeadCodeEliminationPass()); 130 } 131 132 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) { 133 unwrap(PM)->add(createBitTrackingDCEPass()); 134 } 135 136 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) { 137 unwrap(PM)->add(createAlignmentFromAssumptionsPass()); 138 } 139 140 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { 141 unwrap(PM)->add(createCFGSimplificationPass()); 142 } 143 144 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { 145 unwrap(PM)->add(createDeadStoreEliminationPass()); 146 } 147 148 void LLVMAddScalarizerPass(LLVMPassManagerRef PM) { 149 unwrap(PM)->add(createScalarizerPass()); 150 } 151 152 void LLVMAddGVNPass(LLVMPassManagerRef PM) { 153 unwrap(PM)->add(createGVNPass()); 154 } 155 156 void LLVMAddNewGVNPass(LLVMPassManagerRef PM) { 157 unwrap(PM)->add(createNewGVNPass()); 158 } 159 160 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) { 161 unwrap(PM)->add(createMergedLoadStoreMotionPass()); 162 } 163 164 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) { 165 unwrap(PM)->add(createIndVarSimplifyPass()); 166 } 167 168 void LLVMAddInstructionSimplifyPass(LLVMPassManagerRef PM) { 169 unwrap(PM)->add(createInstSimplifyLegacyPass()); 170 } 171 172 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) { 173 unwrap(PM)->add(createJumpThreadingPass()); 174 } 175 176 void LLVMAddLoopSinkPass(LLVMPassManagerRef PM) { 177 unwrap(PM)->add(createLoopSinkPass()); 178 } 179 180 void LLVMAddLICMPass(LLVMPassManagerRef PM) { 181 unwrap(PM)->add(createLICMPass()); 182 } 183 184 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) { 185 unwrap(PM)->add(createLoopDeletionPass()); 186 } 187 188 void LLVMAddLoopFlattenPass(LLVMPassManagerRef PM) { 189 unwrap(PM)->add(createLoopFlattenPass()); 190 } 191 192 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { 193 unwrap(PM)->add(createLoopIdiomPass()); 194 } 195 196 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { 197 unwrap(PM)->add(createLoopRotatePass()); 198 } 199 200 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) { 201 unwrap(PM)->add(createLoopRerollPass()); 202 } 203 204 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) { 205 unwrap(PM)->add(createLoopUnrollPass()); 206 } 207 208 void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM) { 209 unwrap(PM)->add(createLoopUnrollAndJamPass()); 210 } 211 212 void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM) { 213 unwrap(PM)->add(createLowerAtomicPass()); 214 } 215 216 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) { 217 unwrap(PM)->add(createMemCpyOptPass()); 218 } 219 220 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) { 221 unwrap(PM)->add(createPartiallyInlineLibCallsPass()); 222 } 223 224 void LLVMAddReassociatePass(LLVMPassManagerRef PM) { 225 unwrap(PM)->add(createReassociatePass()); 226 } 227 228 void LLVMAddSCCPPass(LLVMPassManagerRef PM) { 229 unwrap(PM)->add(createSCCPPass()); 230 } 231 232 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) { 233 unwrap(PM)->add(createSROAPass()); 234 } 235 236 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) { 237 unwrap(PM)->add(createSROAPass()); 238 } 239 240 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, 241 int Threshold) { 242 unwrap(PM)->add(createSROAPass()); 243 } 244 245 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) { 246 // NOTE: The simplify-libcalls pass has been removed. 247 } 248 249 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { 250 unwrap(PM)->add(createTailCallEliminationPass()); 251 } 252 253 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { 254 unwrap(PM)->add(createDemoteRegisterToMemoryPass()); 255 } 256 257 void LLVMAddVerifierPass(LLVMPassManagerRef PM) { 258 unwrap(PM)->add(createVerifierPass()); 259 } 260 261 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) { 262 unwrap(PM)->add(createCorrelatedValuePropagationPass()); 263 } 264 265 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) { 266 unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/)); 267 } 268 269 void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM) { 270 unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/)); 271 } 272 273 void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM) { 274 unwrap(PM)->add(createGVNHoistPass()); 275 } 276 277 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) { 278 unwrap(PM)->add(createTypeBasedAAWrapperPass()); 279 } 280 281 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) { 282 unwrap(PM)->add(createScopedNoAliasAAWrapperPass()); 283 } 284 285 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) { 286 unwrap(PM)->add(createBasicAAWrapperPass()); 287 } 288 289 void LLVMAddLowerConstantIntrinsicsPass(LLVMPassManagerRef PM) { 290 unwrap(PM)->add(createLowerConstantIntrinsicsPass()); 291 } 292 293 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { 294 unwrap(PM)->add(createLowerExpectIntrinsicPass()); 295 } 296 297 void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM) { 298 unwrap(PM)->add(createUnifyFunctionExitNodesPass()); 299 } 300