-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Add support for __builtin_alloca #157116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,10 @@ void unreachable() { | |
| // LLVM: unreachable | ||
| // LLVM: } | ||
|
|
||
| // OGCG-LABEL: @_Z11unreachablev | ||
| // OGCG: unreachable | ||
| // OGCG: } | ||
|
|
||
| void f1(); | ||
| void unreachable2() { | ||
| __builtin_unreachable(); | ||
|
|
@@ -229,6 +233,9 @@ void unreachable2() { | |
| // LLVM-NEXT: call void @_Z2f1v() | ||
| // LLVM: } | ||
|
|
||
| // OGCG-LABEL: @_Z12unreachable2v | ||
| // OGCG: unreachable | ||
|
|
||
| void trap() { | ||
| __builtin_trap(); | ||
| } | ||
|
|
@@ -241,6 +248,10 @@ void trap() { | |
| // LLVM: call void @llvm.trap() | ||
| // LLVM: } | ||
|
|
||
| // OGCG-LABEL: @_Z4trapv | ||
| // OGCG: call void @llvm.trap() | ||
| // OGCG: } | ||
|
|
||
| void trap2() { | ||
| __builtin_trap(); | ||
| f1(); | ||
|
|
@@ -258,3 +269,40 @@ void trap2() { | |
| // LLVM: {{.+}}: | ||
| // LLVM-NEXT: call void @_Z2f1v() | ||
| // LLVM: } | ||
|
|
||
| // OGCG-LABEL: define{{.*}} void @_Z5trap2v | ||
| // OGCG: call void @llvm.trap() | ||
| // OGCG-NEXT: call void @_Z2f1v() | ||
| // OGCG: ret void | ||
| // OGCG: } | ||
|
|
||
| void *test_alloca(unsigned long n) { | ||
| return __builtin_alloca(n); | ||
| } | ||
|
|
||
| // CIR-LABEL: @_Z11test_allocam( | ||
| // CIR: %{{.+}} = cir.alloca !u8i, !cir.ptr<!u8i>, %{{.+}} : !u64i, ["bi_alloca"] | ||
|
|
||
| // LLVM-LABEL: @_Z11test_allocam( | ||
|
||
| // LLVM: alloca i8, i64 %{{.+}} | ||
|
|
||
| // OGCG-LABEL: @_Z11test_allocam( | ||
| // OGCG: alloca i8, i64 %{{.+}} | ||
|
|
||
| bool test_multiple_allocas(unsigned long n) { | ||
| void *a = __builtin_alloca(n); | ||
| void *b = __builtin_alloca(n); | ||
| return a != b; | ||
| } | ||
|
|
||
| // CIR-LABEL: @_Z21test_multiple_allocasm( | ||
| // CIR: %{{.+}} = cir.alloca !u8i, !cir.ptr<!u8i>, %{{.+}} : !u64i, ["bi_alloca"] | ||
| // CIR: %{{.+}} = cir.alloca !u8i, !cir.ptr<!u8i>, %{{.+}} : !u64i, ["bi_alloca"] | ||
|
|
||
| // LLVM-LABEL: @_Z21test_multiple_allocasm( | ||
| // LLVM: alloca i8, i64 %{{.+}} | ||
| // LLVM: alloca i8, i64 %{{.+}} | ||
|
|
||
| // OGCG-LABEL: @_Z21test_multiple_allocasm( | ||
| // OGCG: alloca i8, i64 %{{.+}} | ||
| // OGCG: alloca i8, i64 %{{.+}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
|
|
||
| // RUN: cir-opt %s | FileCheck %s | ||
|
|
||
| !u64i = !cir.int<u, 64> | ||
| !u8i = !cir.int<u, 8> | ||
| !void = !cir.void | ||
| module { | ||
| cir.func dso_local @_Z11test_allocam(%arg0: !u64i) -> !cir.ptr<!void> { | ||
| %0 = cir.alloca !u64i, !cir.ptr<!u64i>, ["n", init] {alignment = 8 : i64} | ||
| %1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["__retval"] {alignment = 8 : i64} | ||
| cir.store %arg0, %0 : !u64i, !cir.ptr<!u64i> | ||
| %2 = cir.load align(8) %0 : !cir.ptr<!u64i>, !u64i | ||
| // Dynamically sized alloca | ||
| %3 = cir.alloca !u8i, !cir.ptr<!u8i>, %2 : !u64i, ["bi_alloca"] {alignment = 16 : i64} | ||
| %4 = cir.cast(bitcast, %3 : !cir.ptr<!u8i>), !cir.ptr<!void> | ||
| cir.store %4, %1 : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| %5 = cir.load %1 : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> | ||
| cir.return %5 : !cir.ptr<!void> | ||
| } | ||
|
|
||
| // CHECK: cir.func dso_local @_Z11test_allocam(%arg0: !u64i) -> !cir.ptr<!void> { | ||
| // CHECK: %0 = cir.alloca !u64i, !cir.ptr<!u64i>, ["n", init] {alignment = 8 : i64} | ||
| // CHECK: %1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["__retval"] {alignment = 8 : i64} | ||
| // CHECK: cir.store %arg0, %0 : !u64i, !cir.ptr<!u64i> | ||
| // CHECK: %2 = cir.load align(8) %0 : !cir.ptr<!u64i>, !u64i | ||
| // CHECK: %3 = cir.alloca !u8i, !cir.ptr<!u8i>, %2 : !u64i, ["bi_alloca"] {alignment = 16 : i64} | ||
| // CHECK: %4 = cir.cast(bitcast, %3 : !cir.ptr<!u8i>), !cir.ptr<!void> | ||
| // CHECK: cir.store %4, %1 : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // CHECK: %5 = cir.load %1 : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> | ||
| // CHECK: cir.return %5 : !cir.ptr<!void> | ||
| // CHECK: } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.