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/Transforms/IPO.h" 17 #include "llvm-c/Initialization.h" 18 #include "llvm/IR/LegacyPassManager.h" 19 #include "llvm/InitializePasses.h" 20 #include "llvm/Transforms/IPO.h" 21 #include "llvm/Transforms/IPO/AlwaysInliner.h" 22 #include "llvm/Transforms/IPO/FunctionAttrs.h" 23 24 using namespace llvm; 25 initializeIPO(PassRegistry & Registry)26void llvm::initializeIPO(PassRegistry &Registry) { 27 initializeArgPromotionPass(Registry); 28 initializeCalledValuePropagationLegacyPassPass(Registry); 29 initializeConstantMergeLegacyPassPass(Registry); 30 initializeCrossDSOCFIPass(Registry); 31 initializeDAEPass(Registry); 32 initializeDAHPass(Registry); 33 initializeForceFunctionAttrsLegacyPassPass(Registry); 34 initializeGlobalDCELegacyPassPass(Registry); 35 initializeGlobalOptLegacyPassPass(Registry); 36 initializeGlobalSplitPass(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); 62 } 63 LLVMInitializeIPO(LLVMPassRegistryRef R)64void LLVMInitializeIPO(LLVMPassRegistryRef R) { 65 initializeIPO(*unwrap(R)); 66 } 67 LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM)68void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { 69 unwrap(PM)->add(createArgumentPromotionPass()); 70 } 71 LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM)72void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) { 73 unwrap(PM)->add(createCalledValuePropagationPass()); 74 } 75 LLVMAddConstantMergePass(LLVMPassManagerRef PM)76void LLVMAddConstantMergePass(LLVMPassManagerRef PM) { 77 unwrap(PM)->add(createConstantMergePass()); 78 } 79 LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM)80void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { 81 unwrap(PM)->add(createDeadArgEliminationPass()); 82 } 83 LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM)84void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { 85 unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass()); 86 } 87 LLVMAddFunctionInliningPass(LLVMPassManagerRef PM)88void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { 89 unwrap(PM)->add(createFunctionInliningPass()); 90 } 91 LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM)92void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { 93 unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass()); 94 } 95 LLVMAddGlobalDCEPass(LLVMPassManagerRef PM)96void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { 97 unwrap(PM)->add(createGlobalDCEPass()); 98 } 99 LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM)100void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { 101 unwrap(PM)->add(createGlobalOptimizerPass()); 102 } 103 LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM)104void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { 105 unwrap(PM)->add(createIPConstantPropagationPass()); 106 } 107 LLVMAddPruneEHPass(LLVMPassManagerRef PM)108void LLVMAddPruneEHPass(LLVMPassManagerRef PM) { 109 unwrap(PM)->add(createPruneEHPass()); 110 } 111 LLVMAddIPSCCPPass(LLVMPassManagerRef PM)112void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { 113 unwrap(PM)->add(createIPSCCPPass()); 114 } 115 LLVMAddInternalizePass(LLVMPassManagerRef PM,unsigned AllButMain)116void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { 117 auto PreserveMain = [=](const GlobalValue &GV) { 118 return AllButMain && GV.getName() == "main"; 119 }; 120 unwrap(PM)->add(createInternalizePass(PreserveMain)); 121 } 122 LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM)123void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { 124 unwrap(PM)->add(createStripDeadPrototypesPass()); 125 } 126 LLVMAddStripSymbolsPass(LLVMPassManagerRef PM)127void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { 128 unwrap(PM)->add(createStripSymbolsPass()); 129 } 130