Home | History | Annotate | Download | only in Scalar
      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/IR/DataLayout.h"
     24 #include "llvm/IR/Verifier.h"
     25 #include "llvm/InitializePasses.h"
     26 #include "llvm/IR/LegacyPassManager.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   initializeBDCEPass(Registry);
     35   initializeAlignmentFromAssumptionsPass(Registry);
     36   initializeConstantHoistingPass(Registry);
     37   initializeConstantPropagationPass(Registry);
     38   initializeCorrelatedValuePropagationPass(Registry);
     39   initializeDCEPass(Registry);
     40   initializeDeadInstEliminationPass(Registry);
     41   initializeScalarizerPass(Registry);
     42   initializeDSEPass(Registry);
     43   initializeGVNPass(Registry);
     44   initializeEarlyCSELegacyPassPass(Registry);
     45   initializeFlattenCFGPassPass(Registry);
     46   initializeInductiveRangeCheckEliminationPass(Registry);
     47   initializeIndVarSimplifyPass(Registry);
     48   initializeJumpThreadingPass(Registry);
     49   initializeLICMPass(Registry);
     50   initializeLoopDeletionPass(Registry);
     51   initializeLoopAccessAnalysisPass(Registry);
     52   initializeLoopInstSimplifyPass(Registry);
     53   initializeLoopInterchangePass(Registry);
     54   initializeLoopRotatePass(Registry);
     55   initializeLoopStrengthReducePass(Registry);
     56   initializeLoopRerollPass(Registry);
     57   initializeLoopUnrollPass(Registry);
     58   initializeLoopUnswitchPass(Registry);
     59   initializeLoopIdiomRecognizePass(Registry);
     60   initializeLowerAtomicPass(Registry);
     61   initializeLowerExpectIntrinsicPass(Registry);
     62   initializeMemCpyOptPass(Registry);
     63   initializeMergedLoadStoreMotionPass(Registry);
     64   initializeNaryReassociatePass(Registry);
     65   initializePartiallyInlineLibCallsPass(Registry);
     66   initializeReassociatePass(Registry);
     67   initializeRegToMemPass(Registry);
     68   initializeRewriteStatepointsForGCPass(Registry);
     69   initializeSCCPPass(Registry);
     70   initializeIPSCCPPass(Registry);
     71   initializeSROALegacyPassPass(Registry);
     72   initializeSROA_DTPass(Registry);
     73   initializeSROA_SSAUpPass(Registry);
     74   initializeCFGSimplifyPassPass(Registry);
     75   initializeStructurizeCFGPass(Registry);
     76   initializeSinkingPass(Registry);
     77   initializeTailCallElimPass(Registry);
     78   initializeSeparateConstOffsetFromGEPPass(Registry);
     79   initializeSpeculativeExecutionPass(Registry);
     80   initializeStraightLineStrengthReducePass(Registry);
     81   initializeLoadCombinePass(Registry);
     82   initializePlaceBackedgeSafepointsImplPass(Registry);
     83   initializePlaceSafepointsPass(Registry);
     84   initializeFloat2IntPass(Registry);
     85   initializeLoopDistributePass(Registry);
     86   initializeLoopLoadEliminationPass(Registry);
     87 }
     88 
     89 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
     90   initializeScalarOpts(*unwrap(R));
     91 }
     92 
     93 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
     94   unwrap(PM)->add(createAggressiveDCEPass());
     95 }
     96 
     97 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) {
     98   unwrap(PM)->add(createBitTrackingDCEPass());
     99 }
    100 
    101 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
    102   unwrap(PM)->add(createAlignmentFromAssumptionsPass());
    103 }
    104 
    105 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
    106   unwrap(PM)->add(createCFGSimplificationPass());
    107 }
    108 
    109 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
    110   unwrap(PM)->add(createDeadStoreEliminationPass());
    111 }
    112 
    113 void LLVMAddScalarizerPass(LLVMPassManagerRef PM) {
    114   unwrap(PM)->add(createScalarizerPass());
    115 }
    116 
    117 void LLVMAddGVNPass(LLVMPassManagerRef PM) {
    118   unwrap(PM)->add(createGVNPass());
    119 }
    120 
    121 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) {
    122   unwrap(PM)->add(createMergedLoadStoreMotionPass());
    123 }
    124 
    125 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
    126   unwrap(PM)->add(createIndVarSimplifyPass());
    127 }
    128 
    129 void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) {
    130   unwrap(PM)->add(createInstructionCombiningPass());
    131 }
    132 
    133 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
    134   unwrap(PM)->add(createJumpThreadingPass());
    135 }
    136 
    137 void LLVMAddLICMPass(LLVMPassManagerRef PM) {
    138   unwrap(PM)->add(createLICMPass());
    139 }
    140 
    141 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
    142   unwrap(PM)->add(createLoopDeletionPass());
    143 }
    144 
    145 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
    146   unwrap(PM)->add(createLoopIdiomPass());
    147 }
    148 
    149 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
    150   unwrap(PM)->add(createLoopRotatePass());
    151 }
    152 
    153 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) {
    154   unwrap(PM)->add(createLoopRerollPass());
    155 }
    156 
    157 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
    158   unwrap(PM)->add(createLoopUnrollPass());
    159 }
    160 
    161 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
    162   unwrap(PM)->add(createLoopUnswitchPass());
    163 }
    164 
    165 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
    166   unwrap(PM)->add(createMemCpyOptPass());
    167 }
    168 
    169 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) {
    170   unwrap(PM)->add(createPartiallyInlineLibCallsPass());
    171 }
    172 
    173 void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM) {
    174   unwrap(PM)->add(createLowerSwitchPass());
    175 }
    176 
    177 void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
    178   unwrap(PM)->add(createPromoteMemoryToRegisterPass());
    179 }
    180 
    181 void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
    182   unwrap(PM)->add(createReassociatePass());
    183 }
    184 
    185 void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
    186   unwrap(PM)->add(createSCCPPass());
    187 }
    188 
    189 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
    190   unwrap(PM)->add(createScalarReplAggregatesPass());
    191 }
    192 
    193 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
    194   unwrap(PM)->add(createScalarReplAggregatesPass(-1, false));
    195 }
    196 
    197 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
    198                                                   int Threshold) {
    199   unwrap(PM)->add(createScalarReplAggregatesPass(Threshold));
    200 }
    201 
    202 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
    203   // NOTE: The simplify-libcalls pass has been removed.
    204 }
    205 
    206 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
    207   unwrap(PM)->add(createTailCallEliminationPass());
    208 }
    209 
    210 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
    211   unwrap(PM)->add(createConstantPropagationPass());
    212 }
    213 
    214 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
    215   unwrap(PM)->add(createDemoteRegisterToMemoryPass());
    216 }
    217 
    218 void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
    219   unwrap(PM)->add(createVerifierPass());
    220 }
    221 
    222 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
    223   unwrap(PM)->add(createCorrelatedValuePropagationPass());
    224 }
    225 
    226 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
    227   unwrap(PM)->add(createEarlyCSEPass());
    228 }
    229 
    230 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
    231   unwrap(PM)->add(createTypeBasedAAWrapperPass());
    232 }
    233 
    234 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) {
    235   unwrap(PM)->add(createScopedNoAliasAAWrapperPass());
    236 }
    237 
    238 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
    239   unwrap(PM)->add(createBasicAAWrapperPass());
    240 }
    241 
    242 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
    243   unwrap(PM)->add(createLowerExpectIntrinsicPass());
    244 }
    245