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. 12 // 13 //===----------------------------------------------------------------------===// 14 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" 22 23 using namespace llvm; 24 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); 63 } 64 65 void LLVMInitializeIPO(LLVMPassRegistryRef R) { 66 initializeIPO(*unwrap(R)); 67 } 68 69 void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { 70 unwrap(PM)->add(createArgumentPromotionPass()); 71 } 72 73 void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) { 74 unwrap(PM)->add(createCalledValuePropagationPass()); 75 } 76 77 void LLVMAddConstantMergePass(LLVMPassManagerRef PM) { 78 unwrap(PM)->add(createConstantMergePass()); 79 } 80 81 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { 82 unwrap(PM)->add(createDeadArgEliminationPass()); 83 } 84 85 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { 86 unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass()); 87 } 88 89 void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { 90 unwrap(PM)->add(createFunctionInliningPass()); 91 } 92 93 void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { 94 unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass()); 95 } 96 97 void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { 98 unwrap(PM)->add(createGlobalDCEPass()); 99 } 100 101 void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { 102 unwrap(PM)->add(createGlobalOptimizerPass()); 103 } 104 105 void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { 106 unwrap(PM)->add(createIPConstantPropagationPass()); 107 } 108 109 void LLVMAddPruneEHPass(LLVMPassManagerRef PM) { 110 unwrap(PM)->add(createPruneEHPass()); 111 } 112 113 void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { 114 unwrap(PM)->add(createIPSCCPPass()); 115 } 116 117 void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM) { 118 unwrap(PM)->add(createMergeFunctionsPass()); 119 } 120 121 void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { 122 auto PreserveMain = [=](const GlobalValue &GV) { 123 return AllButMain && GV.getName() == "main"; 124 }; 125 unwrap(PM)->add(createInternalizePass(PreserveMain)); 126 } 127 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 })); 135 } 136 137 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { 138 unwrap(PM)->add(createStripDeadPrototypesPass()); 139 } 140 141 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { 142 unwrap(PM)->add(createStripSymbolsPass()); 143 } 144