1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
llvm-mirror/test/Transforms/GlobalOpt/unnamed-addr.ll
Peter Collingbourne 5dcb77e9fb IR: Introduce local_unnamed_addr attribute.
If a local_unnamed_addr attribute is attached to a global, the address
is known to be insignificant within the module. It is distinct from the
existing unnamed_addr attribute in that it only describes a local property
of the module rather than a global property of the symbol.

This attribute is intended to be used by the code generator and LTO to allow
the linker to decide whether the global needs to be in the symbol table. It is
possible to exclude a global from the symbol table if three things are true:
- This attribute is present on every instance of the global (which means that
  the normal rule that the global must have a unique address can be broken without
  being observable by the program by performing comparisons against the global's
  address)
- The global has linkonce_odr linkage (which means that each linkage unit must have
  its own copy of the global if it requires one, and the copy in each linkage unit
  must be the same)
- It is a constant or a function (which means that the program cannot observe that
  the unique-address rule has been broken by writing to the global)

Although this attribute could in principle be computed from the module
contents, LTO clients (i.e. linkers) will normally need to be able to compute
this property as part of symbol resolution, and it would be inefficient to
materialize every module just to compute it.

See:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html
for earlier discussion.

Part of the fix for PR27553.

Differential Revision: http://reviews.llvm.org/D20348

llvm-svn: 272709
2016-06-14 21:01:22 +00:00

75 lines
1.7 KiB
LLVM

; RUN: opt -globalopt -S < %s | FileCheck %s
@a = internal global i32 0, align 4
@b = internal global i32 0, align 4
@c = internal global i32 0, align 4
@d = internal constant [4 x i8] c"foo\00", align 1
@e = linkonce_odr global i32 0
; CHECK: @a = internal global i32 0, align 4
; CHECK: @b = internal global i32 0, align 4
; CHECK: @c = internal unnamed_addr global i32 0, align 4
; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
; CHECK: @e = linkonce_odr local_unnamed_addr global i32 0
; CHECK: define internal fastcc void @used_internal() unnamed_addr {
define internal void @used_internal() {
ret void
}
define i32 @get_e() {
call void @used_internal()
%t = load i32, i32* @e
ret i32 %t
}
define void @set_e(i32 %x) {
store i32 %x, i32* @e
ret void
}
define i1 @bah(i64 %i) nounwind readonly optsize ssp {
entry:
%arrayidx4 = getelementptr inbounds [4 x i8], [4 x i8]* @d, i64 0, i64 %i
%tmp5 = load i8, i8* %arrayidx4, align 1
%array0 = bitcast [4 x i8]* @d to i8*
%tmp6 = load i8, i8* %array0, align 1
%cmp = icmp eq i8 %tmp5, %tmp6
ret i1 %cmp
}
define void @baz(i32 %x) {
entry:
store i32 %x, i32* @a, align 4
store i32 %x, i32* @b, align 4
store i32 %x, i32* @c, align 4
ret void
}
define i32 @foo(i32* %x) nounwind readnone optsize ssp {
entry:
%cmp = icmp eq i32* %x, @a
%conv = zext i1 %cmp to i32
ret i32 %conv
}
define i32 @bar() {
entry:
switch i64 ptrtoint (i32* @b to i64), label %sw.epilog [
i64 1, label %return
i64 0, label %return
]
sw.epilog:
ret i32 0
return:
ret i32 1
}
define i32 @zed() {
entry:
%tmp1 = load i32, i32* @c, align 4
ret i32 %tmp1
}