]> granicus.if.org Git - llvm/commitdiff
[LLVM-C] Improve Bindings to The Internalize Pass
authorRobert Widmann <devteam.codafi@gmail.com>
Tue, 23 Jul 2019 04:56:44 +0000 (04:56 +0000)
committerRobert Widmann <devteam.codafi@gmail.com>
Tue, 23 Jul 2019 04:56:44 +0000 (04:56 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366777 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7a82ed4641415b7099f117b0646b6c8690875c95..748b6db05e3c04998a70afbe7e43f2f437deac91 100644 (file)
@@ -67,6 +67,21 @@ void LLVMAddIPSCCPPass(LLVMPassManagerRef PM);
 /** See llvm::createInternalizePass function. */
 void LLVMAddInternalizePass(LLVMPassManagerRef, unsigned AllButMain);
 
+/**
+ * Create and add the internalize pass to the given pass manager with the
+ * provided preservation callback.
+ *
+ * The context parameter is forwarded to the callback on each invocation.
+ * As such, it is the responsibility of the caller to extend its lifetime
+ * until execution of this pass has finished.
+ *
+ * @see llvm::createInternalizePass function.
+ */
+void LLVMAddInternalizePassWithMustPreservePredicate(
+    LLVMPassManagerRef PM,
+    void *Context,
+    LLVMBool (*MustPreserve)(LLVMValueRef, void *));
+
 /** See llvm::createStripDeadPrototypesPass function. */
 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM);
 
index 34db75dd8b0380b0ef7a0e34848d5edba8dd334c..465ffbd905525f35cbce365641cc93e07c62eb5f 100644 (file)
@@ -121,6 +121,15 @@ void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
   unwrap(PM)->add(createInternalizePass(PreserveMain));
 }
 
+void LLVMAddInternalizePassWithMustPreservePredicate(
+    LLVMPassManagerRef PM,
+    void *Context,
+    LLVMBool (*Pred)(LLVMValueRef, void *)) {
+  unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
+    return Pred(wrap(&GV), Context) == 0 ? false : true;
+  }));
+}
+
 void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
   unwrap(PM)->add(createStripDeadPrototypesPass());
 }