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