David Blaikie 198d8baafb [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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230786 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-27 19:29:02 +00:00

155 lines
5.3 KiB
LLVM

; RUN: opt -alignment-from-assumptions -S < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%type1 = type { %type2 }
%type2 = type { [4 x i8] }
; Function Attrs: nounwind
declare void @llvm.assume(i1) #0
; Function Attrs: nounwind readnone
declare i32 @llvm.bswap.i32(i32) #1
; Function Attrs: nounwind uwtable
define void @test1() unnamed_addr #2 align 2 {
; CHECK-LABEL: @test1
entry:
br i1 undef, label %if.then, label %if.end
if.then: ; preds = %entry
unreachable
if.end: ; preds = %entry
br i1 undef, label %return, label %if.end8
if.end8: ; preds = %if.end
br i1 undef, label %if.then13, label %if.end14
if.then13: ; preds = %if.end8
unreachable
if.end14: ; preds = %if.end8
br i1 undef, label %cond.false.i129, label %cond.end.i136
cond.false.i129: ; preds = %if.end14
unreachable
cond.end.i136: ; preds = %if.end14
br i1 undef, label %land.lhs.true.i, label %if.end.i145
land.lhs.true.i: ; preds = %cond.end.i136
br i1 undef, label %if.end.i145, label %if.then.i137
if.then.i137: ; preds = %land.lhs.true.i
br i1 undef, label %cond.false8.i, label %cond.end9.i
cond.false8.i: ; preds = %if.then.i137
unreachable
cond.end9.i: ; preds = %if.then.i137
br i1 undef, label %if.then23, label %if.end24
if.end.i145: ; preds = %land.lhs.true.i, %cond.end.i136
unreachable
if.then23: ; preds = %cond.end9.i
unreachable
if.end24: ; preds = %cond.end9.i
br i1 undef, label %for.end, label %for.body.lr.ph
for.body.lr.ph: ; preds = %if.end24
unreachable
for.end: ; preds = %if.end24
br i1 undef, label %if.end123, label %if.then121
if.then121: ; preds = %for.end
unreachable
if.end123: ; preds = %for.end
br i1 undef, label %if.end150, label %if.then126
if.then126: ; preds = %if.end123
%ptrint.i.i185 = ptrtoint %type1* undef to i64
%maskedptr.i.i186 = and i64 %ptrint.i.i185, 1
%maskcond.i.i187 = icmp eq i64 %maskedptr.i.i186, 0
tail call void @llvm.assume(i1 %maskcond.i.i187) #0
%ret.0..sroa_cast.i.i188 = bitcast %type1* undef to i32*
%ret.0.copyload.i.i189 = load i32* %ret.0..sroa_cast.i.i188, align 2
; CHECK: load {{.*}} align 2
%0 = tail call i32 @llvm.bswap.i32(i32 %ret.0.copyload.i.i189) #0
%conv131 = zext i32 %0 to i64
%add.ptr132 = getelementptr inbounds i8, i8* undef, i64 %conv131
%1 = bitcast i8* %add.ptr132 to %type1*
br i1 undef, label %if.end150, label %if.end.i173
if.end.i173: ; preds = %if.then126
br i1 undef, label %test1.exit, label %cond.false.i.i.i.i174
cond.false.i.i.i.i174: ; preds = %if.end.i173
unreachable
test1.exit: ; preds = %if.end.i173
br i1 undef, label %test1a.exit, label %if.end.i124
if.end.i124: ; preds = %test1.exit
unreachable
test1a.exit: ; preds = %test1.exit
br i1 undef, label %if.end150, label %for.body137.lr.ph
for.body137.lr.ph: ; preds = %test1a.exit
br label %for.body137
for.body137: ; preds = %test1b.exit, %for.body137.lr.ph
%ShndxTable.0309 = phi %type1* [ %1, %for.body137.lr.ph ], [ %incdec.ptr, %test1b.exit ]
%ret.0..sroa_cast.i.i106 = bitcast %type1* %ShndxTable.0309 to i32*
br i1 undef, label %for.body137.if.end146_crit_edge, label %if.then140
for.body137.if.end146_crit_edge: ; preds = %for.body137
%incdec.ptr = getelementptr inbounds %type1, %type1* %ShndxTable.0309, i64 1
br i1 undef, label %cond.false.i70, label %cond.end.i
if.then140: ; preds = %for.body137
%ret.0.copyload.i.i102 = load i32* %ret.0..sroa_cast.i.i106, align 2
; CHECK: load {{.*}} align 2
unreachable
cond.false.i70: ; preds = %for.body137.if.end146_crit_edge
unreachable
cond.end.i: ; preds = %for.body137.if.end146_crit_edge
br i1 undef, label %test1b.exit, label %cond.false.i.i
cond.false.i.i: ; preds = %cond.end.i
unreachable
test1b.exit: ; preds = %cond.end.i
br i1 undef, label %if.end150, label %for.body137
if.end150: ; preds = %test1b.exit, %test1a.exit, %if.then126, %if.end123
br i1 undef, label %for.end176, label %for.body155.lr.ph
for.body155.lr.ph: ; preds = %if.end150
unreachable
for.end176: ; preds = %if.end150
unreachable
return: ; preds = %if.end
ret void
}
attributes #0 = { nounwind }
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind uwtable }