1 //===-- IPO.cpp -----------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the common infrastructure (including C bindings) for
10 // libLLVMIPO.a, which implements several transformations over the LLVM
11 // intermediate representation.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-c/Transforms/IPO.h"
16 #include "llvm-c/Initialization.h"
17 #include "llvm/IR/LegacyPassManager.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Transforms/IPO.h"
20 #include "llvm/Transforms/IPO/AlwaysInliner.h"
21 #include "llvm/Transforms/IPO/FunctionAttrs.h"
25 void llvm::initializeIPO(PassRegistry
&Registry
) {
26 initializeArgPromotionPass(Registry
);
27 initializeCalledValuePropagationLegacyPassPass(Registry
);
28 initializeConstantMergeLegacyPassPass(Registry
);
29 initializeCrossDSOCFIPass(Registry
);
30 initializeDAEPass(Registry
);
31 initializeDAHPass(Registry
);
32 initializeForceFunctionAttrsLegacyPassPass(Registry
);
33 initializeGlobalDCELegacyPassPass(Registry
);
34 initializeGlobalOptLegacyPassPass(Registry
);
35 initializeGlobalSplitPass(Registry
);
36 initializeHotColdSplittingLegacyPassPass(Registry
);
37 initializeIPCPPass(Registry
);
38 initializeAlwaysInlinerLegacyPassPass(Registry
);
39 initializeSimpleInlinerPass(Registry
);
40 initializeInferFunctionAttrsLegacyPassPass(Registry
);
41 initializeInternalizeLegacyPassPass(Registry
);
42 initializeLoopExtractorPass(Registry
);
43 initializeBlockExtractorPass(Registry
);
44 initializeSingleLoopExtractorPass(Registry
);
45 initializeLowerTypeTestsPass(Registry
);
46 initializeMergeFunctionsPass(Registry
);
47 initializePartialInlinerLegacyPassPass(Registry
);
48 initializeAttributorLegacyPassPass(Registry
);
49 initializePostOrderFunctionAttrsLegacyPassPass(Registry
);
50 initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry
);
51 initializePruneEHPass(Registry
);
52 initializeIPSCCPLegacyPassPass(Registry
);
53 initializeStripDeadPrototypesLegacyPassPass(Registry
);
54 initializeStripSymbolsPass(Registry
);
55 initializeStripDebugDeclarePass(Registry
);
56 initializeStripDeadDebugInfoPass(Registry
);
57 initializeStripNonDebugSymbolsPass(Registry
);
58 initializeBarrierNoopPass(Registry
);
59 initializeEliminateAvailableExternallyLegacyPassPass(Registry
);
60 initializeSampleProfileLoaderLegacyPassPass(Registry
);
61 initializeFunctionImportLegacyPassPass(Registry
);
62 initializeWholeProgramDevirtPass(Registry
);
65 void LLVMInitializeIPO(LLVMPassRegistryRef R
) {
66 initializeIPO(*unwrap(R
));
69 void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM
) {
70 unwrap(PM
)->add(createArgumentPromotionPass());
73 void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM
) {
74 unwrap(PM
)->add(createCalledValuePropagationPass());
77 void LLVMAddConstantMergePass(LLVMPassManagerRef PM
) {
78 unwrap(PM
)->add(createConstantMergePass());
81 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM
) {
82 unwrap(PM
)->add(createDeadArgEliminationPass());
85 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM
) {
86 unwrap(PM
)->add(createPostOrderFunctionAttrsLegacyPass());
89 void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM
) {
90 unwrap(PM
)->add(createFunctionInliningPass());
93 void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM
) {
94 unwrap(PM
)->add(llvm::createAlwaysInlinerLegacyPass());
97 void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM
) {
98 unwrap(PM
)->add(createGlobalDCEPass());
101 void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM
) {
102 unwrap(PM
)->add(createGlobalOptimizerPass());
105 void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM
) {
106 unwrap(PM
)->add(createIPConstantPropagationPass());
109 void LLVMAddPruneEHPass(LLVMPassManagerRef PM
) {
110 unwrap(PM
)->add(createPruneEHPass());
113 void LLVMAddIPSCCPPass(LLVMPassManagerRef PM
) {
114 unwrap(PM
)->add(createIPSCCPPass());
117 void LLVMAddInternalizePass(LLVMPassManagerRef PM
, unsigned AllButMain
) {
118 auto PreserveMain
= [=](const GlobalValue
&GV
) {
119 return AllButMain
&& GV
.getName() == "main";
121 unwrap(PM
)->add(createInternalizePass(PreserveMain
));
124 void LLVMAddInternalizePassWithMustPreservePredicate(
125 LLVMPassManagerRef PM
,
127 LLVMBool (*Pred
)(LLVMValueRef
, void *)) {
128 unwrap(PM
)->add(createInternalizePass([=](const GlobalValue
&GV
) {
129 return Pred(wrap(&GV
), Context
) == 0 ? false : true;
133 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM
) {
134 unwrap(PM
)->add(createStripDeadPrototypesPass());
137 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM
) {
138 unwrap(PM
)->add(createStripSymbolsPass());