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-c/Transforms/Scalar.h"
17#include "llvm-c/Initialization.h"
18#include "llvm/InitializePasses.h"
19#include "llvm/PassManager.h"
20#include "llvm/Analysis/Passes.h"
21#include "llvm/Analysis/Verifier.h"
22#include "llvm/Target/TargetData.h"
23#include "llvm/Transforms/Scalar.h"
24
25using namespace llvm;
26
27/// initializeScalarOptsPasses - Initialize all passes linked into the
28/// ScalarOpts library.
29void 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  initializeObjCARCAliasAnalysisPass(Registry);
54  initializeObjCARCExpandPass(Registry);
55  initializeObjCARCContractPass(Registry);
56  initializeObjCARCOptPass(Registry);
57  initializeReassociatePass(Registry);
58  initializeRegToMemPass(Registry);
59  initializeSCCPPass(Registry);
60  initializeIPSCCPPass(Registry);
61  initializeSROA_DTPass(Registry);
62  initializeSROA_SSAUpPass(Registry);
63  initializeCFGSimplifyPassPass(Registry);
64  initializeSimplifyLibCallsPass(Registry);
65  initializeSinkingPass(Registry);
66  initializeTailCallElimPass(Registry);
67}
68
69void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
70  initializeScalarOpts(*unwrap(R));
71}
72
73void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
74  unwrap(PM)->add(createAggressiveDCEPass());
75}
76
77void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
78  unwrap(PM)->add(createCFGSimplificationPass());
79}
80
81void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
82  unwrap(PM)->add(createDeadStoreEliminationPass());
83}
84
85void LLVMAddGVNPass(LLVMPassManagerRef PM) {
86  unwrap(PM)->add(createGVNPass());
87}
88
89void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
90  unwrap(PM)->add(createIndVarSimplifyPass());
91}
92
93void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) {
94  unwrap(PM)->add(createInstructionCombiningPass());
95}
96
97void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
98  unwrap(PM)->add(createJumpThreadingPass());
99}
100
101void LLVMAddLICMPass(LLVMPassManagerRef PM) {
102  unwrap(PM)->add(createLICMPass());
103}
104
105void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
106  unwrap(PM)->add(createLoopDeletionPass());
107}
108
109void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
110  unwrap(PM)->add(createLoopIdiomPass());
111}
112
113void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
114  unwrap(PM)->add(createLoopRotatePass());
115}
116
117void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
118  unwrap(PM)->add(createLoopUnrollPass());
119}
120
121void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
122  unwrap(PM)->add(createLoopUnswitchPass());
123}
124
125void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
126  unwrap(PM)->add(createMemCpyOptPass());
127}
128
129void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
130  unwrap(PM)->add(createPromoteMemoryToRegisterPass());
131}
132
133void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
134  unwrap(PM)->add(createReassociatePass());
135}
136
137void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
138  unwrap(PM)->add(createSCCPPass());
139}
140
141void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
142  unwrap(PM)->add(createScalarReplAggregatesPass());
143}
144
145void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
146  unwrap(PM)->add(createScalarReplAggregatesPass(-1, false));
147}
148
149void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
150                                                  int Threshold) {
151  unwrap(PM)->add(createScalarReplAggregatesPass(Threshold));
152}
153
154void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
155  unwrap(PM)->add(createSimplifyLibCallsPass());
156}
157
158void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
159  unwrap(PM)->add(createTailCallEliminationPass());
160}
161
162void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
163  unwrap(PM)->add(createConstantPropagationPass());
164}
165
166void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
167  unwrap(PM)->add(createDemoteRegisterToMemoryPass());
168}
169
170void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
171  unwrap(PM)->add(createVerifierPass());
172}
173
174void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
175  unwrap(PM)->add(createCorrelatedValuePropagationPass());
176}
177
178void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
179  unwrap(PM)->add(createEarlyCSEPass());
180}
181
182void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
183  unwrap(PM)->add(createTypeBasedAliasAnalysisPass());
184}
185
186void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
187  unwrap(PM)->add(createBasicAliasAnalysisPass());
188}
189
190void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
191  unwrap(PM)->add(createLowerExpectIntrinsicPass());
192}
193