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