LLVM  12.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 
30  initializeCrossDSOCFIPass(Registry);
31  initializeDAEPass(Registry);
32  initializeDAHPass(Registry);
36  initializeGlobalSplitPass(Registry);
38  initializeIPCPPass(Registry);
53  initializePruneEHPass(Registry);
60  initializeBarrierNoopPass(Registry);
65 }
66 
68  initializeIPO(*unwrap(R));
69 }
70 
73 }
74 
77 }
78 
80  unwrap(PM)->add(createConstantMergePass());
81 }
82 
85 }
86 
89 }
90 
93 }
94 
97 }
98 
100  unwrap(PM)->add(createGlobalDCEPass());
101 }
102 
104  unwrap(PM)->add(createGlobalOptimizerPass());
105 }
106 
109 }
110 
112  unwrap(PM)->add(createPruneEHPass());
113 }
114 
116  unwrap(PM)->add(createIPSCCPPass());
117 }
118 
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 
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 
141 }
142 
144  unwrap(PM)->add(createStripSymbolsPass());
145 }
void initializeIPCPPass(PassRegistry &)
void initializeCalledValuePropagationLegacyPassPass(PassRegistry &)
ModulePass * createIPConstantPropagationPass()
createIPConstantPropagationPass - This pass propagates constants from call sites into the bodies of f...
void initializeOpenMPOptLegacyPassPass(PassRegistry &)
void initializeGlobalOptLegacyPassPass(PassRegistry &)
ModulePass * createStripDeadPrototypesPass()
createStripDeadPrototypesPass - This pass removes any function declarations (prototypes) that are not...
LLVMContext & Context
void initializeInternalizeLegacyPassPass(PassRegistry &)
void initializeLoopExtractorPass(PassRegistry &)
void initializeStripDeadDebugInfoPass(PassRegistry &)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ModulePass * createMergeFunctionsPass()
createMergeFunctionsPass - This pass discovers identical functions and collapses them.
void initializePartialInlinerLegacyPassPass(PassRegistry &)
void initializeSimpleInlinerPass(PassRegistry &)
void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM)
See llvm::createGlobalDCEPass function.
Definition: IPO.cpp:99
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
void initializeWholeProgramDevirtPass(PassRegistry &)
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions...
Definition: SCCP.cpp:93
void initializeGlobalSplitPass(PassRegistry &)
void initializeGlobalDCELegacyPassPass(PassRegistry &)
void LLVMAddPruneEHPass(LLVMPassManagerRef PM)
See llvm::createPruneEHPass function.
Definition: IPO.cpp:111
void initializeAttributorCGSCCLegacyPassPass(PassRegistry &)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:130
void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM)
See llvm::createAlwaysInlinerPass function.
Definition: IPO.cpp:95
void LLVMAddIPSCCPPass(LLVMPassManagerRef PM)
See llvm::createIPSCCPPass function.
Definition: IPO.cpp:115
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
void initializeStripSymbolsPass(PassRegistry &)
void initializePruneEHPass(PassRegistry &)
void initializeLowerTypeTestsPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:217
void LLVMAddConstantMergePass(LLVMPassManagerRef PM)
See llvm::createConstantMergePass function.
Definition: IPO.cpp:79
void initializeArgPromotionPass(PassRegistry &)
Pass * createArgumentPromotionPass(unsigned maxElements=3)
createArgumentPromotionPass - This pass promotes "by reference" arguments to be passed by value if th...
void initializeMergeFunctionsLegacyPassPass(PassRegistry &)
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry &)
void initializeStripNonDebugSymbolsPass(PassRegistry &)
void initializeCrossDSOCFIPass(PassRegistry &)
ModulePass * createCalledValuePropagationPass()
createCalledValuePropagationPass - Attach metadata to indirct call sites indicating the set of functi...
void initializeAttributorLegacyPassPass(PassRegistry &)
void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadArgEliminationPass function.
Definition: IPO.cpp:83
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:130
ModulePass * createGlobalDCEPass()
createGlobalDCEPass - This transform is designed to eliminate unreachable internal globals (functions...
void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry &)
ModulePass * createDeadArgEliminationPass()
createDeadArgEliminationPass - This pass removes arguments from functions which are not used by the b...
void initializeDAEPass(PassRegistry &)
void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain)
See llvm::createInternalizePass function.
Definition: IPO.cpp:123
void initializeFunctionImportLegacyPassPass(PassRegistry &)
Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
ModulePass * createConstantMergePass()
createConstantMergePass - This function returns a new pass that merges duplicate global constants tog...
ModulePass * createGlobalOptimizerPass()
createGlobalOptimizerPass - This function returns a new pass that optimizes non-address taken interna...
Definition: GlobalOpt.cpp:3200
void initializeSampleProfileLoaderLegacyPassPass(PassRegistry &)
Function Alias Analysis false
void initializeAlwaysInlinerLegacyPassPass(PassRegistry &)
int LLVMBool
Definition: Types.h:28
Pass * createPostOrderFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to compute function attrs in post-order.
void initializeConstantMergeLegacyPassPass(PassRegistry &)
void initializeIPO(PassRegistry &)
Initialize all passes linked into the IPO library.
Definition: IPO.cpp:25
void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM)
See llvm::createIPConstantPropagationPass function.
Definition: IPO.cpp:107
void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM)
See llvm::createCalledValuePropagationPass function.
Definition: IPO.cpp:75
void LLVMInitializeIPO(LLVMPassRegistryRef R)
Definition: IPO.cpp:67
Provides passes to inlining "always_inline" functions.
void initializeHotColdSplittingLegacyPassPass(PassRegistry &)
void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM)
See llvm::createMergeFunctionsPass function.
Definition: IPO.cpp:119
ModulePass * createInternalizePass(std::function< bool(const GlobalValue &)> MustPreserveGV)
createInternalizePass - This pass loops over all of the functions in the input module, internalizing all globals (functions and variables) it can.
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM)
See llvm::createArgumentPromotionPass function.
Definition: IPO.cpp:71
void initializeSingleLoopExtractorPass(PassRegistry &)
void initializeDAHPass(PassRegistry &)
void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM)
See llvm::createFunctionInliningPass function.
Definition: IPO.cpp:91
void initializeBlockExtractorPass(PassRegistry &)
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:212
void initializePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
void initializeIPSCCPLegacyPassPass(PassRegistry &)
void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM)
See llvm::createStripSymbolsPass function.
Definition: IPO.cpp:143
Provides passes for computing function attributes based on interprocedural analyses.
void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM)
See llvm::createGlobalOptimizerPass function.
Definition: IPO.cpp:103
void initializeForceFunctionAttrsLegacyPassPass(PassRegistry &)
void initializeStripDebugDeclarePass(PassRegistry &)
void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM)
See llvm::createFunctionAttrsPass function.
Definition: IPO.cpp:87
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
Pass * createPruneEHPass()
createPruneEHPass - Return a new pass object which transforms invoke instructions into calls...
Definition: PruneEH.cpp:61
void initializeBarrierNoopPass(PassRegistry &)
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM)
See llvm::createStripDeadPrototypesPass function.
Definition: IPO.cpp:139
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry &)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75