transform: update allocs test to opaque pointers

Also, rename most of the SSA values while we're at it.
Этот коммит содержится в:
Ayke van Laethem 2023-03-16 19:34:35 +01:00 коммит произвёл Damian Gryski
родитель db08b5aaa5
коммит 0ddd65658e
2 изменённых файлов: 53 добавлений и 69 удалений

62
transform/testdata/allocs.ll предоставленный
Просмотреть файл

@ -3,57 +3,51 @@ target triple = "armv7m-none-eabi"
@runtime.zeroSizedAlloc = internal global i8 0, align 1 @runtime.zeroSizedAlloc = internal global i8 0, align 1
declare nonnull i8* @runtime.alloc(i32, i8*) declare nonnull ptr @runtime.alloc(i32, ptr)
; Test allocating a single int (i32) that should be allocated on the stack. ; Test allocating a single int (i32) that should be allocated on the stack.
define void @testInt() { define void @testInt() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* store i32 5, ptr %alloc
store i32 5, i32* %2
ret void ret void
} }
; Test allocating an array of 3 i16 values that should be allocated on the ; Test allocating an array of 3 i16 values that should be allocated on the
; stack. ; stack.
define i16 @testArray() { define i16 @testArray() {
%1 = call i8* @runtime.alloc(i32 6, i8* null) %alloc = call ptr @runtime.alloc(i32 6, ptr null)
%2 = bitcast i8* %1 to i16* %alloc.1 = getelementptr i16, ptr %alloc, i32 1
%3 = getelementptr i16, i16* %2, i32 1 store i16 5, ptr %alloc.1
store i16 5, i16* %3 %alloc.2 = getelementptr i16, ptr %alloc, i32 2
%4 = getelementptr i16, i16* %2, i32 2 %val = load i16, ptr %alloc.2
%5 = load i16, i16* %4 ret i16 %val
ret i16 %5
} }
; Call a function that will let the pointer escape, so the heap-to-stack ; Call a function that will let the pointer escape, so the heap-to-stack
; transform shouldn't be applied. ; transform shouldn't be applied.
define void @testEscapingCall() { define void @testEscapingCall() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* %val = call ptr @escapeIntPtr(ptr %alloc)
%3 = call i32* @escapeIntPtr(i32* %2)
ret void ret void
} }
define void @testEscapingCall2() { define void @testEscapingCall2() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc)
%3 = call i32* @escapeIntPtrSometimes(i32* %2, i32* %2)
ret void ret void
} }
; Call a function that doesn't let the pointer escape. ; Call a function that doesn't let the pointer escape.
define void @testNonEscapingCall() { define void @testNonEscapingCall() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* %val = call ptr @noescapeIntPtr(ptr %alloc)
%3 = call i32* @noescapeIntPtr(i32* %2)
ret void ret void
} }
; Return the allocated value, which lets it escape. ; Return the allocated value, which lets it escape.
define i32* @testEscapingReturn() { define ptr @testEscapingReturn() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* ret ptr %alloc
ret i32* %2
} }
; Do a non-escaping allocation in a loop. ; Do a non-escaping allocation in a loop.
@ -61,25 +55,23 @@ define void @testNonEscapingLoop() {
entry: entry:
br label %loop br label %loop
loop: loop:
%0 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%1 = bitcast i8* %0 to i32* %ptr = call ptr @noescapeIntPtr(ptr %alloc)
%2 = call i32* @noescapeIntPtr(i32* %1) %result = icmp eq ptr null, %ptr
%3 = icmp eq i32* null, %2 br i1 %result, label %loop, label %end
br i1 %3, label %loop, label %end
end: end:
ret void ret void
} }
; Test a zero-sized allocation. ; Test a zero-sized allocation.
define void @testZeroSizedAlloc() { define void @testZeroSizedAlloc() {
%1 = call i8* @runtime.alloc(i32 0, i8* null) %alloc = call ptr @runtime.alloc(i32 0, ptr null)
%2 = bitcast i8* %1 to i32* %ptr = call ptr @noescapeIntPtr(ptr %alloc)
%3 = call i32* @noescapeIntPtr(i32* %2)
ret void ret void
} }
declare i32* @escapeIntPtr(i32*) declare ptr @escapeIntPtr(ptr)
declare i32* @noescapeIntPtr(i32* nocapture) declare ptr @noescapeIntPtr(ptr nocapture)
declare i32* @escapeIntPtrSometimes(i32* nocapture, i32*) declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr)

60
transform/testdata/allocs.out.ll предоставленный
Просмотреть файл

@ -3,53 +3,47 @@ target triple = "armv7m-none-eabi"
@runtime.zeroSizedAlloc = internal global i8 0, align 1 @runtime.zeroSizedAlloc = internal global i8 0, align 1
declare nonnull i8* @runtime.alloc(i32, i8*) declare nonnull ptr @runtime.alloc(i32, ptr)
define void @testInt() { define void @testInt() {
%stackalloc.alloca = alloca [4 x i8], align 4 %stackalloc.alloca = alloca [4 x i8], align 4
store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4
%stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* store i32 5, ptr %stackalloc.alloca, align 4
store i32 5, i32* %stackalloc, align 4
ret void ret void
} }
define i16 @testArray() { define i16 @testArray() {
%stackalloc.alloca = alloca [6 x i8], align 2 %stackalloc.alloca = alloca [6 x i8], align 2
store [6 x i8] zeroinitializer, [6 x i8]* %stackalloc.alloca, align 2 store [6 x i8] zeroinitializer, ptr %stackalloc.alloca, align 2
%stackalloc = bitcast [6 x i8]* %stackalloc.alloca to i16* %alloc.1 = getelementptr i16, ptr %stackalloc.alloca, i32 1
%1 = getelementptr i16, i16* %stackalloc, i32 1 store i16 5, ptr %alloc.1, align 2
store i16 5, i16* %1, align 2 %alloc.2 = getelementptr i16, ptr %stackalloc.alloca, i32 2
%2 = getelementptr i16, i16* %stackalloc, i32 2 %val = load i16, ptr %alloc.2, align 2
%3 = load i16, i16* %2, align 2 ret i16 %val
ret i16 %3
} }
define void @testEscapingCall() { define void @testEscapingCall() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* %val = call ptr @escapeIntPtr(ptr %alloc)
%3 = call i32* @escapeIntPtr(i32* %2)
ret void ret void
} }
define void @testEscapingCall2() { define void @testEscapingCall2() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc)
%3 = call i32* @escapeIntPtrSometimes(i32* %2, i32* %2)
ret void ret void
} }
define void @testNonEscapingCall() { define void @testNonEscapingCall() {
%stackalloc.alloca = alloca [4 x i8], align 4 %stackalloc.alloca = alloca [4 x i8], align 4
store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4
%stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* %val = call ptr @noescapeIntPtr(ptr %stackalloc.alloca)
%1 = call i32* @noescapeIntPtr(i32* %stackalloc)
ret void ret void
} }
define i32* @testEscapingReturn() { define ptr @testEscapingReturn() {
%1 = call i8* @runtime.alloc(i32 4, i8* null) %alloc = call ptr @runtime.alloc(i32 4, ptr null)
%2 = bitcast i8* %1 to i32* ret ptr %alloc
ret i32* %2
} }
define void @testNonEscapingLoop() { define void @testNonEscapingLoop() {
@ -58,24 +52,22 @@ entry:
br label %loop br label %loop
loop: ; preds = %loop, %entry loop: ; preds = %loop, %entry
store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4
%stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* %ptr = call ptr @noescapeIntPtr(ptr %stackalloc.alloca)
%0 = call i32* @noescapeIntPtr(i32* %stackalloc) %result = icmp eq ptr null, %ptr
%1 = icmp eq i32* null, %0 br i1 %result, label %loop, label %end
br i1 %1, label %loop, label %end
end: ; preds = %loop end: ; preds = %loop
ret void ret void
} }
define void @testZeroSizedAlloc() { define void @testZeroSizedAlloc() {
%1 = bitcast i8* @runtime.zeroSizedAlloc to i32* %ptr = call ptr @noescapeIntPtr(ptr @runtime.zeroSizedAlloc)
%2 = call i32* @noescapeIntPtr(i32* %1)
ret void ret void
} }
declare i32* @escapeIntPtr(i32*) declare ptr @escapeIntPtr(ptr)
declare i32* @noescapeIntPtr(i32* nocapture) declare ptr @noescapeIntPtr(ptr nocapture)
declare i32* @escapeIntPtrSometimes(i32* nocapture, i32*) declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr)