llvm-6502/test/Feature/recursivetype.ll

104 lines
3.9 KiB
LLVM
Raw Normal View History

; RUN: llvm-as < %s | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
; This file contains the output from the following compiled C code:
; typedef struct list {
; struct list *Next;
; int Data;
; } list;
;
; // Iterative insert fn
; void InsertIntoListTail(list **L, int Data) {
; while (*L)
; L = &(*L)->Next;
; *L = (list*)malloc(sizeof(list));
; (*L)->Data = Data;
; (*L)->Next = 0;
; }
;
; // Recursive list search fn
; list *FindData(list *L, int Data) {
; if (L == 0) return 0;
; if (L->Data == Data) return L;
; return FindData(L->Next, Data);
; }
;
; void DoListStuff() {
; list *MyList = 0;
; InsertIntoListTail(&MyList, 100);
; InsertIntoListTail(&MyList, 12);
; InsertIntoListTail(&MyList, 42);
; InsertIntoListTail(&MyList, 1123);
; InsertIntoListTail(&MyList, 1213);
;
; if (FindData(MyList, 75)) foundIt();
; if (FindData(MyList, 42)) foundIt();
; if (FindData(MyList, 700)) foundIt();
; }
%list = type { %list*, i32 }
declare i8* @malloc(i32)
define void @InsertIntoListTail(%list** %L, i32 %Data) {
bb1:
%reg116 = load %list*, %list** %L ; <%list*> [#uses=1]
%cast1004 = inttoptr i64 0 to %list* ; <%list*> [#uses=1]
%cond1000 = icmp eq %list* %reg116, %cast1004 ; <i1> [#uses=1]
br i1 %cond1000, label %bb3, label %bb2
bb2: ; preds = %bb2, %bb1
%reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ; <%list**> [#uses=1]
%cast1010 = bitcast %list** %reg117 to %list*** ; <%list***> [#uses=1]
%reg118 = load %list**, %list*** %cast1010 ; <%list**> [#uses=3]
%reg109 = load %list*, %list** %reg118 ; <%list*> [#uses=1]
%cast1005 = inttoptr i64 0 to %list* ; <%list*> [#uses=1]
%cond1001 = icmp ne %list* %reg109, %cast1005 ; <i1> [#uses=1]
br i1 %cond1001, label %bb2, label %bb3
bb3: ; preds = %bb2, %bb1
%reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ; <%list**> [#uses=1]
%cast1006 = bitcast %list** %reg119 to i8** ; <i8**> [#uses=1]
%reg111 = call i8* @malloc( i32 16 ) ; <i8*> [#uses=3]
store i8* %reg111, i8** %cast1006
%reg111.upgrd.1 = ptrtoint i8* %reg111 to i64 ; <i64> [#uses=1]
%reg1002 = add i64 %reg111.upgrd.1, 8 ; <i64> [#uses=1]
%reg1002.upgrd.2 = inttoptr i64 %reg1002 to i8* ; <i8*> [#uses=1]
%cast1008 = bitcast i8* %reg1002.upgrd.2 to i32* ; <i32*> [#uses=1]
store i32 %Data, i32* %cast1008
%cast1003 = inttoptr i64 0 to i64* ; <i64*> [#uses=1]
%cast1009 = bitcast i8* %reg111 to i64** ; <i64**> [#uses=1]
store i64* %cast1003, i64** %cast1009
ret void
}
define %list* @FindData(%list* %L, i32 %Data) {
bb1:
br label %bb2
bb2: ; preds = %bb6, %bb1
%reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ] ; <%list*> [#uses=4]
%cast1014 = inttoptr i64 0 to %list* ; <%list*> [#uses=1]
%cond1011 = icmp ne %list* %reg115, %cast1014 ; <i1> [#uses=1]
br i1 %cond1011, label %bb4, label %bb3
bb3: ; preds = %bb2
ret %list* null
bb4: ; preds = %bb2
[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
%idx = getelementptr %list, %list* %reg115, i64 0, i32 1 ; <i32*> [#uses=1]
%reg111 = load i32, i32* %idx ; <i32> [#uses=1]
%cond1013 = icmp ne i32 %reg111, %Data ; <i1> [#uses=1]
br i1 %cond1013, label %bb6, label %bb5
bb5: ; preds = %bb4
ret %list* %reg115
bb6: ; preds = %bb4
[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
%idx2 = getelementptr %list, %list* %reg115, i64 0, i32 0 ; <%list**> [#uses=1]
%reg116 = load %list*, %list** %idx2 ; <%list*> [#uses=1]
br label %bb2
}