xref: /aosp_15_r20/external/llvm/lib/Transforms/IPO/IPO.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- IPO.cpp -----------------------------------------------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file implements the common infrastructure (including C bindings) for
11*9880d681SAndroid Build Coastguard Worker // libLLVMIPO.a, which implements several transformations over the LLVM
12*9880d681SAndroid Build Coastguard Worker // intermediate representation.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker 
16*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Initialization.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Transforms/IPO.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/InitializePasses.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/LegacyPassManager.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/FunctionAttrs.h"
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker using namespace llvm;
24*9880d681SAndroid Build Coastguard Worker 
initializeIPO(PassRegistry & Registry)25*9880d681SAndroid Build Coastguard Worker void llvm::initializeIPO(PassRegistry &Registry) {
26*9880d681SAndroid Build Coastguard Worker   initializeArgPromotionPass(Registry);
27*9880d681SAndroid Build Coastguard Worker   initializeConstantMergeLegacyPassPass(Registry);
28*9880d681SAndroid Build Coastguard Worker   initializeCrossDSOCFIPass(Registry);
29*9880d681SAndroid Build Coastguard Worker   initializeDAEPass(Registry);
30*9880d681SAndroid Build Coastguard Worker   initializeDAHPass(Registry);
31*9880d681SAndroid Build Coastguard Worker   initializeForceFunctionAttrsLegacyPassPass(Registry);
32*9880d681SAndroid Build Coastguard Worker   initializeGlobalDCELegacyPassPass(Registry);
33*9880d681SAndroid Build Coastguard Worker   initializeGlobalOptLegacyPassPass(Registry);
34*9880d681SAndroid Build Coastguard Worker   initializeIPCPPass(Registry);
35*9880d681SAndroid Build Coastguard Worker   initializeAlwaysInlinerPass(Registry);
36*9880d681SAndroid Build Coastguard Worker   initializeSimpleInlinerPass(Registry);
37*9880d681SAndroid Build Coastguard Worker   initializeInferFunctionAttrsLegacyPassPass(Registry);
38*9880d681SAndroid Build Coastguard Worker   initializeInternalizeLegacyPassPass(Registry);
39*9880d681SAndroid Build Coastguard Worker   initializeLoopExtractorPass(Registry);
40*9880d681SAndroid Build Coastguard Worker   initializeBlockExtractorPassPass(Registry);
41*9880d681SAndroid Build Coastguard Worker   initializeSingleLoopExtractorPass(Registry);
42*9880d681SAndroid Build Coastguard Worker   initializeLowerTypeTestsPass(Registry);
43*9880d681SAndroid Build Coastguard Worker   initializeMergeFunctionsPass(Registry);
44*9880d681SAndroid Build Coastguard Worker   initializePartialInlinerLegacyPassPass(Registry);
45*9880d681SAndroid Build Coastguard Worker   initializePostOrderFunctionAttrsLegacyPassPass(Registry);
46*9880d681SAndroid Build Coastguard Worker   initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
47*9880d681SAndroid Build Coastguard Worker   initializePruneEHPass(Registry);
48*9880d681SAndroid Build Coastguard Worker   initializeStripDeadPrototypesLegacyPassPass(Registry);
49*9880d681SAndroid Build Coastguard Worker   initializeStripSymbolsPass(Registry);
50*9880d681SAndroid Build Coastguard Worker   initializeStripDebugDeclarePass(Registry);
51*9880d681SAndroid Build Coastguard Worker   initializeStripDeadDebugInfoPass(Registry);
52*9880d681SAndroid Build Coastguard Worker   initializeStripNonDebugSymbolsPass(Registry);
53*9880d681SAndroid Build Coastguard Worker   initializeBarrierNoopPass(Registry);
54*9880d681SAndroid Build Coastguard Worker   initializeEliminateAvailableExternallyLegacyPassPass(Registry);
55*9880d681SAndroid Build Coastguard Worker   initializeSampleProfileLoaderLegacyPassPass(Registry);
56*9880d681SAndroid Build Coastguard Worker   initializeFunctionImportPassPass(Registry);
57*9880d681SAndroid Build Coastguard Worker   initializeWholeProgramDevirtPass(Registry);
58*9880d681SAndroid Build Coastguard Worker }
59*9880d681SAndroid Build Coastguard Worker 
LLVMInitializeIPO(LLVMPassRegistryRef R)60*9880d681SAndroid Build Coastguard Worker void LLVMInitializeIPO(LLVMPassRegistryRef R) {
61*9880d681SAndroid Build Coastguard Worker   initializeIPO(*unwrap(R));
62*9880d681SAndroid Build Coastguard Worker }
63*9880d681SAndroid Build Coastguard Worker 
LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM)64*9880d681SAndroid Build Coastguard Worker void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) {
65*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createArgumentPromotionPass());
66*9880d681SAndroid Build Coastguard Worker }
67*9880d681SAndroid Build Coastguard Worker 
LLVMAddConstantMergePass(LLVMPassManagerRef PM)68*9880d681SAndroid Build Coastguard Worker void LLVMAddConstantMergePass(LLVMPassManagerRef PM) {
69*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createConstantMergePass());
70*9880d681SAndroid Build Coastguard Worker }
71*9880d681SAndroid Build Coastguard Worker 
LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM)72*9880d681SAndroid Build Coastguard Worker void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) {
73*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createDeadArgEliminationPass());
74*9880d681SAndroid Build Coastguard Worker }
75*9880d681SAndroid Build Coastguard Worker 
LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM)76*9880d681SAndroid Build Coastguard Worker void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) {
77*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass());
78*9880d681SAndroid Build Coastguard Worker }
79*9880d681SAndroid Build Coastguard Worker 
LLVMAddFunctionInliningPass(LLVMPassManagerRef PM)80*9880d681SAndroid Build Coastguard Worker void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) {
81*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createFunctionInliningPass());
82*9880d681SAndroid Build Coastguard Worker }
83*9880d681SAndroid Build Coastguard Worker 
LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM)84*9880d681SAndroid Build Coastguard Worker void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) {
85*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(llvm::createAlwaysInlinerPass());
86*9880d681SAndroid Build Coastguard Worker }
87*9880d681SAndroid Build Coastguard Worker 
LLVMAddGlobalDCEPass(LLVMPassManagerRef PM)88*9880d681SAndroid Build Coastguard Worker void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) {
89*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createGlobalDCEPass());
90*9880d681SAndroid Build Coastguard Worker }
91*9880d681SAndroid Build Coastguard Worker 
LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM)92*9880d681SAndroid Build Coastguard Worker void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) {
93*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createGlobalOptimizerPass());
94*9880d681SAndroid Build Coastguard Worker }
95*9880d681SAndroid Build Coastguard Worker 
LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM)96*9880d681SAndroid Build Coastguard Worker void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) {
97*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createIPConstantPropagationPass());
98*9880d681SAndroid Build Coastguard Worker }
99*9880d681SAndroid Build Coastguard Worker 
LLVMAddPruneEHPass(LLVMPassManagerRef PM)100*9880d681SAndroid Build Coastguard Worker void LLVMAddPruneEHPass(LLVMPassManagerRef PM) {
101*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createPruneEHPass());
102*9880d681SAndroid Build Coastguard Worker }
103*9880d681SAndroid Build Coastguard Worker 
LLVMAddIPSCCPPass(LLVMPassManagerRef PM)104*9880d681SAndroid Build Coastguard Worker void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) {
105*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createIPSCCPPass());
106*9880d681SAndroid Build Coastguard Worker }
107*9880d681SAndroid Build Coastguard Worker 
LLVMAddInternalizePass(LLVMPassManagerRef PM,unsigned AllButMain)108*9880d681SAndroid Build Coastguard Worker void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
109*9880d681SAndroid Build Coastguard Worker   auto PreserveMain = [=](const GlobalValue &GV) {
110*9880d681SAndroid Build Coastguard Worker     return AllButMain && GV.getName() == "main";
111*9880d681SAndroid Build Coastguard Worker   };
112*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createInternalizePass(PreserveMain));
113*9880d681SAndroid Build Coastguard Worker }
114*9880d681SAndroid Build Coastguard Worker 
LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM)115*9880d681SAndroid Build Coastguard Worker void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
116*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createStripDeadPrototypesPass());
117*9880d681SAndroid Build Coastguard Worker }
118*9880d681SAndroid Build Coastguard Worker 
LLVMAddStripSymbolsPass(LLVMPassManagerRef PM)119*9880d681SAndroid Build Coastguard Worker void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) {
120*9880d681SAndroid Build Coastguard Worker   unwrap(PM)->add(createStripSymbolsPass());
121*9880d681SAndroid Build Coastguard Worker }
122