Skip to content

Commit fcf3c55

Browse files
committed
[LLVM-C] Improve Bindings to The Internalize Pass
Summary: Adds a binding to the internalize pass that allows the caller to pass a function pointer that acts as the visibility-preservation predicate. Previously, one could only pass an unsigned value (not LLVMBool?) that directed the pass to consider "main" or not. Reviewers: whitequark, deadalnix, harlanhaskins Reviewed By: whitequark, harlanhaskins Subscribers: kren1, hiraditya, llvm-commits, harlanhaskins Tags: #llvm Differential Revision: https://reviews.llvm.org/D62456 llvm-svn: 366777
1 parent 30f12a4 commit fcf3c55

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/include/llvm-c/Transforms/IPO.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ void LLVMAddIPSCCPPass(LLVMPassManagerRef PM);
6767
/** See llvm::createInternalizePass function. */
6868
void LLVMAddInternalizePass(LLVMPassManagerRef, unsigned AllButMain);
6969

70+
/**
71+
* Create and add the internalize pass to the given pass manager with the
72+
* provided preservation callback.
73+
*
74+
* The context parameter is forwarded to the callback on each invocation.
75+
* As such, it is the responsibility of the caller to extend its lifetime
76+
* until execution of this pass has finished.
77+
*
78+
* @see llvm::createInternalizePass function.
79+
*/
80+
void LLVMAddInternalizePassWithMustPreservePredicate(
81+
LLVMPassManagerRef PM,
82+
void *Context,
83+
LLVMBool (*MustPreserve)(LLVMValueRef, void *));
84+
7085
/** See llvm::createStripDeadPrototypesPass function. */
7186
void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM);
7287

llvm/lib/Transforms/IPO/IPO.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
121121
unwrap(PM)->add(createInternalizePass(PreserveMain));
122122
}
123123

124+
void LLVMAddInternalizePassWithMustPreservePredicate(
125+
LLVMPassManagerRef PM,
126+
void *Context,
127+
LLVMBool (*Pred)(LLVMValueRef, void *)) {
128+
unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
129+
return Pred(wrap(&GV), Context) == 0 ? false : true;
130+
}));
131+
}
132+
124133
void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
125134
unwrap(PM)->add(createStripDeadPrototypesPass());
126135
}

0 commit comments

Comments
 (0)