LLVM  14.0.0git
IPO.cpp
Go to the documentation of this file.
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"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Transforms/IPO.h"
22 
23 using namespace llvm;
24 
67 }
68 
70  initializeIPO(*unwrap(R));
71 }
72 
75 }
76 
79 }
80 
82  unwrap(PM)->add(createConstantMergePass());
83 }
84 
87 }
88 
91 }
92 
95 }
96 
99 }
100 
102  unwrap(PM)->add(createGlobalDCEPass());
103 }
104 
106  unwrap(PM)->add(createGlobalOptimizerPass());
107 }
108 
110  unwrap(PM)->add(createPruneEHPass());
111 }
112 
114  unwrap(PM)->add(createIPSCCPPass());
115 }
116 
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 
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 
139 }
140 
142  unwrap(PM)->add(createStripSymbolsPass());
143 }
llvm::initializeAlwaysInlinerLegacyPassPass
void initializeAlwaysInlinerLegacyPassPass(PassRegistry &)
LLVMAddFunctionInliningPass
void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM)
See llvm::createFunctionInliningPass function.
Definition: IPO.cpp:93
LLVMAddInternalizePassWithMustPreservePredicate
void LLVMAddInternalizePassWithMustPreservePredicate(LLVMPassManagerRef PM, void *Context, LLVMBool(*Pred)(LLVMValueRef, void *))
Create and add the internalize pass to the given pass manager with the provided preservation callback...
Definition: IPO.cpp:128
llvm::initializeBarrierNoopPass
void initializeBarrierNoopPass(PassRegistry &)
llvm::initializeAttributorLegacyPassPass
void initializeAttributorLegacyPassPass(PassRegistry &)
llvm::initializeArgPromotionPass
void initializeArgPromotionPass(PassRegistry &)
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
LLVMPassRegistryRef
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:130
LLVMAddArgumentPromotionPass
void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM)
See llvm::createArgumentPromotionPass function.
Definition: IPO.cpp:73
llvm::initializeInferFunctionAttrsLegacyPassPass
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry &)
llvm::createAlwaysInlinerLegacyPass
Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
Definition: AlwaysInliner.cpp:169
llvm::initializeOpenMPOptCGSCCLegacyPassPass
void initializeOpenMPOptCGSCCLegacyPassPass(PassRegistry &)
llvm::initializeLowerTypeTestsPass
void initializeLowerTypeTestsPass(PassRegistry &)
llvm::createPruneEHPass
Pass * createPruneEHPass()
createPruneEHPass - Return a new pass object which transforms invoke instructions into calls,...
Definition: PruneEH.cpp:63
IPO.h
llvm::initializeConstantMergeLegacyPassPass
void initializeConstantMergeLegacyPassPass(PassRegistry &)
llvm::createDeadArgEliminationPass
ModulePass * createDeadArgEliminationPass()
createDeadArgEliminationPass - This pass removes arguments from functions which are not used by the b...
llvm::initializeAnnotation2MetadataLegacyPass
void initializeAnnotation2MetadataLegacyPass(PassRegistry &)
llvm::initializeStripDeadDebugInfoPass
void initializeStripDeadDebugInfoPass(PassRegistry &)
llvm::createMergeFunctionsPass
ModulePass * createMergeFunctionsPass()
createMergeFunctionsPass - This pass discovers identical functions and collapses them.
llvm::initializeSampleProfileLoaderLegacyPassPass
void initializeSampleProfileLoaderLegacyPassPass(PassRegistry &)
llvm::initializeSimpleInlinerPass
void initializeSimpleInlinerPass(PassRegistry &)
LegacyPassManager.h
llvm::initializeGlobalOptLegacyPassPass
void initializeGlobalOptLegacyPassPass(PassRegistry &)
llvm::createStripDeadPrototypesPass
ModulePass * createStripDeadPrototypesPass()
createStripDeadPrototypesPass - This pass removes any function declarations (prototypes) that are not...
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::initializeStripDebugDeclarePass
void initializeStripDebugDeclarePass(PassRegistry &)
LLVMAddGlobalOptimizerPass
void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM)
See llvm::createGlobalOptimizerPass function.
Definition: IPO.cpp:105
AlwaysInliner.h
LLVMAddFunctionAttrsPass
void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM)
See llvm::createFunctionAttrsPass function.
Definition: IPO.cpp:89
LLVMAddDeadArgEliminationPass
void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadArgEliminationPass function.
Definition: IPO.cpp:85
LLVMAddGlobalDCEPass
void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM)
See llvm::createGlobalDCEPass function.
Definition: IPO.cpp:101
llvm::initializeFunctionImportLegacyPassPass
void initializeFunctionImportLegacyPassPass(PassRegistry &)
llvm::PassRegistry
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:256
llvm::initializeDAHPass
void initializeDAHPass(PassRegistry &)
LLVMAddAlwaysInlinerPass
void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM)
See llvm::createAlwaysInlinerPass function.
Definition: IPO.cpp:97
llvm::createGlobalOptimizerPass
ModulePass * createGlobalOptimizerPass()
createGlobalOptimizerPass - This function returns a new pass that optimizes non-address taken interna...
Definition: GlobalOpt.cpp:2768
LLVMAddMergeFunctionsPass
void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM)
See llvm::createMergeFunctionsPass function.
Definition: IPO.cpp:117
LLVMInitializeIPO
void LLVMInitializeIPO(LLVMPassRegistryRef R)
Definition: IPO.cpp:69
llvm::initializeWholeProgramDevirtPass
void initializeWholeProgramDevirtPass(PassRegistry &)
LLVMAddIPSCCPPass
void LLVMAddIPSCCPPass(LLVMPassManagerRef PM)
See llvm::createIPSCCPPass function.
Definition: IPO.cpp:113
llvm::createFunctionInliningPass
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
Definition: InlineSimple.cpp:97
llvm::createIPSCCPPass
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions,...
Definition: SCCP.cpp:106
llvm::initializeFunctionSpecializationLegacyPassPass
void initializeFunctionSpecializationLegacyPassPass(PassRegistry &)
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::initializeHotColdSplittingLegacyPassPass
void initializeHotColdSplittingLegacyPassPass(PassRegistry &)
LLVMAddStripDeadPrototypesPass
void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM)
See llvm::createStripDeadPrototypesPass function.
Definition: IPO.cpp:137
IPO.h
llvm::createGlobalDCEPass
ModulePass * createGlobalDCEPass()
createGlobalDCEPass - This transform is designed to eliminate unreachable internal globals (functions...
llvm::initializePruneEHPass
void initializePruneEHPass(PassRegistry &)
llvm::createPostOrderFunctionAttrsLegacyPass
Pass * createPostOrderFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to compute function attrs in post-order.
Definition: FunctionAttrs.cpp:1679
llvm::initializeSingleLoopExtractorPass
void initializeSingleLoopExtractorPass(PassRegistry &)
llvm::initializeIROutlinerLegacyPassPass
void initializeIROutlinerLegacyPassPass(PassRegistry &)
LLVMAddStripSymbolsPass
void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM)
See llvm::createStripSymbolsPass function.
Definition: IPO.cpp:141
llvm::createArgumentPromotionPass
Pass * createArgumentPromotionPass(unsigned maxElements=3)
createArgumentPromotionPass - This pass promotes "by reference" arguments to be passed by value if th...
Definition: ArgumentPromotion.cpp:1102
LLVMAddConstantMergePass
void LLVMAddConstantMergePass(LLVMPassManagerRef PM)
See llvm::createConstantMergePass function.
Definition: IPO.cpp:81
llvm::initializeForceFunctionAttrsLegacyPassPass
void initializeForceFunctionAttrsLegacyPassPass(PassRegistry &)
LLVMPassManagerRef
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:251
llvm::initializePartialInlinerLegacyPassPass
void initializePartialInlinerLegacyPassPass(PassRegistry &)
llvm::initializeReversePostOrderFunctionAttrsLegacyPassPass
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
llvm::initializeStripDeadPrototypesLegacyPassPass
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry &)
llvm::createStripSymbolsPass
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
llvm::initializePostOrderFunctionAttrsLegacyPassPass
void initializePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
llvm::initializeCrossDSOCFIPass
void initializeCrossDSOCFIPass(PassRegistry &)
llvm::initializeCalledValuePropagationLegacyPassPass
void initializeCalledValuePropagationLegacyPassPass(PassRegistry &)
llvm::createCalledValuePropagationPass
ModulePass * createCalledValuePropagationPass()
createCalledValuePropagationPass - Attach metadata to indirct call sites indicating the set of functi...
llvm::initializeGlobalSplitPass
void initializeGlobalSplitPass(PassRegistry &)
llvm::initializeMergeFunctionsLegacyPassPass
void initializeMergeFunctionsLegacyPassPass(PassRegistry &)
llvm::initializeLoopExtractorLegacyPassPass
void initializeLoopExtractorLegacyPassPass(PassRegistry &)
LLVMBool
int LLVMBool
Definition: Types.h:28
llvm::createInternalizePass
ModulePass * createInternalizePass(std::function< bool(const GlobalValue &)> MustPreserveGV)
createInternalizePass - This pass loops over all of the functions in the input module,...
Definition: Internalize.cpp:315
llvm::initializeStripSymbolsPass
void initializeStripSymbolsPass(PassRegistry &)
llvm::initializeIPO
void initializeIPO(PassRegistry &)
Initialize all passes linked into the IPO library.
Definition: IPO.cpp:25
llvm::initializeInternalizeLegacyPassPass
void initializeInternalizeLegacyPassPass(PassRegistry &)
llvm::initializeBlockExtractorLegacyPassPass
void initializeBlockExtractorLegacyPassPass(PassRegistry &)
false
Function Alias Analysis false
Definition: AliasAnalysis.cpp:847
llvm::Registry
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
llvm::createConstantMergePass
ModulePass * createConstantMergePass()
createConstantMergePass - This function returns a new pass that merges duplicate global constants tog...
LLVMAddInternalizePass
void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain)
See llvm::createInternalizePass function.
Definition: IPO.cpp:121
llvm::initializeEliminateAvailableExternallyLegacyPassPass
void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry &)
LLVMValueRef
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
llvm::initializeGlobalDCELegacyPassPass
void initializeGlobalDCELegacyPassPass(PassRegistry &)
llvm::initializeAttributorCGSCCLegacyPassPass
void initializeAttributorCGSCCLegacyPassPass(PassRegistry &)
llvm::initializeDAEPass
void initializeDAEPass(PassRegistry &)
LLVMAddPruneEHPass
void LLVMAddPruneEHPass(LLVMPassManagerRef PM)
See llvm::createPruneEHPass function.
Definition: IPO.cpp:109
llvm::initializeIPSCCPLegacyPassPass
void initializeIPSCCPLegacyPassPass(PassRegistry &)
InitializePasses.h
LLVMAddCalledValuePropagationPass
void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM)
See llvm::createCalledValuePropagationPass function.
Definition: IPO.cpp:77
FunctionAttrs.h
Initialization.h
llvm::initializeStripNonDebugSymbolsPass
void initializeStripNonDebugSymbolsPass(PassRegistry &)