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 initializePostOrderFunctionAttrsLegacyPassPass(Registry
);
49 initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry
);
50 initializePruneEHPass(Registry
);
51 initializeIPSCCPLegacyPassPass(Registry
);
52 initializeStripDeadPrototypesLegacyPassPass(Registry
);
53 initializeStripSymbolsPass(Registry
);
54 initializeStripDebugDeclarePass(Registry
);
55 initializeStripDeadDebugInfoPass(Registry
);
56 initializeStripNonDebugSymbolsPass(Registry
);
57 initializeBarrierNoopPass(Registry
);
58 initializeEliminateAvailableExternallyLegacyPassPass(Registry
);
59 initializeSampleProfileLoaderLegacyPassPass(Registry
);
60 initializeFunctionImportLegacyPassPass(Registry
);
61 initializeWholeProgramDevirtPass(Registry
);
64 void LLVMInitializeIPO(LLVMPassRegistryRef R
) {
65 initializeIPO(*unwrap(R
));
68 void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM
) {
69 unwrap(PM
)->add(createArgumentPromotionPass());
72 void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM
) {
73 unwrap(PM
)->add(createCalledValuePropagationPass());
76 void LLVMAddConstantMergePass(LLVMPassManagerRef PM
) {
77 unwrap(PM
)->add(createConstantMergePass());
80 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM
) {
81 unwrap(PM
)->add(createDeadArgEliminationPass());
84 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM
) {
85 unwrap(PM
)->add(createPostOrderFunctionAttrsLegacyPass());
88 void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM
) {
89 unwrap(PM
)->add(createFunctionInliningPass());
92 void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM
) {
93 unwrap(PM
)->add(llvm::createAlwaysInlinerLegacyPass());
96 void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM
) {
97 unwrap(PM
)->add(createGlobalDCEPass());
100 void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM
) {
101 unwrap(PM
)->add(createGlobalOptimizerPass());
104 void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM
) {
105 unwrap(PM
)->add(createIPConstantPropagationPass());
108 void LLVMAddPruneEHPass(LLVMPassManagerRef PM
) {
109 unwrap(PM
)->add(createPruneEHPass());
112 void LLVMAddIPSCCPPass(LLVMPassManagerRef PM
) {
113 unwrap(PM
)->add(createIPSCCPPass());
116 void LLVMAddInternalizePass(LLVMPassManagerRef PM
, unsigned AllButMain
) {
117 auto PreserveMain
= [=](const GlobalValue
&GV
) {
118 return AllButMain
&& GV
.getName() == "main";
120 unwrap(PM
)->add(createInternalizePass(PreserveMain
));
123 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM
) {
124 unwrap(PM
)->add(createStripDeadPrototypesPass());
127 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM
) {
128 unwrap(PM
)->add(createStripSymbolsPass());