LLVM 17.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
19#include "llvm/Transforms/IPO.h"
22
23using namespace llvm;
24
53}
54
57}
58
61}
62
65}
66
69}
70
73}
74
77}
78
80 unwrap(PM)->add(createGlobalDCEPass());
81}
82
85}
86
88 unwrap(PM)->add(createIPSCCPPass());
89}
90
91void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
92 auto PreserveMain = [=](const GlobalValue &GV) {
93 return AllButMain && GV.getName() == "main";
94 };
95 unwrap(PM)->add(createInternalizePass(PreserveMain));
96}
97
100 void *Context,
101 LLVMBool (*Pred)(LLVMValueRef, void *)) {
102 unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
103 return Pred(wrap(&GV), Context) == 0 ? false : true;
104 }));
105}
106
109}
110
112 unwrap(PM)->add(createStripSymbolsPass());
113}
Provides passes to inlining "always_inline" functions.
Provides passes for computing function attributes based on interprocedural analyses.
LLVMContext & Context
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
void LLVMInitializeIPO(LLVMPassRegistryRef R)
Definition: IPO.cpp:55
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:130
void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM)
See llvm::createAlwaysInlinerPass function.
Definition: IPO.cpp:75
void LLVMAddConstantMergePass(LLVMPassManagerRef PM)
See llvm::createConstantMergePass function.
Definition: IPO.cpp:59
void LLVMAddIPSCCPPass(LLVMPassManagerRef PM)
See llvm::createIPSCCPPass function.
Definition: IPO.cpp:87
void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM)
See llvm::createGlobalOptimizerPass function.
Definition: IPO.cpp:83
void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM)
See llvm::createFunctionInliningPass function.
Definition: IPO.cpp:71
void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadArgEliminationPass function.
Definition: IPO.cpp:63
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:98
void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM)
See llvm::createFunctionAttrsPass function.
Definition: IPO.cpp:67
void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM)
See llvm::createGlobalDCEPass function.
Definition: IPO.cpp:79
void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM)
See llvm::createStripSymbolsPass function.
Definition: IPO.cpp:111
void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain)
See llvm::createInternalizePass function.
Definition: IPO.cpp:91
void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM)
See llvm::createStripDeadPrototypesPass function.
Definition: IPO.cpp:107
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeAttributorLegacyPassPass(PassRegistry &)
void initializeLoopExtractorLegacyPassPass(PassRegistry &)
void initializeSingleLoopExtractorPass(PassRegistry &)
void initializeAttributorCGSCCLegacyPassPass(PassRegistry &)
ModulePass * createDeadArgEliminationPass()
createDeadArgEliminationPass - This pass removes arguments from functions which are not used by the b...
void initializePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry &)
void initializeStripNonDebugSymbolsPass(PassRegistry &)
void initializeIPSCCPLegacyPassPass(PassRegistry &)
ModulePass * createInternalizePass()
createInternalizePass - Same as above, but with an empty exportList.
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry &)
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
void initializeGlobalOptLegacyPassPass(PassRegistry &)
ModulePass * createStripDeadPrototypesPass()
createStripDeadPrototypesPass - This pass removes any function declarations (prototypes) that are not...
void initializeDAHPass(PassRegistry &)
void initializeIPO(PassRegistry &)
Initialize all passes linked into the IPO library.
Definition: IPO.cpp:25
void initializeInternalizeLegacyPassPass(PassRegistry &)
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
void initializeForceFunctionAttrsLegacyPassPass(PassRegistry &)
Pass * createPostOrderFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to compute function attrs in post-order.
void initializeGlobalDCELegacyPassPass(PassRegistry &)
Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
void initializeAnnotation2MetadataLegacyPass(PassRegistry &)
void initializeCrossDSOCFIPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:285
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions,...
Definition: SCCP.cpp:478
void initializeSimpleInlinerPass(PassRegistry &)
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry &)
void initializeConstantMergeLegacyPassPass(PassRegistry &)
ModulePass * createGlobalOptimizerPass()
createGlobalOptimizerPass - This function returns a new pass that optimizes non-address taken interna...
Definition: GlobalOpt.cpp:2624
void initializeStripSymbolsPass(PassRegistry &)
void initializeGlobalSplitPass(PassRegistry &)
void initializeBarrierNoopPass(PassRegistry &)
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:280
void initializeDAEPass(PassRegistry &)
void initializeStripDeadDebugInfoPass(PassRegistry &)
ModulePass * createConstantMergePass()
createConstantMergePass - This function returns a new pass that merges duplicate global constants tog...
void initializeAlwaysInlinerLegacyPassPass(PassRegistry &)
ModulePass * createGlobalDCEPass()
createGlobalDCEPass - This transform is designed to eliminate unreachable internal globals (functions...
void initializeStripDebugDeclarePass(PassRegistry &)