[llvm-branch-commits] [llvm-branch] r345401 - Merging r344325:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Oct 26 09:52:32 PDT 2018


Author: tstellar
Date: Fri Oct 26 09:52:32 2018
New Revision: 345401

URL: http://llvm.org/viewvc/llvm-project?rev=345401&view=rev
Log:
Merging r344325:

------------------------------------------------------------------------
r344325 | evgeny777 | 2018-10-12 00:24:02 -0700 (Fri, 12 Oct 2018) | 4 lines

[ThinLTO] Don't import GV which contains blockaddress

Differential revision: https://reviews.llvm.org/D53139

------------------------------------------------------------------------

Added:
    llvm/branches/release_70/test/ThinLTO/X86/Inputs/globals-import-blockaddr.ll
    llvm/branches/release_70/test/ThinLTO/X86/globals-import-blockaddr.ll
Modified:
    llvm/branches/release_70/lib/Analysis/ModuleSummaryAnalysis.cpp
    llvm/branches/release_70/lib/Transforms/IPO/FunctionImport.cpp

Modified: llvm/branches/release_70/lib/Analysis/ModuleSummaryAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/lib/Analysis/ModuleSummaryAnalysis.cpp?rev=345401&r1=345400&r2=345401&view=diff
==============================================================================
--- llvm/branches/release_70/lib/Analysis/ModuleSummaryAnalysis.cpp (original)
+++ llvm/branches/release_70/lib/Analysis/ModuleSummaryAnalysis.cpp Fri Oct 26 09:52:32 2018
@@ -74,9 +74,17 @@ cl::opt<FunctionSummary::ForceSummaryHot
 // Walk through the operands of a given User via worklist iteration and populate
 // the set of GlobalValue references encountered. Invoked either on an
 // Instruction or a GlobalVariable (which walks its initializer).
-static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
+// Return true if any of the operands contains blockaddress. This is important
+// to know when computing summary for global var, because if global variable
+// references basic block address we can't import it separately from function
+// containing that basic block. For simplicity we currently don't import such
+// global vars at all. When importing function we aren't interested if any 
+// instruction in it takes an address of any basic block, because instruction
+// can only take an address of basic block located in the same function.
+static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
                          SetVector<ValueInfo> &RefEdges,
                          SmallPtrSet<const User *, 8> &Visited) {
+  bool HasBlockAddress = false;
   SmallVector<const User *, 32> Worklist;
   Worklist.push_back(CurUser);
 
@@ -92,8 +100,10 @@ static void findRefEdges(ModuleSummaryIn
       const User *Operand = dyn_cast<User>(OI);
       if (!Operand)
         continue;
-      if (isa<BlockAddress>(Operand))
+      if (isa<BlockAddress>(Operand)) {
+        HasBlockAddress = true;
         continue;
+      }
       if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
         // We have a reference to a global value. This should be added to
         // the reference set unless it is a callee. Callees are handled
@@ -105,6 +115,7 @@ static void findRefEdges(ModuleSummaryIn
       Worklist.push_back(Operand);
     }
   }
+  return HasBlockAddress;
 }
 
 static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount,
@@ -369,7 +380,7 @@ computeVariableSummary(ModuleSummaryInde
                        DenseSet<GlobalValue::GUID> &CantBePromoted) {
   SetVector<ValueInfo> RefEdges;
   SmallPtrSet<const User *, 8> Visited;
-  findRefEdges(Index, &V, RefEdges, Visited);
+  bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
   bool NonRenamableLocal = isNonRenamableLocal(V);
   GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
                                     /* Live = */ false, V.isDSOLocal());
@@ -377,6 +388,8 @@ computeVariableSummary(ModuleSummaryInde
       llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.takeVector());
   if (NonRenamableLocal)
     CantBePromoted.insert(V.getGUID());
+  if (HasBlockAddress)
+    GVarSummary->setNotEligibleToImport();
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 

Modified: llvm/branches/release_70/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/lib/Transforms/IPO/FunctionImport.cpp?rev=345401&r1=345400&r2=345401&view=diff
==============================================================================
--- llvm/branches/release_70/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/branches/release_70/lib/Transforms/IPO/FunctionImport.cpp Fri Oct 26 09:52:32 2018
@@ -258,8 +258,7 @@ static void computeImportForReferencedGl
 
     for (auto &RefSummary : VI.getSummaryList())
       if (RefSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind &&
-          // Don't try to import regular LTO summaries added to dummy module.
-          !RefSummary->modulePath().empty() &&
+          !RefSummary->notEligibleToImport() &&
           !GlobalValue::isInterposableLinkage(RefSummary->linkage()) &&
           RefSummary->refs().empty()) {
         ImportList[RefSummary->modulePath()].insert(VI.getGUID());

Added: llvm/branches/release_70/test/ThinLTO/X86/Inputs/globals-import-blockaddr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/test/ThinLTO/X86/Inputs/globals-import-blockaddr.ll?rev=345401&view=auto
==============================================================================
--- llvm/branches/release_70/test/ThinLTO/X86/Inputs/globals-import-blockaddr.ll (added)
+++ llvm/branches/release_70/test/ThinLTO/X86/Inputs/globals-import-blockaddr.ll Fri Oct 26 09:52:32 2018
@@ -0,0 +1,12 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at label_addr = internal constant [1 x i8*] [i8* blockaddress(@foo, %lb)], align 8
+
+; Function Attrs: noinline norecurse nounwind optnone uwtable
+define dso_local [1 x i8*]* @foo() {
+  br label %lb
+
+lb:
+  ret [1 x i8*]* @label_addr
+}

Added: llvm/branches/release_70/test/ThinLTO/X86/globals-import-blockaddr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/test/ThinLTO/X86/globals-import-blockaddr.ll?rev=345401&view=auto
==============================================================================
--- llvm/branches/release_70/test/ThinLTO/X86/globals-import-blockaddr.ll (added)
+++ llvm/branches/release_70/test/ThinLTO/X86/globals-import-blockaddr.ll Fri Oct 26 09:52:32 2018
@@ -0,0 +1,18 @@
+; RUN: opt -module-summary %s -o %t1.bc
+; RUN: opt -module-summary %p/Inputs/globals-import-blockaddr.ll -o %t2.bc
+; RUN: llvm-lto2 run -save-temps %t1.bc -r=%t1.bc,foo,l -r=%t1.bc,main,pl %t2.bc -r=%t2.bc,foo,pl -o %t3
+; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s
+
+; Verify that we haven't imported GV containing blockaddress
+; CHECK: @label_addr.llvm.0 = external hidden constant
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare dso_local [1 x i8*]* @foo();
+
+define dso_local i32 @main() {
+  %p = call [1 x i8*]* @foo()
+  %v = ptrtoint [1 x i8*]* %p to i32
+  ret i32 %v
+}




More information about the llvm-branch-commits mailing list