llvm.org GIT mirror llvm / 69bd41d
Revert r193251 : Use address-taken to disambiguate global variable and indirect memops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193489 91177308-0d34-0410-b5e6-96231b3b80d8 Shuxin Yang 6 years ago
18 changed file(s) with 11 addition(s) and 72 deletion(s). Raw diff Collapse all Expand all
509509 module, including those with external linkage or appearing in
510510 ``@llvm.used``. This assumption may be suppressed by marking the
511511 variable with ``externally_initialized``.
512
513 If a global variable dose not have its address taken, it will be optionally
514 flagged ``notaddrtaken``.
515512
516513 An explicit alignment may be specified for a global, which must be a
517514 power of 2. If not present, or if the alignment is set to zero, the
4747 // can change from its initial
4848 // value before global
4949 // initializers are run?
50 bool notAddrTaken : 1; // Dose not have address taken.
5150
5251 public:
5352 // allocate space for exactly one operand
174173 isExternallyInitializedConstant = Val;
175174 }
176175
177 void setAddressMaybeTaken(bool Val) { notAddrTaken = !Val; }
178 bool AddressMaybeTaken(void) const { return !notAddrTaken; }
179
180176 /// copyAttributesFrom - copy all additional attributes (those not needed to
181177 /// create a GlobalVariable) from the GlobalVariable Src to this one.
182178 void copyAttributesFrom(const GlobalValue *Src);
12371237 return NoAlias;
12381238 if (isEscapeSource(O2) && isNonEscapingLocalObject(O1))
12391239 return NoAlias;
1240
1241 // If one object is a global variable without address taken, the other one
1242 // is a different object, they will not alias because the global variable
1243 // in question cannot be indirectly accessed.
1244 if (const GlobalVariable *GV = dyn_cast(O1))
1245 if (!GV->AddressMaybeTaken())
1246 return NoAlias;
1247
1248 if (const GlobalVariable *GV = dyn_cast(O2))
1249 if (!GV->AddressMaybeTaken())
1250 return NoAlias;
12511240 }
12521241
12531242 // If the size of one access is larger than the entire object on the other
503503 KEYWORD(zeroinitializer);
504504 KEYWORD(undef);
505505 KEYWORD(null);
506 KEYWORD(notaddrtaken);
507506 KEYWORD(to);
508507 KEYWORD(tail);
509508 KEYWORD(target);
703703 unsigned Linkage, bool HasLinkage,
704704 unsigned Visibility) {
705705 unsigned AddrSpace;
706 bool IsConstant, UnnamedAddr, IsExternallyInitialized, notAddrTaken;
706 bool IsConstant, UnnamedAddr, IsExternallyInitialized;
707707 GlobalVariable::ThreadLocalMode TLM;
708708 LocTy UnnamedAddrLoc;
709709 LocTy IsExternallyInitializedLoc;
718718 IsExternallyInitialized,
719719 &IsExternallyInitializedLoc) ||
720720 ParseGlobalType(IsConstant) ||
721 ParseOptionalToken(lltok::kw_notaddrtaken, notAddrTaken) ||
722721 ParseType(Ty, TyLoc))
723722 return true;
724723
776775 GV->setLinkage((GlobalValue::LinkageTypes)Linkage);
777776 GV->setVisibility((GlobalValue::VisibilityTypes)Visibility);
778777 GV->setExternallyInitialized(IsExternallyInitialized);
779 GV->setAddressMaybeTaken(!notAddrTaken);
780778 GV->setThreadLocalMode(TLM);
781779 GV->setUnnamedAddr(UnnamedAddr);
782780
5050 kw_localdynamic, kw_initialexec, kw_localexec,
5151 kw_zeroinitializer,
5252 kw_undef, kw_null,
53 kw_notaddrtaken,
5453 kw_to,
5554 kw_tail,
5655 kw_target,
18471847 new GlobalVariable(*TheModule, Ty, isConstant, Linkage, 0, "", 0,
18481848 TLM, AddressSpace, ExternallyInitialized);
18491849 NewGV->setAlignment(Alignment);
1850 if (Record.size() > 10)
1851 NewGV->setAddressMaybeTaken(Record[10]);
1852
18531850 if (!Section.empty())
18541851 NewGV->setSection(Section);
18551852 NewGV->setVisibility(Visibility);
615615 Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0);
616616 if (GV->isThreadLocal() ||
617617 GV->getVisibility() != GlobalValue::DefaultVisibility ||
618 GV->hasUnnamedAddr() || GV->isExternallyInitialized() ||
619 !GV->AddressMaybeTaken()) {
618 GV->hasUnnamedAddr() || GV->isExternallyInitialized()) {
620619 Vals.push_back(getEncodedVisibility(GV));
621620 Vals.push_back(getEncodedThreadLocalMode(GV));
622621 Vals.push_back(GV->hasUnnamedAddr());
623622 Vals.push_back(GV->isExternallyInitialized());
624 Vals.push_back(GV->AddressMaybeTaken());
625623 } else {
626624 AbbrevToUse = SimpleGVarAbbrev;
627625 }
14581458 if (GV->hasUnnamedAddr()) Out << "unnamed_addr ";
14591459 if (GV->isExternallyInitialized()) Out << "externally_initialized ";
14601460 Out << (GV->isConstant() ? "constant " : "global ");
1461 if (!GV->AddressMaybeTaken()) Out << "notaddrtaken ";
14621461 TypePrinter.print(GV->getType()->getElementType(), Out);
14631462
14641463 if (GV->hasInitializer()) {
9898 }
9999
100100 LeakDetector::addGarbageObject(this);
101 setAddressMaybeTaken(true);
102101 }
103102
104103 GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
125124 Before->getParent()->getGlobalList().insert(Before, this);
126125 else
127126 M.getGlobalList().push_back(this);
128 setAddressMaybeTaken(true);
129127 }
130128
131129 void GlobalVariable::setParent(Module *parent) {
186184 GlobalValue::copyAttributesFrom(Src);
187185 const GlobalVariable *SrcVar = cast(Src);
188186 setThreadLocal(SrcVar->isThreadLocal());
189 setAddressMaybeTaken(SrcVar->AddressMaybeTaken());
190187 }
191188
192189
17221722 if (GlobalStatus::analyzeGlobal(GV, GS))
17231723 return false;
17241724
1725 GV->setAddressMaybeTaken(false);
17261725 if (!GS.IsCompared && !GV->hasUnnamedAddr()) {
17271726 GV->setUnnamedAddr(true);
17281727 NumUnnamed++;
+0
-29
test/Analysis/BasicAA/noaddrtaken.ll less more
None ; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info 2>&1 | FileCheck %s
1
2 ; ModuleID = 'b.c'
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.8.0"
5
6 ; CHECK: NoAlias: i32* %p, i32* @xyz
7
8 ;@xyz = global i32 12, align 4
9 @xyz = internal unnamed_addr global notaddrtaken i32 12, align 4
10
11 ; Function Attrs: nounwind ssp uwtable
12 define i32 @foo(i32* nocapture %p, i32* nocapture %q) #0 {
13 entry:
14 %0 = load i32* @xyz, align 4, !tbaa !0
15 %inc = add nsw i32 %0, 1
16 store i32 %inc, i32* @xyz, align 4, !tbaa !0
17 store i32 1, i32* %p, align 4, !tbaa !0
18 %1 = load i32* @xyz, align 4, !tbaa !0
19 store i32 %1, i32* %q, align 4, !tbaa !0
20 ret i32 undef
21 }
22
23 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
24
25 !0 = metadata !{metadata !1, metadata !1, i64 0}
26 !1 = metadata !{metadata !"int", metadata !2, i64 0}
27 !2 = metadata !{metadata !"omnipotent char", metadata !3, i64 0}
28 !3 = metadata !{metadata !"Simple C/C++ TBAA"}
None ; RUN: opt < %s -globalopt -S | grep "@X = internal unnamed_addr global notaddrtaken i32"
0 ; RUN: opt < %s -globalopt -S | grep "@X = internal unnamed_addr global i32"
11 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
22 target triple = "i386-apple-darwin7"
33 @X = internal global i32* null ; [#uses=2]
77 target triple = "x86_64-apple-darwin10.0"
88
99 @TOP = internal global i64* null ; [#uses=2]
10 ; CHECK: @TOP = internal unnamed_addr global notaddrtaken i64* null
10 ; CHECK: @TOP = internal unnamed_addr global i64* null
1111 @channelColumns = internal global i64 0 ; [#uses=2]
1212
1313 ; Derived from @DescribeChannel() in yacr2
22 @GV1 = internal global i64 1
33 @GV2 = internal global i32 0
44
5 ; CHECK: @GV1 = internal unnamed_addr constant notaddrtaken i64 1
6 ; CHECK: @GV2 = internal unnamed_addr global notaddrtaken i32 0
5 ; CHECK: @GV1 = internal unnamed_addr constant i64 1
6 ; CHECK: @GV2 = internal unnamed_addr global i32 0
77
88 define void @test1() {
99 entry:
0 ; RUN: opt < %s -globalopt -S > %t
1 ; RUN: grep "@Y = internal unnamed_addr global notaddrtaken \[3 x [%]struct.X\] zeroinitializer" %t
1 ; RUN: grep "@Y = internal unnamed_addr global \[3 x [%]struct.X\] zeroinitializer" %t
22 ; RUN: grep load %t | count 6
33 ; RUN: grep "add i32 [%]a, [%]b" %t | count 3
44
33 @G = internal addrspace(1) global i32 0
44 ; CHECK: @G
55 ; CHECK: addrspace(1)
6 ; CHECK: global notaddrtaken i1 false
6 ; CHECK: global i1 false
77
88 define void @set1() {
99 store i32 0, i32 addrspace(1)* @G
55 @d = internal constant [4 x i8] c"foo\00", align 1
66 @e = linkonce_odr global i32 0
77
8 ; CHECK: @a = internal global notaddrtaken i32 0, align 4
8 ; CHECK: @a = internal global i32 0, align 4
99 ; CHECK: @b = internal global i32 0, align 4
10 ; CHECK: @c = internal unnamed_addr global notaddrtaken i32 0, align 4
11 ; CHECK: @d = internal unnamed_addr constant notaddrtaken [4 x i8] c"foo\00", align 1
10 ; CHECK: @c = internal unnamed_addr global i32 0, align 4
11 ; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
1212 ; CHECK: @e = linkonce_odr global i32 0
1313
1414 define i32 @get_e() {