summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/Coroutines/ex1.ll
diff options
context:
space:
mode:
authorGor Nishanov <GorNishanov@gmail.com>2016-08-24 04:44:35 +0000
committerGor Nishanov <GorNishanov@gmail.com>2016-08-24 04:44:35 +0000
commit241b041fbad8e776f6eab3644d9679264f762afd (patch)
tree58ed9efd832b16e296d0f838b82a68a5d437173f /llvm/test/Transforms/Coroutines/ex1.ll
parent9c84859075e8dc415cfc012132ffd56c38b730e9 (diff)
downloadbcm5719-llvm-241b041fbad8e776f6eab3644d9679264f762afd.tar.gz
bcm5719-llvm-241b041fbad8e776f6eab3644d9679264f762afd.zip
[Coroutines] Part 8: Coroutine Frame Building algorithm
Summary: This patch adds coroutine frame building algorithm. Now, simple coroutines such as ex0.ll and ex1.ll (first examples from docs\Coroutines.rst can be compiled). Documentation and overview is here: http://llvm.org/docs/Coroutines.html. Upstreaming sequence (rough plan) 1.Add documentation. (https://reviews.llvm.org/D22603) 2.Add coroutine intrinsics. (https://reviews.llvm.org/D22659) ... 7. Split coroutine into subfunctions. (https://reviews.llvm.org/D23461) 8. Coroutine Frame Building algorithm <= we are here 9. Add f.cleanup subfunction. 10+. The rest of the logic Reviewers: majnemer Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D23586 llvm-svn: 279609
Diffstat (limited to 'llvm/test/Transforms/Coroutines/ex1.ll')
-rw-r--r--llvm/test/Transforms/Coroutines/ex1.ll54
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/test/Transforms/Coroutines/ex1.ll b/llvm/test/Transforms/Coroutines/ex1.ll
new file mode 100644
index 00000000000..942dbe558a3
--- /dev/null
+++ b/llvm/test/Transforms/Coroutines/ex1.ll
@@ -0,0 +1,54 @@
+; First example from Doc/Coroutines.rst (one block loop)
+; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
+
+define i8* @f(i32 %n) {
+entry:
+ %id = call token @llvm.coro.id(i32 0, i8* null, i8* null)
+ %size = call i32 @llvm.coro.size.i32()
+ %alloc = call i8* @malloc(i32 %size)
+ %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
+ br label %loop
+loop:
+ %n.val = phi i32 [ %n, %entry ], [ %inc, %loop ]
+ %inc = add nsw i32 %n.val, 1
+ call void @print(i32 %n.val)
+ %0 = call i8 @llvm.coro.suspend(token none, i1 false)
+ switch i8 %0, label %suspend [i8 0, label %loop
+ i8 1, label %cleanup]
+cleanup:
+ %mem = call i8* @llvm.coro.free(i8* %hdl)
+ call void @free(i8* %mem)
+ br label %suspend
+suspend:
+ call void @llvm.coro.end(i8* %hdl, i1 false)
+ ret i8* %hdl
+}
+
+; CHECK-LABEL: @main(
+define i32 @main() {
+entry:
+ %hdl = call i8* @f(i32 4)
+ call void @llvm.coro.resume(i8* %hdl)
+ call void @llvm.coro.resume(i8* %hdl)
+ call void @llvm.coro.destroy(i8* %hdl)
+ ret i32 0
+; CHECK-NEXT: entry:
+; CHECK: call void @print(i32 4)
+; CHECK: call void @print(i32 5)
+; CHECK: call void @print(i32 6)
+; CHECK: ret i32 0
+}
+
+declare i8* @malloc(i32)
+declare void @free(i8*)
+declare void @print(i32)
+
+declare token @llvm.coro.id(i32, i8*, i8*)
+declare i32 @llvm.coro.size.i32()
+declare i8* @llvm.coro.begin(token, i8*)
+declare i8 @llvm.coro.suspend(token, i1)
+declare i8* @llvm.coro.free(i8*)
+declare void @llvm.coro.end(i8*, i1)
+
+declare void @llvm.coro.resume(i8*)
+declare void @llvm.coro.destroy(i8*)
OpenPOWER on IntegriCloud