<div dir="ltr">This is giving me link errors on initializePAEAnalysis.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 14, 2014 at 3:17 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Fri Nov 14 17:17:47 2014<br>
New Revision: 222061<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=222061&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=222061&view=rev</a><br>
Log:<br>
Don't make assumptions about the name of private global variables.<br>
<br>
Private variables are can be renamed, so it is not reliable to make<br>
decisions on the name.<br>
<br>
The name is also dropped by the assembler before getting to the<br>
linker, so using the name causes a disconnect between how llvm makes a<br>
decision (var name) and how the linker makes a decision (section it is<br>
in).<br>
<br>
This patch changes one case where we were looking at the variable name to use<br>
the section instead.<br>
<br>
Test tuning by Michael Gottesman.<br>
<br>
Added:<br>
    llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp<br>
    llvm/trunk/test/Transforms/ObjCARC/provenance.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/Analysis/Passes.h<br>
    llvm/trunk/include/llvm/InitializePasses.h<br>
    llvm/trunk/include/llvm/LinkAllPasses.h<br>
    llvm/trunk/lib/Analysis/Analysis.cpp<br>
    llvm/trunk/lib/Transforms/ObjCARC/CMakeLists.txt<br>
    llvm/trunk/lib/Transforms/ObjCARC/ObjCARC.h<br>
<br>
Modified: llvm/trunk/include/llvm/Analysis/Passes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Passes.h?rev=222061&r1=222060&r2=222061&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Passes.h?rev=222061&r1=222060&r2=222061&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/Passes.h (original)<br>
+++ llvm/trunk/include/llvm/Analysis/Passes.h Fri Nov 14 17:17:47 2014<br>
@@ -107,6 +107,8 @@ namespace llvm {<br>
   //<br>
   ImmutablePass *createObjCARCAliasAnalysisPass();<br>
<br>
+  FunctionPass *createPAEvalPass();<br>
+<br>
   //===--------------------------------------------------------------------===//<br>
   //<br>
   /// createLazyValueInfoPass - This creates an instance of the LazyValueInfo<br>
<br>
Modified: llvm/trunk/include/llvm/InitializePasses.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=222061&r1=222060&r2=222061&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=222061&r1=222060&r2=222061&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/InitializePasses.h (original)<br>
+++ llvm/trunk/include/llvm/InitializePasses.h Fri Nov 14 17:17:47 2014<br>
@@ -211,6 +211,7 @@ void initializeObjCARCAPElimPass(PassReg<br>
 void initializeObjCARCExpandPass(PassRegistry&);<br>
 void initializeObjCARCContractPass(PassRegistry&);<br>
 void initializeObjCARCOptPass(PassRegistry&);<br>
+void initializePAEvalPass(PassRegistry &);<br>
 void initializeOptimizePHIsPass(PassRegistry&);<br>
 void initializePartiallyInlineLibCallsPass(PassRegistry&);<br>
 void initializePEIPass(PassRegistry&);<br>
<br>
Modified: llvm/trunk/include/llvm/LinkAllPasses.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=222061&r1=222060&r2=222061&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=222061&r1=222060&r2=222061&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/LinkAllPasses.h (original)<br>
+++ llvm/trunk/include/llvm/LinkAllPasses.h Fri Nov 14 17:17:47 2014<br>
@@ -111,6 +111,7 @@ namespace {<br>
       (void) llvm::createObjCARCExpandPass();<br>
       (void) llvm::createObjCARCContractPass();<br>
       (void) llvm::createObjCARCOptPass();<br>
+      (void) llvm::createPAEvalPass();<br>
       (void) llvm::createPromoteMemoryToRegisterPass();<br>
       (void) llvm::createDemoteRegisterToMemoryPass();<br>
       (void) llvm::createPruneEHPass();<br>
<br>
Modified: llvm/trunk/lib/Analysis/Analysis.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=222061&r1=222060&r2=222061&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=222061&r1=222060&r2=222061&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/Analysis.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/Analysis.cpp Fri Nov 14 17:17:47 2014<br>
@@ -68,6 +68,7 @@ void llvm::initializeAnalysis(PassRegist<br>
   initializeTargetTransformInfoAnalysisGroup(Registry);<br>
   initializeTypeBasedAliasAnalysisPass(Registry);<br>
   initializeScopedNoAliasAAPass(Registry);<br>
+  initializePAEvalPass(Registry);<br>
 }<br>
<br>
 void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {<br>
<br>
Modified: llvm/trunk/lib/Transforms/ObjCARC/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/CMakeLists.txt?rev=222061&r1=222060&r2=222061&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/CMakeLists.txt?rev=222061&r1=222060&r2=222061&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/ObjCARC/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/Transforms/ObjCARC/CMakeLists.txt Fri Nov 14 17:17:47 2014<br>
@@ -8,6 +8,7 @@ add_llvm_library(LLVMObjCARCOpts<br>
   ObjCARCContract.cpp<br>
   DependencyAnalysis.cpp<br>
   ProvenanceAnalysis.cpp<br>
+  ProvenanceAnalysisEvaluator.cpp<br>
   )<br>
<br>
 add_dependencies(LLVMObjCARCOpts intrinsics_gen)<br>
<br>
Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARC.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARC.h?rev=222061&r1=222060&r2=222061&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARC.h?rev=222061&r1=222060&r2=222061&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARC.h (original)<br>
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARC.h Fri Nov 14 17:17:47 2014<br>
@@ -380,11 +380,15 @@ static inline bool IsObjCIdentifiedObjec<br>
       StringRef Name = GV->getName();<br>
       // These special variables are known to hold values which are not<br>
       // reference-counted pointers.<br>
-      if (Name.startswith("\01L_OBJC_SELECTOR_REFERENCES_") ||<br>
-          Name.startswith("\01L_OBJC_CLASSLIST_REFERENCES_") ||<br>
-          Name.startswith("\01L_OBJC_CLASSLIST_SUP_REFS_$_") ||<br>
-          Name.startswith("\01L_OBJC_METH_VAR_NAME_") ||<br>
-          Name.startswith("\01l_objc_msgSend_fixup_"))<br>
+      if (Name.startswith("\01l_objc_msgSend_fixup_"))<br>
+        return true;<br>
+<br>
+      StringRef Section = GV->getSection();<br>
+      if (Section.find("__message_refs") != StringRef::npos ||<br>
+          Section.find("__objc_classrefs") != StringRef::npos ||<br>
+          Section.find("__objc_superrefs") != StringRef::npos ||<br>
+          Section.find("__objc_methname") != StringRef::npos ||<br>
+          Section.find("__cstring") != StringRef::npos)<br>
         return true;<br>
     }<br>
   }<br>
<br>
Added: llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp?rev=222061&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp?rev=222061&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp (added)<br>
+++ llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp Fri Nov 14 17:17:47 2014<br>
@@ -0,0 +1,92 @@<br>
+//===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "ProvenanceAnalysis.h"<br>
+#include "llvm/Pass.h"<br>
+#include "llvm/ADT/SetVector.h"<br>
+#include "llvm/Analysis/AliasAnalysis.h"<br>
+#include "llvm/Analysis/Passes.h"<br>
+#include "llvm/IR/InstIterator.h"<br>
+#include "llvm/IR/Function.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+using namespace llvm;<br>
+using namespace llvm::objcarc;<br>
+<br>
+namespace {<br>
+class PAEval : public FunctionPass {<br>
+<br>
+public:<br>
+  static char ID;<br>
+  PAEval();<br>
+  void getAnalysisUsage(AnalysisUsage &AU) const override;<br>
+  bool runOnFunction(Function &F) override;<br>
+};<br>
+}<br>
+<br>
+char PAEval::ID = 0;<br>
+PAEval::PAEval() : FunctionPass(ID) {}<br>
+<br>
+void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {<br>
+  AU.addRequired<AliasAnalysis>();<br>
+}<br>
+<br>
+static StringRef getName(Value *V) {<br>
+  StringRef Name = V->getName();<br>
+  if (Name.startswith("\1"))<br>
+    return Name.substr(1);<br>
+  return Name;<br>
+}<br>
+<br>
+static void insertIfNamed(SetVector<Value *> &Values, Value *V) {<br>
+  if (!V->hasName())<br>
+    return;<br>
+  Values.insert(V);<br>
+}<br>
+<br>
+bool PAEval::runOnFunction(Function &F) {<br>
+  SetVector<Value *> Values;<br>
+<br>
+  for (auto &Arg : F.args())<br>
+    insertIfNamed(Values, &Arg);<br>
+<br>
+  for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {<br>
+    insertIfNamed(Values, &*I);<br>
+<br>
+    for (auto &Op : I->operands())<br>
+    insertIfNamed(Values, Op);<br>
+  }<br>
+<br>
+  ProvenanceAnalysis PA;<br>
+  PA.setAA(&getAnalysis<AliasAnalysis>());<br>
+<br>
+  for (Value *V1 : Values) {<br>
+    StringRef NameV1 = getName(V1);<br>
+    for (Value *V2 : Values) {<br>
+      StringRef NameV2 = getName(V2);<br>
+      if (NameV1 >= NameV2)<br>
+        continue;<br>
+      errs() << NameV1 << " and " << NameV2;<br>
+      if (PA.related(V1, V2))<br>
+        errs() << " are related.\n";<br>
+      else<br>
+        errs() << " are not related.\n";<br>
+    }<br>
+  }<br>
+<br>
+  return false;<br>
+}<br>
+<br>
+FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }<br>
+<br>
+INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",<br>
+                      "Evaluate ProvenanceAnalysis on all pairs", false, true)<br>
+INITIALIZE_AG_DEPENDENCY(AliasAnalysis)<br>
+INITIALIZE_PASS_END(PAEval, "pa-eval",<br>
+                    "Evaluate ProvenanceAnalysis on all pairs", false, true)<br>
<br>
Added: llvm/trunk/test/Transforms/ObjCARC/provenance.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/provenance.ll?rev=222061&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/provenance.ll?rev=222061&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/ObjCARC/provenance.ll (added)<br>
+++ llvm/trunk/test/Transforms/ObjCARC/provenance.ll Fri Nov 14 17:17:47 2014<br>
@@ -0,0 +1,52 @@<br>
+; RUN: opt -disable-output -pa-eval %s 2>&1 | FileCheck %s<br>
+<br>
+@"\01l_objc_msgSend_fixup_" = global i8 0<br>
+@g1 = global i8 0, section "__OBJC,__message_refs,literal_pointers,no_dead_strip"<br>
+@g2 = global i8 0, section "__DATA, __objc_classrefs, regular, no_dead_strip"<br>
+@g3 = global i8 0, section "__DATA, __objc_superrefs, regular, no_dead_strip"<br>
+@g4 = global i8 0, section "__TEXT,__objc_methname,cstring_literals"<br>
+@g5 = global i8 0, section "__TEXT,__cstring,cstring_literals"<br>
+<br>
+declare void @g(i8)<br>
+<br>
+define void @f(i8* %a, i8** %b, i8** %c) {<br>
+  %y1 = load i8* %a<br>
+  call void @g(i8 %y1)<br>
+<br>
+  %y2 = load i8** %b<br>
+  %y3 = load i8** %c<br>
+<br>
+  %x0 = load i8* @"\01l_objc_msgSend_fixup_"<br>
+  call void @g(i8 %x0)<br>
+<br>
+  %x1 = load i8* @g1<br>
+  call void @g(i8 %x1)<br>
+<br>
+  %x2 = load i8* @g2<br>
+  call void @g(i8 %x2)<br>
+<br>
+  %x3 = load i8* @g3<br>
+  call void @g(i8 %x3)<br>
+<br>
+  %x4 = load i8* @g4<br>
+  call void @g(i8 %x4)<br>
+<br>
+  %x5 = load i8* @g5<br>
+  call void @g(i8 %x5)<br>
+  ret void<br>
+}<br>
+<br>
+; CHECK: y1 and y2 are related.<br>
+; CHECK: y1 and y3 are related.<br>
+; CHECK: y2 and y3 are related.<br>
+; CHECK: x0 and y1 are not related.<br>
+; CHECK: x0 and y2 are not related.<br>
+; CHECK: x0 and y3 are not related.<br>
+; CHECK: l_objc_msgSend_fixup_ and y1 are not related.<br>
+; CHECK: l_objc_msgSend_fixup_ and y2 are not related.<br>
+; CHECK: l_objc_msgSend_fixup_ and y3 are not related.<br>
+; CHECK: x1 and y1 are not related.<br>
+; CHECK: x2 and y1 are not related.<br>
+; CHECK: x3 and y1 are not related.<br>
+; CHECK: x4 and y1 are not related.<br>
+; CHECK: x5 and y1 are not related.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>