<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I missed the Analysis->Object dependency this introduces.<div class=""><br class=""></div><div class="">I reverted in r286329, looks like we’ll need more thought on this.</div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><div class=""><br class=""></div><div class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 8, 2016, at 5:46 PM, David Jones <<a href="mailto:dlj@google.com" class="">dlj@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">It looks like this adds a new layering violation:<div class=""><br class=""></div><div class="">Analysis/ModuleSummaryAnalysis.cpp -></div><div class="">Object/IRObjectFile -></div><div class="">Bitcode -></div><div class="">Analysis</div><div class=""><br class=""></div><div class="">In particular, the long pole appears to be IRObjectFile::CollectAsmUndefinedRefs. It is almost independent of Object, except for BasicSymbolRef::Flags.</div><div class=""><br class=""></div><div class="">Ben and I looked at it for a bit but didn't see any obvious moves. Teresa, Mehdi, any ideas?</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Nov 8, 2016 at 1:53 PM, Teresa Johnson via llvm-commits <span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: tejohnson<br class="">
Date: Tue Nov  8 15:53:35 2016<br class="">
New Revision: 286297<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=286297&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project?rev=286297&view=rev</a><br class="">
Log:<br class="">
[ThinLTO] Prevent exporting of locals used/defined in module level asm<br class="">
<br class="">
Summary:<br class="">
This patch uses the same approach added for inline asm in r285513 to<br class="">
similarly prevent promotion/renaming of locals used or defined in module<br class="">
level asm.<br class="">
<br class="">
All static global values defined in normal IR and used in module level asm<br class="">
should be included on either the llvm.used or llvm.compiler.used global.<br class="">
The former were already being flagged as NoRename in the summary, and<br class="">
I've simply added llvm.compiler.used values to this handling.<br class="">
<br class="">
Module level asm may also contain defs of values. We need to prevent<br class="">
export of any refs to local values defined in module level asm (e.g. a<br class="">
ref in normal IR), since that also requires renaming/promotion of the<br class="">
local. To do that, the summary index builder looks at all values in the<br class="">
module level asm string that are not marked Weak or Global, which is<br class="">
exactly the set of locals that are defined. A summary is created for<br class="">
each of these local defs and flagged as NoRename.<br class="">
<br class="">
This required adding handling to the BitcodeWriter to look at GV<br class="">
declarations to see if they have a summary (rather than skipping them<br class="">
all).<br class="">
<br class="">
Finally, added an assert to IRObjectFile::<wbr class="">CollectAsmUndefinedRefs to<br class="">
ensure that an MCAsmParser is available, otherwise the module asm parse<br class="">
would silently fail. Initialized the asm parser in the opt tool for use<br class="">
in testing this fix.<br class="">
<br class="">
Fixes PR30610.<br class="">
<br class="">
Reviewers: mehdi_amini<br class="">
<br class="">
Subscribers: johanengelen, krasin, llvm-commits<br class="">
<br class="">
Differential Revision: <a href="https://reviews.llvm.org/D26146" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/<wbr class="">D26146</a><br class="">
<br class="">
Added:<br class="">
    llvm/trunk/test/ThinLTO/X86/<wbr class="">Inputs/module_asm2.ll<br class="">
    llvm/trunk/test/ThinLTO/X86/<wbr class="">module_asm2.ll<br class="">
Modified:<br class="">
    llvm/trunk/include/llvm/<wbr class="">Support/TargetRegistry.h<br class="">
    llvm/trunk/lib/Analysis/<wbr class="">LLVMBuild.txt<br class="">
    llvm/trunk/lib/Analysis/<wbr class="">ModuleSummaryAnalysis.cpp<br class="">
    llvm/trunk/lib/Bitcode/Writer/<wbr class="">BitcodeWriter.cpp<br class="">
    llvm/trunk/lib/Object/<wbr class="">IRObjectFile.cpp<br class="">
    llvm/trunk/test/LTO/X86/<wbr class="">current-section.ll<br class="">
    llvm/trunk/tools/opt/opt.cpp<br class="">
<br class="">
Modified: llvm/trunk/include/llvm/<wbr class="">Support/TargetRegistry.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetRegistry.h?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/include/<wbr class="">llvm/Support/TargetRegistry.h?<wbr class="">rev=286297&r1=286296&r2=<wbr class="">286297&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/include/llvm/<wbr class="">Support/TargetRegistry.h (original)<br class="">
+++ llvm/trunk/include/llvm/<wbr class="">Support/TargetRegistry.h Tue Nov  8 15:53:35 2016<br class="">
@@ -280,6 +280,9 @@ public:<br class="">
   /// hasMCAsmBackend - Check if this target supports .o generation.<br class="">
   bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }<br class="">
<br class="">
+  /// hasMCAsmParser - Check if this target supports assembly parsing.<br class="">
+  bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }<br class="">
+<br class="">
   /// @}<br class="">
   /// @name Feature Constructors<br class="">
   /// @{<br class="">
<br class="">
Modified: llvm/trunk/lib/Analysis/<wbr class="">LLVMBuild.txt<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LLVMBuild.txt?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/lib/<wbr class="">Analysis/LLVMBuild.txt?rev=<wbr class="">286297&r1=286296&r2=286297&<wbr class="">view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/lib/Analysis/<wbr class="">LLVMBuild.txt (original)<br class="">
+++ llvm/trunk/lib/Analysis/<wbr class="">LLVMBuild.txt Tue Nov  8 15:53:35 2016<br class="">
@@ -19,4 +19,4 @@<br class="">
 type = Library<br class="">
 name = Analysis<br class="">
 parent = Libraries<br class="">
-required_libraries = Core Support ProfileData<br class="">
+required_libraries = Core Support ProfileData Object<br class="">
<br class="">
Modified: llvm/trunk/lib/Analysis/<wbr class="">ModuleSummaryAnalysis.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/lib/<wbr class="">Analysis/<wbr class="">ModuleSummaryAnalysis.cpp?rev=<wbr class="">286297&r1=286296&r2=286297&<wbr class="">view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/lib/Analysis/<wbr class="">ModuleSummaryAnalysis.cpp (original)<br class="">
+++ llvm/trunk/lib/Analysis/<wbr class="">ModuleSummaryAnalysis.cpp Tue Nov  8 15:53:35 2016<br class="">
@@ -13,6 +13,7 @@<br class="">
 //===-------------------------<wbr class="">------------------------------<wbr class="">---------------===//<br class="">
<br class="">
 #include "llvm/Analysis/<wbr class="">ModuleSummaryAnalysis.h"<br class="">
+#include "llvm/ADT/Triple.h"<br class="">
 #include "llvm/Analysis/<wbr class="">BlockFrequencyInfo.h"<br class="">
 #include "llvm/Analysis/<wbr class="">BlockFrequencyInfoImpl.h"<br class="">
 #include "llvm/Analysis/<wbr class="">BranchProbabilityInfo.h"<br class="">
@@ -24,6 +25,7 @@<br class="">
 #include "llvm/IR/InstIterator.h"<br class="">
 #include "llvm/IR/IntrinsicInst.h"<br class="">
 #include "llvm/IR/ValueSymbolTable.h"<br class="">
+#include "llvm/Object/IRObjectFile.h"<br class="">
 #include "llvm/Pass.h"<br class="">
 using namespace llvm;<br class="">
<br class="">
@@ -194,12 +196,22 @@ ModuleSummaryIndex llvm::buildModuleSumm<br class="">
     ProfileSummaryInfo *PSI) {<br class="">
   ModuleSummaryIndex Index;<br class="">
<br class="">
-  // Identify the local values in the llvm.used set, which should not be<br class="">
-  // exported as they would then require renaming and promotion, but we<br class="">
-  // may have opaque uses e.g. in inline asm.<br class="">
+  // Identify the local values in the llvm.used and llvm.compiler.used sets,<br class="">
+  // which should not be exported as they would then require renaming and<br class="">
+  // promotion, but we may have opaque uses e.g. in inline asm. We collect them<br class="">
+  // here because we use this information to mark functions containing inline<br class="">
+  // assembly calls as not importable.<br class="">
+  SmallPtrSet<GlobalValue *, 8> LocalsUsed;<br class="">
   SmallPtrSet<GlobalValue *, 8> Used;<br class="">
+  // First collect those in the llvm.used set.<br class="">
   collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);<br class="">
-  SmallPtrSet<GlobalValue *, 8> LocalsUsed;<br class="">
+  for (auto *V : Used) {<br class="">
+    if (V->hasLocalLinkage())<br class="">
+      LocalsUsed.insert(V);<br class="">
+  }<br class="">
+  Used.clear();<br class="">
+  // Next collect those in the llvm.compiler.used set.<br class="">
+  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);<br class="">
   for (auto *V : Used) {<br class="">
     if (V->hasLocalLinkage())<br class="">
       LocalsUsed.insert(V);<br class="">
@@ -244,6 +256,47 @@ ModuleSummaryIndex llvm::buildModuleSumm<br class="">
     Summary->setNoRename();<br class="">
   }<br class="">
<br class="">
+  if (!M.getModuleInlineAsm().<wbr class="">empty()) {<br class="">
+    // Collect the local values defined by module level asm, and set up<br class="">
+    // summaries for these symbols so that they can be marked as NoRename,<br class="">
+    // to prevent export of any use of them in regular IR that would require<br class="">
+    // renaming within the module level asm. Note we don't need to create a<br class="">
+    // summary for weak or global defs, as they don't need to be flagged as<br class="">
+    // NoRename, and defs in module level asm can't be imported anyway.<br class="">
+    // Also, any values used but not defined within module level asm should<br class="">
+    // be listed on the llvm.used or llvm.compiler.used global and marked as<br class="">
+    // referenced from there.<br class="">
+    // FIXME: Rename CollectAsmUndefinedRefs to something more general, as we<br class="">
+    // are also using it to find the file-scope locals defined in module asm.<br class="">
+    object::IRObjectFile::<wbr class="">CollectAsmUndefinedRefs(<br class="">
+        Triple(M.getTargetTriple()), M.getModuleInlineAsm(),<br class="">
+        [&M, &Index](StringRef Name, object::BasicSymbolRef::Flags Flags) {<br class="">
+          // Symbols not marked as Weak or Global are local definitions.<br class="">
+          if (Flags & (object::BasicSymbolRef::SF_<wbr class="">Weak ||<br class="">
+                       object::BasicSymbolRef::SF_<wbr class="">Global))<br class="">
+            return;<br class="">
+          GlobalValue *GV = M.getNamedValue(Name);<br class="">
+          if (!GV)<br class="">
+            return;<br class="">
+          assert(GV->isDeclaration() && "Def in module asm already has definition");<br class="">
+          GlobalValueSummary::GVFlags GVFlags(GlobalValue::<wbr class="">InternalLinkage,<br class="">
+                                              /* NoRename */ true,<br class="">
+                                              /*IsNotViableToInline */ true);<br class="">
+          // Create the appropriate summary type.<br class="">
+          if (isa<Function>(GV)) {<br class="">
+            std::unique_ptr<<wbr class="">FunctionSummary> Summary =<br class="">
+                llvm::make_unique<<wbr class="">FunctionSummary>(GVFlags, 0);<br class="">
+            Summary->setNoRename();<br class="">
+            Index.addGlobalValueSummary(<wbr class="">Name, std::move(Summary));<br class="">
+          } else {<br class="">
+            std::unique_ptr<<wbr class="">GlobalVarSummary> Summary =<br class="">
+                llvm::make_unique<<wbr class="">GlobalVarSummary>(GVFlags);<br class="">
+            Summary->setNoRename();<br class="">
+            Index.addGlobalValueSummary(<wbr class="">Name, std::move(Summary));<br class="">
+          }<br class="">
+        });<br class="">
+  }<br class="">
+<br class="">
   return Index;<br class="">
 }<br class="">
<br class="">
<br class="">
Modified: llvm/trunk/lib/Bitcode/Writer/<wbr class="">BitcodeWriter.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/lib/<wbr class="">Bitcode/Writer/BitcodeWriter.<wbr class="">cpp?rev=286297&r1=286296&r2=<wbr class="">286297&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/lib/Bitcode/Writer/<wbr class="">BitcodeWriter.cpp (original)<br class="">
+++ llvm/trunk/lib/Bitcode/Writer/<wbr class="">BitcodeWriter.cpp Tue Nov  8 15:53:35 2016<br class="">
@@ -3327,11 +3327,16 @@ void ModuleBitcodeWriter::<wbr class="">writePerModule<br class="">
 void ModuleBitcodeWriter::<wbr class="">writeModuleLevelReferences(<br class="">
     const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,<br class="">
     unsigned FSModRefsAbbrev) {<br class="">
-  // Only interested in recording variable defs in the summary.<br class="">
-  if (V.isDeclaration())<br class="">
+  auto Summaries =<br class="">
+      Index-><wbr class="">findGlobalValueSummaryList(<wbr class="">GlobalValue::getGUID(V.<wbr class="">getName()));<br class="">
+  if (Summaries == Index->end()) {<br class="">
+    // Only declarations should not have a summary (a declaration might however<br class="">
+    // have a summary if the def was in module level asm).<br class="">
+    assert(V.isDeclaration());<br class="">
     return;<br class="">
+  }<br class="">
+  auto *Summary = Summaries->second.front().get(<wbr class="">);<br class="">
   NameVals.push_back(VE.<wbr class="">getValueID(&V));<br class="">
-  auto *Summary = Index->getGlobalValueSummary(<wbr class="">V);<br class="">
   GlobalVarSummary *VS = cast<GlobalVarSummary>(<wbr class="">Summary);<br class="">
   NameVals.push_back(<wbr class="">getEncodedGVSummaryFlags(VS-><wbr class="">flags()));<br class="">
<br class="">
@@ -3409,14 +3414,20 @@ void ModuleBitcodeWriter::<wbr class="">writePerModule<br class="">
   // Iterate over the list of functions instead of the Index to<br class="">
   // ensure the ordering is stable.<br class="">
   for (const Function &F : M) {<br class="">
-    if (F.isDeclaration())<br class="">
-      continue;<br class="">
     // Summary emission does not support anonymous functions, they have to<br class="">
     // renamed using the anonymous function renaming pass.<br class="">
     if (!F.hasName())<br class="">
       report_fatal_error("Unexpected anonymous function when writing summary");<br class="">
<br class="">
-    auto *Summary = Index->getGlobalValueSummary(<wbr class="">F);<br class="">
+    auto Summaries =<br class="">
+        Index-><wbr class="">findGlobalValueSummaryList(<wbr class="">GlobalValue::getGUID(F.<wbr class="">getName()));<br class="">
+    if (Summaries == Index->end()) {<br class="">
+      // Only declarations should not have a summary (a declaration might<br class="">
+      // however have a summary if the def was in module level asm).<br class="">
+      assert(F.isDeclaration());<br class="">
+      continue;<br class="">
+    }<br class="">
+    auto *Summary = Summaries->second.front().get(<wbr class="">);<br class="">
     writePerModuleFunctionSummaryR<wbr class="">ecord(NameVals, Summary, VE.getValueID(&F),<br class="">
                                         FSCallsAbbrev, FSCallsProfileAbbrev, F);<br class="">
   }<br class="">
<br class="">
Modified: llvm/trunk/lib/Object/<wbr class="">IRObjectFile.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/lib/Object/<wbr class="">IRObjectFile.cpp?rev=286297&<wbr class="">r1=286296&r2=286297&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/lib/Object/<wbr class="">IRObjectFile.cpp (original)<br class="">
+++ llvm/trunk/lib/Object/<wbr class="">IRObjectFile.cpp Tue Nov  8 15:53:35 2016<br class="">
@@ -54,8 +54,7 @@ void IRObjectFile::<wbr class="">CollectAsmUndefinedRe<br class="">
<br class="">
   std::string Err;<br class="">
   const Target *T = TargetRegistry::lookupTarget(<wbr class="">TT.str(), Err);<br class="">
-  if (!T)<br class="">
-    return;<br class="">
+  assert(T && T->hasMCAsmParser());<br class="">
<br class="">
   std::unique_ptr<<wbr class="">MCRegisterInfo> MRI(T->createMCRegInfo(TT.str(<wbr class="">)));<br class="">
   if (!MRI)<br class="">
<br class="">
Modified: llvm/trunk/test/LTO/X86/<wbr class="">current-section.ll<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/current-section.ll?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/test/LTO/<wbr class="">X86/current-section.ll?rev=<wbr class="">286297&r1=286296&r2=286297&<wbr class="">view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/test/LTO/X86/<wbr class="">current-section.ll (original)<br class="">
+++ llvm/trunk/test/LTO/X86/<wbr class="">current-section.ll Tue Nov  8 15:53:35 2016<br class="">
@@ -2,4 +2,7 @@<br class="">
 ; RUN: llvm-lto -o %t2 %t1<br class="">
 ; REQUIRES: default_triple<br class="">
<br class="">
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:<wbr class="">32:64-S128"<br class="">
+target triple = "x86_64-unknown-linux-gnu"<br class="">
+<br class="">
 module asm ".align 4"<br class="">
<br class="">
Added: llvm/trunk/test/ThinLTO/X86/<wbr class="">Inputs/module_asm2.ll<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/module_asm2.ll?rev=286297&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/test/<wbr class="">ThinLTO/X86/Inputs/module_<wbr class="">asm2.ll?rev=286297&view=auto</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/test/ThinLTO/X86/<wbr class="">Inputs/module_asm2.ll (added)<br class="">
+++ llvm/trunk/test/ThinLTO/X86/<wbr class="">Inputs/module_asm2.ll Tue Nov  8 15:53:35 2016<br class="">
@@ -0,0 +1,12 @@<br class="">
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:<wbr class="">32:64-S128"<br class="">
+target triple = "x86_64-unknown-linux-gnu"<br class="">
+<br class="">
+define i32 @main({ i64, { i64, i8* }* } %unnamed) #0 {<br class="">
+  %1 = call i32 @func1() #1<br class="">
+  %2 = call i32 @func2() #1<br class="">
+  %3 = call i32 @func3() #1<br class="">
+  ret i32 %1<br class="">
+}<br class="">
+declare i32 @func1() #1<br class="">
+declare i32 @func2() #1<br class="">
+declare i32 @func3() #1<br class="">
<br class="">
Added: llvm/trunk/test/ThinLTO/X86/<wbr class="">module_asm2.ll<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/module_asm2.ll?rev=286297&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/test/<wbr class="">ThinLTO/X86/module_asm2.ll?<wbr class="">rev=286297&view=auto</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/test/ThinLTO/X86/<wbr class="">module_asm2.ll (added)<br class="">
+++ llvm/trunk/test/ThinLTO/X86/<wbr class="">module_asm2.ll Tue Nov  8 15:53:35 2016<br class="">
@@ -0,0 +1,84 @@<br class="">
+; Test to ensure that uses and defs in module level asm are handled<br class="">
+; appropriately. Specifically, we should conservatively block importing<br class="">
+; of any references to these values, as they can't be renamed.<br class="">
+; RUN: opt -module-summary %s -o %t1.bc<br class="">
+; RUN: opt -module-summary %p/Inputs/module_asm2.ll -o %t2.bc<br class="">
+<br class="">
+; RUN: llvm-lto -thinlto-action=run -exported-symbol=main -exported-symbol=func1 -exported-symbol=func2 -exported-symbol=func3 %t1.bc %t2.bc<br class="">
+; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck  %s --check-prefix=NM0<br class="">
+; RUN: llvm-nm %t2.bc.thinlto.o | FileCheck  %s --check-prefix=NM1<br class="">
+<br class="">
+; RUN: llvm-lto2 %t1.bc %t2.bc -o %t.o -save-temps \<br class="">
+; RUN:     -r=%t1.bc,foo,plx \<br class="">
+; RUN:     -r=%t1.bc,b,pl \<br class="">
+; RUN:     -r=%t1.bc,x,pl \<br class="">
+; RUN:     -r=%t1.bc,func1,pl \<br class="">
+; RUN:     -r=%t1.bc,func2,pl \<br class="">
+; RUN:     -r=%t1.bc,func3,pl \<br class="">
+; RUN:     -r=%t2.bc,main,plx \<br class="">
+; RUN:     -r=%t2.bc,func1,l \<br class="">
+; RUN:     -r=%t2.bc,func2,l \<br class="">
+; RUN:     -r=%t2.bc,func3,l<br class="">
+; RUN: llvm-nm %t.o.0 | FileCheck  %s --check-prefix=NM0<br class="">
+; RUN: llvm-nm %t.o.1 | FileCheck  %s --check-prefix=NM1<br class="">
+<br class="">
+; Check that local values b and x, which are referenced on<br class="">
+; llvm.used and llvm.compiler.used, respectively, are not promoted.<br class="">
+; Similarly, foo which is defined in module level asm should not be<br class="">
+; promoted.<br class="">
+; NM0-DAG: d b<br class="">
+; NM0-DAG: d x<br class="">
+; NM0-DAG: t foo<br class="">
+; NM0-DAG: T func1<br class="">
+; NM0-DAG: T func2<br class="">
+; NM0-DAG: T func3<br class="">
+<br class="">
+; Ensure that foo, b and x are likewise not exported (imported as refs<br class="">
+; into the other module), since they can't be promoted. Additionally,<br class="">
+; referencing functions func1, func2 and func3 should not have been<br class="">
+; imported.<br class="">
+; NM1-NOT: foo<br class="">
+; NM1-NOT: b<br class="">
+; NM1-NOT: x<br class="">
+; NM1-DAG: U func1<br class="">
+; NM1-DAG: U func2<br class="">
+; NM1-DAG: U func3<br class="">
+; NM1-DAG: T main<br class="">
+; NM1-NOT: foo<br class="">
+; NM1-NOT: b<br class="">
+; NM1-NOT: x<br class="">
+<br class="">
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:<wbr class="">32:64-S128"<br class="">
+target triple = "x86_64-unknown-linux-gnu"<br class="">
+<br class="">
+@b = internal global i32 1, align 4<br class="">
+@x = internal global i32 1, align 4<br class="">
+<br class="">
+@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32* @b to i8*)], section "llvm.metadata"<br class="">
+@llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @x to i8*)], section "llvm.metadata"<br class="">
+<br class="">
+module asm "\09.text"<br class="">
+module asm "\09.type\09foo,@function"<br class="">
+module asm "foo:"<br class="">
+module asm "\09movl    b, %eax"<br class="">
+module asm "\09movl    x, %edx"<br class="">
+module asm "\09ret "<br class="">
+module asm "\09.size\09foo, .-foo"<br class="">
+module asm ""<br class="">
+<br class="">
+declare i16 @foo() #0<br class="">
+<br class="">
+define i32 @func1() #1 {<br class="">
+  call i16 @foo()<br class="">
+  ret i32 1<br class="">
+}<br class="">
+<br class="">
+define i32 @func2() #1 {<br class="">
+  %1 = load i32, i32* @b, align 4<br class="">
+  ret i32 %1<br class="">
+}<br class="">
+<br class="">
+define i32 @func3() #1 {<br class="">
+  %1 = load i32, i32* @x, align 4<br class="">
+  ret i32 %1<br class="">
+}<br class="">
<br class="">
Modified: llvm/trunk/tools/opt/opt.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=286297&r1=286296&r2=286297&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/tools/opt/<wbr class="">opt.cpp?rev=286297&r1=286296&<wbr class="">r2=286297&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/tools/opt/opt.cpp (original)<br class="">
+++ llvm/trunk/tools/opt/opt.cpp Tue Nov  8 15:53:35 2016<br class="">
@@ -364,6 +364,7 @@ int main(int argc, char **argv) {<br class="">
   InitializeAllTargets();<br class="">
   InitializeAllTargetMCs();<br class="">
   InitializeAllAsmPrinters();<br class="">
+  InitializeAllAsmParsers();<br class="">
<br class="">
   // Initialize passes<br class="">
   PassRegistry &Registry = *PassRegistry::<wbr class="">getPassRegistry();<br class="">
<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></body></html>