[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / lib / Transforms / IPO / IPO.cpp
blobdfd434e61d5b44b94550377d85fe27f159a21094
1 //===-- IPO.cpp -----------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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"
23 using namespace llvm;
25 void llvm::initializeIPO(PassRegistry &Registry) {
26 initializeOpenMPOptCGSCCLegacyPassPass(Registry);
27 initializeAnnotation2MetadataLegacyPass(Registry);
28 initializeCalledValuePropagationLegacyPassPass(Registry);
29 initializeConstantMergeLegacyPassPass(Registry);
30 initializeCrossDSOCFIPass(Registry);
31 initializeDAEPass(Registry);
32 initializeDAHPass(Registry);
33 initializeForceFunctionAttrsLegacyPassPass(Registry);
34 initializeFunctionSpecializationLegacyPassPass(Registry);
35 initializeGlobalDCELegacyPassPass(Registry);
36 initializeGlobalOptLegacyPassPass(Registry);
37 initializeGlobalSplitPass(Registry);
38 initializeHotColdSplittingLegacyPassPass(Registry);
39 initializeIROutlinerLegacyPassPass(Registry);
40 initializeAlwaysInlinerLegacyPassPass(Registry);
41 initializeSimpleInlinerPass(Registry);
42 initializeInferFunctionAttrsLegacyPassPass(Registry);
43 initializeInternalizeLegacyPassPass(Registry);
44 initializeLoopExtractorLegacyPassPass(Registry);
45 initializeBlockExtractorLegacyPassPass(Registry);
46 initializeSingleLoopExtractorPass(Registry);
47 initializeMergeFunctionsLegacyPassPass(Registry);
48 initializePartialInlinerLegacyPassPass(Registry);
49 initializeAttributorLegacyPassPass(Registry);
50 initializeAttributorCGSCCLegacyPassPass(Registry);
51 initializePostOrderFunctionAttrsLegacyPassPass(Registry);
52 initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
53 initializePruneEHPass(Registry);
54 initializeIPSCCPLegacyPassPass(Registry);
55 initializeStripDeadPrototypesLegacyPassPass(Registry);
56 initializeStripSymbolsPass(Registry);
57 initializeStripDebugDeclarePass(Registry);
58 initializeStripDeadDebugInfoPass(Registry);
59 initializeStripNonDebugSymbolsPass(Registry);
60 initializeBarrierNoopPass(Registry);
61 initializeEliminateAvailableExternallyLegacyPassPass(Registry);
64 void LLVMInitializeIPO(LLVMPassRegistryRef R) {
65 initializeIPO(*unwrap(R));
68 void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) {
69 unwrap(PM)->add(createCalledValuePropagationPass());
72 void LLVMAddConstantMergePass(LLVMPassManagerRef PM) {
73 unwrap(PM)->add(createConstantMergePass());
76 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) {
77 unwrap(PM)->add(createDeadArgEliminationPass());
80 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) {
81 unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass());
84 void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) {
85 unwrap(PM)->add(createFunctionInliningPass());
88 void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) {
89 unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass());
92 void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) {
93 unwrap(PM)->add(createGlobalDCEPass());
96 void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) {
97 unwrap(PM)->add(createGlobalOptimizerPass());
100 void LLVMAddPruneEHPass(LLVMPassManagerRef PM) {
101 unwrap(PM)->add(createPruneEHPass());
104 void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) {
105 unwrap(PM)->add(createIPSCCPPass());
108 void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM) {
109 unwrap(PM)->add(createMergeFunctionsPass());
112 void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
113 auto PreserveMain = [=](const GlobalValue &GV) {
114 return AllButMain && GV.getName() == "main";
116 unwrap(PM)->add(createInternalizePass(PreserveMain));
119 void LLVMAddInternalizePassWithMustPreservePredicate(
120 LLVMPassManagerRef PM,
121 void *Context,
122 LLVMBool (*Pred)(LLVMValueRef, void *)) {
123 unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
124 return Pred(wrap(&GV), Context) == 0 ? false : true;
125 }));
128 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
129 unwrap(PM)->add(createStripDeadPrototypesPass());
132 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) {
133 unwrap(PM)->add(createStripSymbolsPass());