2013-08-21 05:20:04 +08:00
|
|
|
; RUN: opt -S -instcombine %s -o - | FileCheck %s
|
|
|
|
target datalayout = "e-p:32:32:32-p1:64:64:64-p2:8:8:8-p3:16:16:16-p4:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32"
|
|
|
|
|
|
|
|
@g = addrspace(3) global i32 89
|
|
|
|
|
|
|
|
@const_zero_i8_as1 = addrspace(1) constant i8 0
|
|
|
|
@const_zero_i32_as1 = addrspace(1) constant i32 0
|
|
|
|
|
|
|
|
@const_zero_i8_as2 = addrspace(2) constant i8 0
|
|
|
|
@const_zero_i32_as2 = addrspace(2) constant i32 0
|
|
|
|
|
|
|
|
@const_zero_i8_as3 = addrspace(3) constant i8 0
|
|
|
|
@const_zero_i32_as3 = addrspace(3) constant i32 0
|
|
|
|
|
|
|
|
; Test constant folding of inttoptr (ptrtoint constantexpr)
|
|
|
|
; The intermediate integer size is the same as the pointer size
|
|
|
|
define i32 addrspace(3)* @test_constant_fold_inttoptr_as_pointer_same_size() {
|
|
|
|
; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_same_size(
|
|
|
|
; CHECK-NEXT: ret i32 addrspace(3)* @const_zero_i32_as3
|
|
|
|
%x = ptrtoint i32 addrspace(3)* @const_zero_i32_as3 to i32
|
|
|
|
%y = inttoptr i32 %x to i32 addrspace(3)*
|
|
|
|
ret i32 addrspace(3)* %y
|
|
|
|
}
|
|
|
|
|
|
|
|
; The intermediate integer size is larger than the pointer size
|
|
|
|
define i32 addrspace(2)* @test_constant_fold_inttoptr_as_pointer_smaller() {
|
|
|
|
; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_smaller(
|
|
|
|
; CHECK-NEXT: ret i32 addrspace(2)* @const_zero_i32_as2
|
|
|
|
%x = ptrtoint i32 addrspace(2)* @const_zero_i32_as2 to i16
|
|
|
|
%y = inttoptr i16 %x to i32 addrspace(2)*
|
|
|
|
ret i32 addrspace(2)* %y
|
|
|
|
}
|
|
|
|
|
|
|
|
; Different address spaces that are the same size, but they are
|
2013-11-15 09:34:59 +08:00
|
|
|
; different so nothing should happen
|
2013-08-21 05:20:04 +08:00
|
|
|
define i32 addrspace(4)* @test_constant_fold_inttoptr_as_pointer_smaller_different_as() {
|
|
|
|
; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_smaller_different_as(
|
2013-11-15 09:34:59 +08:00
|
|
|
; CHECK-NEXT: ret i32 addrspace(4)* inttoptr (i16 ptrtoint (i32 addrspace(3)* @const_zero_i32_as3 to i16) to i32 addrspace(4)*)
|
2013-08-21 05:20:04 +08:00
|
|
|
%x = ptrtoint i32 addrspace(3)* @const_zero_i32_as3 to i16
|
|
|
|
%y = inttoptr i16 %x to i32 addrspace(4)*
|
|
|
|
ret i32 addrspace(4)* %y
|
|
|
|
}
|
|
|
|
|
|
|
|
; Make sure we don't introduce a bitcast between different sized
|
|
|
|
; address spaces when folding this
|
|
|
|
define i32 addrspace(2)* @test_constant_fold_inttoptr_as_pointer_smaller_different_size_as() {
|
|
|
|
; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_smaller_different_size_as(
|
|
|
|
; CHECK-NEXT: ret i32 addrspace(2)* inttoptr (i32 ptrtoint (i32 addrspace(3)* @const_zero_i32_as3 to i32) to i32 addrspace(2)*)
|
|
|
|
%x = ptrtoint i32 addrspace(3)* @const_zero_i32_as3 to i32
|
|
|
|
%y = inttoptr i32 %x to i32 addrspace(2)*
|
|
|
|
ret i32 addrspace(2)* %y
|
|
|
|
}
|
|
|
|
|
|
|
|
; The intermediate integer size is too small, nothing should happen
|
|
|
|
define i32 addrspace(3)* @test_constant_fold_inttoptr_as_pointer_larger() {
|
|
|
|
; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_larger(
|
|
|
|
; CHECK-NEXT: ret i32 addrspace(3)* inttoptr (i8 ptrtoint (i32 addrspace(3)* @const_zero_i32_as3 to i8) to i32 addrspace(3)*)
|
|
|
|
%x = ptrtoint i32 addrspace(3)* @const_zero_i32_as3 to i8
|
|
|
|
%y = inttoptr i8 %x to i32 addrspace(3)*
|
|
|
|
ret i32 addrspace(3)* %y
|
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @const_fold_ptrtoint() {
|
|
|
|
; CHECK-LABEL: @const_fold_ptrtoint(
|
|
|
|
; CHECK-NEXT: ret i8 4
|
|
|
|
ret i8 ptrtoint (i32 addrspace(2)* inttoptr (i4 4 to i32 addrspace(2)*) to i8)
|
|
|
|
}
|
|
|
|
|
|
|
|
; Test that mask happens when the destination pointer is smaller than
|
|
|
|
; the original
|
|
|
|
define i8 @const_fold_ptrtoint_mask() {
|
|
|
|
; CHECK-LABEL: @const_fold_ptrtoint_mask(
|
|
|
|
; CHECK-NEXT: ret i8 1
|
|
|
|
ret i8 ptrtoint (i32 addrspace(3)* inttoptr (i32 257 to i32 addrspace(3)*) to i8)
|
|
|
|
}
|
|
|
|
|
2013-09-18 07:23:16 +08:00
|
|
|
; Address space 0 is too small for the correct mask, should mask with
|
|
|
|
; 64-bits instead of 32
|
|
|
|
define i64 @const_fold_ptrtoint_mask_small_as0() {
|
|
|
|
; CHECK-LABEL: @const_fold_ptrtoint_mask_small_as0(
|
|
|
|
; CHECK: ret i64 -1
|
|
|
|
ret i64 ptrtoint (i32 addrspace(1)* inttoptr (i128 -1 to i32 addrspace(1)*) to i64)
|
|
|
|
}
|
|
|
|
|
2013-08-21 05:20:04 +08:00
|
|
|
define i32 addrspace(3)* @const_inttoptr() {
|
|
|
|
; CHECK-LABEL: @const_inttoptr(
|
|
|
|
; CHECK-NEXT: ret i32 addrspace(3)* inttoptr (i16 4 to i32 addrspace(3)*)
|
|
|
|
%p = inttoptr i16 4 to i32 addrspace(3)*
|
|
|
|
ret i32 addrspace(3)* %p
|
|
|
|
}
|
|
|
|
|
|
|
|
define i16 @const_ptrtoint() {
|
|
|
|
; CHECK-LABEL: @const_ptrtoint(
|
|
|
|
; CHECK-NEXT: ret i16 ptrtoint (i32 addrspace(3)* @g to i16)
|
|
|
|
%i = ptrtoint i32 addrspace(3)* @g to i16
|
|
|
|
ret i16 %i
|
|
|
|
}
|
|
|
|
|
|
|
|
define i16 @const_inttoptr_ptrtoint() {
|
|
|
|
; CHECK-LABEL: @const_inttoptr_ptrtoint(
|
|
|
|
; CHECK-NEXT: ret i16 9
|
|
|
|
ret i16 ptrtoint (i32 addrspace(3)* inttoptr (i16 9 to i32 addrspace(3)*) to i16)
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @constant_fold_cmp_constantexpr_inttoptr() {
|
|
|
|
; CHECK-LABEL: @constant_fold_cmp_constantexpr_inttoptr(
|
|
|
|
; CHECK-NEXT: ret i1 true
|
|
|
|
%x = icmp eq i32 addrspace(3)* inttoptr (i16 0 to i32 addrspace(3)*), null
|
|
|
|
ret i1 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @constant_fold_inttoptr_null(i16 %i) {
|
|
|
|
; CHECK-LABEL: @constant_fold_inttoptr_null(
|
|
|
|
; CHECK-NEXT: ret i1 false
|
|
|
|
%x = icmp eq i32 addrspace(3)* inttoptr (i16 99 to i32 addrspace(3)*), inttoptr (i16 0 to i32 addrspace(3)*)
|
|
|
|
ret i1 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @constant_fold_ptrtoint_null() {
|
|
|
|
; CHECK-LABEL: @constant_fold_ptrtoint_null(
|
|
|
|
; CHECK-NEXT: ret i1 false
|
|
|
|
%x = icmp eq i16 ptrtoint (i32 addrspace(3)* @g to i16), ptrtoint (i32 addrspace(3)* null to i16)
|
|
|
|
ret i1 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @constant_fold_ptrtoint_null_2() {
|
|
|
|
; CHECK-LABEL: @constant_fold_ptrtoint_null_2(
|
|
|
|
; CHECK-NEXT: ret i1 false
|
|
|
|
%x = icmp eq i16 ptrtoint (i32 addrspace(3)* null to i16), ptrtoint (i32 addrspace(3)* @g to i16)
|
|
|
|
ret i1 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @constant_fold_ptrtoint() {
|
|
|
|
; CHECK-LABEL: @constant_fold_ptrtoint(
|
|
|
|
; CHECK-NEXT: ret i1 true
|
|
|
|
%x = icmp eq i16 ptrtoint (i32 addrspace(3)* @g to i16), ptrtoint (i32 addrspace(3)* @g to i16)
|
|
|
|
ret i1 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @constant_fold_inttoptr() {
|
|
|
|
; CHECK-LABEL: @constant_fold_inttoptr(
|
|
|
|
; CHECK-NEXT: ret i1 false
|
|
|
|
%x = icmp eq i32 addrspace(3)* inttoptr (i16 99 to i32 addrspace(3)*), inttoptr (i16 27 to i32 addrspace(3)*)
|
|
|
|
ret i1 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
@g_float_as3 = addrspace(3) global float zeroinitializer
|
|
|
|
@g_v4f_as3 = addrspace(3) global <4 x float> zeroinitializer
|
|
|
|
|
|
|
|
define float @constant_fold_bitcast_ftoi_load() {
|
|
|
|
; CHECK-LABEL: @constant_fold_bitcast_ftoi_load(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: load float, float addrspace(3)* bitcast (i32 addrspace(3)* @g to float addrspace(3)*), align 4
|
|
|
|
%a = load float, float addrspace(3)* bitcast (i32 addrspace(3)* @g to float addrspace(3)*), align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret float %a
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @constant_fold_bitcast_itof_load() {
|
|
|
|
; CHECK-LABEL: @constant_fold_bitcast_itof_load(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: load i32, i32 addrspace(3)* bitcast (float addrspace(3)* @g_float_as3 to i32 addrspace(3)*), align 4
|
|
|
|
%a = load i32, i32 addrspace(3)* bitcast (float addrspace(3)* @g_float_as3 to i32 addrspace(3)*), align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret i32 %a
|
|
|
|
}
|
|
|
|
|
2014-10-18 14:36:22 +08:00
|
|
|
define <4 x float> @constant_fold_bitcast_vector_as() {
|
2013-08-21 05:20:04 +08:00
|
|
|
; CHECK-LABEL: @constant_fold_bitcast_vector_as(
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK: load <4 x float>, <4 x float> addrspace(3)* @g_v4f_as3, align 16
|
|
|
|
%a = load <4 x float>, <4 x float> addrspace(3)* bitcast (<4 x i32> addrspace(3)* bitcast (<4 x float> addrspace(3)* @g_v4f_as3 to <4 x i32> addrspace(3)*) to <4 x float> addrspace(3)*), align 4
|
2014-10-18 14:36:22 +08:00
|
|
|
ret <4 x float> %a
|
2013-08-21 05:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@i32_array_as3 = addrspace(3) global [10 x i32] zeroinitializer
|
|
|
|
|
|
|
|
define i32 @test_cast_gep_small_indices_as() {
|
|
|
|
; CHECK-LABEL: @test_cast_gep_small_indices_as(
|
2015-03-14 02:20:45 +08:00
|
|
|
; CHECK: load i32, i32 addrspace(3)* getelementptr inbounds ([10 x i32], [10 x i32] addrspace(3)* @i32_array_as3, i16 0, i16 0), align 16
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
%p = getelementptr [10 x i32], [10 x i32] addrspace(3)* @i32_array_as3, i7 0, i7 0
|
2015-02-28 05:17:42 +08:00
|
|
|
%x = load i32, i32 addrspace(3)* %p, align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret i32 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
%struct.foo = type { float, float, [4 x i32], i32 addrspace(3)* }
|
|
|
|
|
|
|
|
@constant_fold_global_ptr = addrspace(3) global %struct.foo {
|
|
|
|
float 0.0,
|
|
|
|
float 0.0,
|
|
|
|
[4 x i32] zeroinitializer,
|
2015-03-14 02:20:45 +08:00
|
|
|
i32 addrspace(3)* getelementptr ([10 x i32], [10 x i32] addrspace(3)* @i32_array_as3, i64 0, i64 0)
|
2013-08-21 05:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_cast_gep_large_indices_as() {
|
|
|
|
; CHECK-LABEL: @test_cast_gep_large_indices_as(
|
2015-03-14 02:20:45 +08:00
|
|
|
; CHECK: load i32, i32 addrspace(3)* getelementptr inbounds ([10 x i32], [10 x i32] addrspace(3)* @i32_array_as3, i16 0, i16 0), align 16
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
%p = getelementptr [10 x i32], [10 x i32] addrspace(3)* @i32_array_as3, i64 0, i64 0
|
2015-02-28 05:17:42 +08:00
|
|
|
%x = load i32, i32 addrspace(3)* %p, align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret i32 %x
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_constant_cast_gep_struct_indices_as() {
|
|
|
|
; CHECK-LABEL: @test_constant_cast_gep_struct_indices_as(
|
2015-03-14 02:20:45 +08:00
|
|
|
; CHECK: load i32, i32 addrspace(3)* getelementptr inbounds (%struct.foo, %struct.foo addrspace(3)* @constant_fold_global_ptr, i16 0, i32 2, i16 2), align 8
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
%x = getelementptr %struct.foo, %struct.foo addrspace(3)* @constant_fold_global_ptr, i18 0, i32 2, i12 2
|
2015-02-28 05:17:42 +08:00
|
|
|
%y = load i32, i32 addrspace(3)* %x, align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret i32 %y
|
|
|
|
}
|
|
|
|
|
|
|
|
@constant_data_as3 = addrspace(3) constant [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
|
|
|
|
|
|
|
|
define i32 @test_read_data_from_global_as3() {
|
|
|
|
; CHECK-LABEL: @test_read_data_from_global_as3(
|
|
|
|
; CHECK-NEXT: ret i32 2
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
%x = getelementptr [5 x i32], [5 x i32] addrspace(3)* @constant_data_as3, i32 0, i32 1
|
2015-02-28 05:17:42 +08:00
|
|
|
%y = load i32, i32 addrspace(3)* %x, align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret i32 %y
|
|
|
|
}
|
|
|
|
|
|
|
|
@a = addrspace(1) constant i32 9
|
|
|
|
@b = addrspace(1) constant i32 23
|
|
|
|
@c = addrspace(1) constant i32 34
|
|
|
|
@d = addrspace(1) constant i32 99
|
|
|
|
|
|
|
|
@ptr_array = addrspace(2) constant [4 x i32 addrspace(1)*] [ i32 addrspace(1)* @a, i32 addrspace(1)* @b, i32 addrspace(1)* @c, i32 addrspace(1)* @d]
|
2015-03-14 02:20:45 +08:00
|
|
|
@indirect = addrspace(0) constant i32 addrspace(1)* addrspace(2)* getelementptr inbounds ([4 x i32 addrspace(1)*], [4 x i32 addrspace(1)*] addrspace(2)* @ptr_array, i1 0, i32 2)
|
2013-08-21 05:20:04 +08:00
|
|
|
|
|
|
|
define i32 @constant_through_array_as_ptrs() {
|
|
|
|
; CHECK-LABEL: @constant_through_array_as_ptrs(
|
|
|
|
; CHECK-NEXT: ret i32 34
|
2015-02-28 05:17:42 +08:00
|
|
|
%p = load i32 addrspace(1)* addrspace(2)*, i32 addrspace(1)* addrspace(2)* addrspace(0)* @indirect, align 4
|
|
|
|
%a = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(2)* %p, align 4
|
|
|
|
%b = load i32, i32 addrspace(1)* %a, align 4
|
2013-08-21 05:20:04 +08:00
|
|
|
ret i32 %b
|
|
|
|
}
|
2014-06-16 05:40:57 +08:00
|
|
|
|
|
|
|
@shared_mem = external addrspace(3) global [0 x i8]
|
|
|
|
|
|
|
|
define float @canonicalize_addrspacecast(i32 %i) {
|
|
|
|
; CHECK-LABEL: @canonicalize_addrspacecast
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
; CHECK-NEXT: getelementptr inbounds float, float* addrspacecast (float addrspace(3)* bitcast ([0 x i8] addrspace(3)* @shared_mem to float addrspace(3)*) to float*), i32 %i
|
|
|
|
%p = getelementptr inbounds float, float* addrspacecast ([0 x i8] addrspace(3)* @shared_mem to float*), i32 %i
|
2015-02-28 05:17:42 +08:00
|
|
|
%v = load float, float* %p
|
2014-06-16 05:40:57 +08:00
|
|
|
ret float %v
|
|
|
|
}
|