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 initializeOpenMPOptLegacyPassPass(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 initializeHotColdSplittingLegacyPassPass(Registry); 38 initializeIPCPPass(Registry); 39 initializeAlwaysInlinerLegacyPassPass(Registry); 40 initializeSimpleInlinerPass(Registry); 41 initializeInferFunctionAttrsLegacyPassPass(Registry); 42 initializeInternalizeLegacyPassPass(Registry); 43 initializeLoopExtractorPass(Registry); 44 initializeBlockExtractorPass(Registry); 45 initializeSingleLoopExtractorPass(Registry); 46 initializeLowerTypeTestsPass(Registry); 47 initializeMergeFunctionsLegacyPassPass(Registry); 48 initializePartialInlinerLegacyPassPass(Registry); 49 initializeAttributorLegacyPassPass(Registry); 50 initializeAttributorCGSCCLegacyPassPass(Registry); 51 initializePostOrderFunctionAttrsLegacyPassPass(Registry); 52 initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry); 53 initializePruneEHPass(Registry); 54 initializeIPSCCPLegacyPassPass(Registry); 55 initializeStripDeadPrototypesLegacyPassPass(Registry); 56 initializeStripSymbolsPass(Registry); 57 initializeStripDebugDeclarePass(Registry); 58 initializeStripDeadDebugInfoPass(Registry); 59 initializeStripNonDebugSymbolsPass(Registry); 60 initializeBarrierNoopPass(Registry); 61 initializeEliminateAvailableExternallyLegacyPassPass(Registry); 62 initializeSampleProfileLoaderLegacyPassPass(Registry); 63 initializeFunctionImportLegacyPassPass(Registry); 64 initializeWholeProgramDevirtPass(Registry); 65 } 66 67 void LLVMInitializeIPO(LLVMPassRegistryRef R) { 68 initializeIPO(*unwrap(R)); 69 } 70 71 void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { 72 unwrap(PM)->add(createArgumentPromotionPass()); 73 } 74 75 void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) { 76 unwrap(PM)->add(createCalledValuePropagationPass()); 77 } 78 79 void LLVMAddConstantMergePass(LLVMPassManagerRef PM) { 80 unwrap(PM)->add(createConstantMergePass()); 81 } 82 83 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { 84 unwrap(PM)->add(createDeadArgEliminationPass()); 85 } 86 87 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { 88 unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass()); 89 } 90 91 void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { 92 unwrap(PM)->add(createFunctionInliningPass()); 93 } 94 95 void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { 96 unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass()); 97 } 98 99 void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { 100 unwrap(PM)->add(createGlobalDCEPass()); 101 } 102 103 void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { 104 unwrap(PM)->add(createGlobalOptimizerPass()); 105 } 106 107 void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { 108 unwrap(PM)->add(createIPConstantPropagationPass()); 109 } 110 111 void LLVMAddPruneEHPass(LLVMPassManagerRef PM) { 112 unwrap(PM)->add(createPruneEHPass()); 113 } 114 115 void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { 116 unwrap(PM)->add(createIPSCCPPass()); 117 } 118 119 void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM) { 120 unwrap(PM)->add(createMergeFunctionsPass()); 121 } 122 123 void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { 124 auto PreserveMain = [=](const GlobalValue &GV) { 125 return AllButMain && GV.getName() == "main"; 126 }; 127 unwrap(PM)->add(createInternalizePass(PreserveMain)); 128 } 129 130 void LLVMAddInternalizePassWithMustPreservePredicate( 131 LLVMPassManagerRef PM, 132 void *Context, 133 LLVMBool (*Pred)(LLVMValueRef, void *)) { 134 unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) { 135 return Pred(wrap(&GV), Context) == 0 ? false : true; 136 })); 137 } 138 139 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { 140 unwrap(PM)->add(createStripDeadPrototypesPass()); 141 } 142 143 void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { 144 unwrap(PM)->add(createStripSymbolsPass()); 145 } 146