• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
initializeScalarOpts(PassRegistry & Registry)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   initializeSimplifyLibCallsPass(Registry);
62   initializeSinkingPass(Registry);
63   initializeTailCallElimPass(Registry);
64 }
65 
LLVMInitializeScalarOpts(LLVMPassRegistryRef R)66 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
67   initializeScalarOpts(*unwrap(R));
68 }
69 
LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)70 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
71   unwrap(PM)->add(createAggressiveDCEPass());
72 }
73 
LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)74 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
75   unwrap(PM)->add(createCFGSimplificationPass());
76 }
77 
LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)78 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
79   unwrap(PM)->add(createDeadStoreEliminationPass());
80 }
81 
LLVMAddGVNPass(LLVMPassManagerRef PM)82 void LLVMAddGVNPass(LLVMPassManagerRef PM) {
83   unwrap(PM)->add(createGVNPass());
84 }
85 
LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)86 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
87   unwrap(PM)->add(createIndVarSimplifyPass());
88 }
89 
LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM)90 void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) {
91   unwrap(PM)->add(createInstructionCombiningPass());
92 }
93 
LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)94 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
95   unwrap(PM)->add(createJumpThreadingPass());
96 }
97 
LLVMAddLICMPass(LLVMPassManagerRef PM)98 void LLVMAddLICMPass(LLVMPassManagerRef PM) {
99   unwrap(PM)->add(createLICMPass());
100 }
101 
LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)102 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
103   unwrap(PM)->add(createLoopDeletionPass());
104 }
105 
LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)106 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
107   unwrap(PM)->add(createLoopIdiomPass());
108 }
109 
LLVMAddLoopRotatePass(LLVMPassManagerRef PM)110 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
111   unwrap(PM)->add(createLoopRotatePass());
112 }
113 
LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)114 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
115   unwrap(PM)->add(createLoopUnrollPass());
116 }
117 
LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)118 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
119   unwrap(PM)->add(createLoopUnswitchPass());
120 }
121 
LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)122 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
123   unwrap(PM)->add(createMemCpyOptPass());
124 }
125 
LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM)126 void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
127   unwrap(PM)->add(createPromoteMemoryToRegisterPass());
128 }
129 
LLVMAddReassociatePass(LLVMPassManagerRef PM)130 void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
131   unwrap(PM)->add(createReassociatePass());
132 }
133 
LLVMAddSCCPPass(LLVMPassManagerRef PM)134 void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
135   unwrap(PM)->add(createSCCPPass());
136 }
137 
LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)138 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
139   unwrap(PM)->add(createScalarReplAggregatesPass());
140 }
141 
LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)142 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
143   unwrap(PM)->add(createScalarReplAggregatesPass(-1, false));
144 }
145 
LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,int Threshold)146 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
147                                                   int Threshold) {
148   unwrap(PM)->add(createScalarReplAggregatesPass(Threshold));
149 }
150 
LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)151 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
152   unwrap(PM)->add(createSimplifyLibCallsPass());
153 }
154 
LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)155 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
156   unwrap(PM)->add(createTailCallEliminationPass());
157 }
158 
LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)159 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
160   unwrap(PM)->add(createConstantPropagationPass());
161 }
162 
LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM)163 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
164   unwrap(PM)->add(createDemoteRegisterToMemoryPass());
165 }
166 
LLVMAddVerifierPass(LLVMPassManagerRef PM)167 void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
168   unwrap(PM)->add(createVerifierPass());
169 }
170 
LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)171 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
172   unwrap(PM)->add(createCorrelatedValuePropagationPass());
173 }
174 
LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)175 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
176   unwrap(PM)->add(createEarlyCSEPass());
177 }
178 
LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)179 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
180   unwrap(PM)->add(createTypeBasedAliasAnalysisPass());
181 }
182 
LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)183 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
184   unwrap(PM)->add(createBasicAliasAnalysisPass());
185 }
186 
LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)187 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
188   unwrap(PM)->add(createLowerExpectIntrinsicPass());
189 }
190