[InstCombine] Signed saturation patterns
[llvm-core.git] / lib / Transforms / IPO / IPO.cpp
blobbddf75211599933b3fcd1cf26e8c17d1deb0e100
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 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 LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM) {
118 unwrap(PM)->add(createMergeFunctionsPass());
121 void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
122 auto PreserveMain = [=](const GlobalValue &GV) {
123 return AllButMain && GV.getName() == "main";
125 unwrap(PM)->add(createInternalizePass(PreserveMain));
128 void LLVMAddInternalizePassWithMustPreservePredicate(
129 LLVMPassManagerRef PM,
130 void *Context,
131 LLVMBool (*Pred)(LLVMValueRef, void *)) {
132 unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
133 return Pred(wrap(&GV), Context) == 0 ? false : true;
134 }));
137 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
138 unwrap(PM)->add(createStripDeadPrototypesPass());
141 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) {
142 unwrap(PM)->add(createStripSymbolsPass());