[PATCH] D39739: [HCC] Add flag to Import Weak Functions in Function Importer

Aaron En Ye Shi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 10:44:33 PST 2017


ashi1 updated this revision to Diff 122271.
ashi1 added subscribers: scchan, yaxunl, ashi1.
ashi1 added a comment.
Herald added a subscriber: eraman.

I've added the lit tests for this change, and also showing full context.

My lit test import_weak_type.ll follows similar format to import_opaque_type.ll.


Repository:
  rL LLVM

https://reviews.llvm.org/D39739

Files:
  include/llvm/Transforms/Utils/FunctionImportUtils.h
  lib/Transforms/IPO/FunctionImport.cpp
  lib/Transforms/Utils/FunctionImportUtils.cpp
  test/ThinLTO/X86/Inputs/import_weak_type.ll
  test/ThinLTO/X86/import_weak_type.ll


Index: test/ThinLTO/X86/import_weak_type.ll
===================================================================
--- /dev/null
+++ test/ThinLTO/X86/import_weak_type.ll
@@ -0,0 +1,19 @@
+; Do setup work for all below tests: generate bitcode and combined index
+; RUN: opt -module-summary %s -o %t.bc
+; RUN: opt -module-summary %p/Inputs/import_weak_type.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
+
+; Check that we import correctly the imported weak type to replace declaration here
+; RUN: llvm-lto -thinlto-action=import %t.bc -thinlto-index=%t3.bc -force-import-weak -o - | llvm-dis -o - | FileCheck %s
+; CHECK: define weak void @foo()
+
+
+target datalayout = "e-p:64:64-p1:64:64-p2:64:64-p3:32:32-p4:32:32-p5:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+target triple = "amdgcn--amdhsa-hcc"
+
+declare extern_weak void @foo()
+define weak_odr amdgpu_kernel void @main() {
+    call void @foo()
+  ret void
+}
+
Index: test/ThinLTO/X86/Inputs/import_weak_type.ll
===================================================================
--- /dev/null
+++ test/ThinLTO/X86/Inputs/import_weak_type.ll
@@ -0,0 +1,7 @@
+target datalayout = "e-p:64:64-p1:64:64-p2:64:64-p3:32:32-p4:32:32-p5:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+target triple = "amdgcn--amdhsa-hcc"
+
+define weak void @foo() {
+  ret void
+}
+
Index: lib/Transforms/Utils/FunctionImportUtils.cpp
===================================================================
--- lib/Transforms/Utils/FunctionImportUtils.cpp
+++ lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -151,7 +151,8 @@
     // program semantics, since the linker will pick the first weak_any
     // definition and importing would change the order they are seen by the
     // linker. The module linking caller needs to enforce this.
-    assert(!doImportAsDefinition(SGV));
+    if(!ForceImportWeakFlag)
+      assert(!doImportAsDefinition(SGV));
     // If imported as a declaration, it becomes external_weak.
     return SGV->getLinkage();
 
Index: lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- lib/Transforms/IPO/FunctionImport.cpp
+++ lib/Transforms/IPO/FunctionImport.cpp
@@ -102,6 +102,12 @@
 static cl::opt<bool> ComputeDead("compute-dead", cl::init(true), cl::Hidden,
                                  cl::desc("Compute dead symbols"));
 
+bool llvm::ForceImportWeakFlag;
+static cl::opt<bool, true>
+ForceImportWeak("force-import-weak", cl::Hidden,
+                cl::desc("Allow weak functions to be imported"),
+                cl::location(ForceImportWeakFlag), cl::init(false));
+
 static cl::opt<bool> EnableImportMetadata(
     "enable-import-metadata", cl::init(
 #if !defined(NDEBUG)
@@ -169,7 +175,7 @@
         // filtered out.
         if (GVSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind)
           return false;
-        if (GlobalValue::isInterposableLinkage(GVSummary->linkage()))
+        if (!ForceImportWeakFlag && GlobalValue::isInterposableLinkage(GVSummary->linkage()))
           // There is no point in importing these, we can't inline them
           return false;
         if (isa<AliasSummary>(GVSummary))
Index: include/llvm/Transforms/Utils/FunctionImportUtils.h
===================================================================
--- include/llvm/Transforms/Utils/FunctionImportUtils.h
+++ include/llvm/Transforms/Utils/FunctionImportUtils.h
@@ -21,6 +21,9 @@
 namespace llvm {
 class Module;
 
+// Set to true depending on option -force-import-weak
+extern bool ForceImportWeakFlag;
+
 /// Class to handle necessary GlobalValue changes required by ThinLTO
 /// function importing, including linkage changes and any necessary renaming.
 class FunctionImportGlobalProcessing {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39739.122271.patch
Type: text/x-patch
Size: 3895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171109/031de0e1/attachment.bin>


More information about the cfe-commits mailing list