[PATCH] D30376: Playing with tokens OR breaking coroutines manually

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 25 02:39:36 PST 2017


jdoerfert created this revision.
Herald added subscribers: EricWF, mehdi_amini.

  After "breaking"* the coroutine code manually:
    - 4 of 6 tests pass,
    - one performs differently than expected and therefor fails, and
    - one crashes with a weird assumptions
  
  All in all it seems the tests/verifier could be more rigorous to
  identify broken input.

- I am not a coroutines expert, I was merely playing around with tokens to see what kind of "transformation" they prevent in this setting. While I think the code is broken it might actually be well defined.


https://reviews.llvm.org/D30376

Files:
  test/Transforms/Coroutines/ex0.ll
  test/Transforms/Coroutines/ex1.ll
  test/Transforms/Coroutines/ex2.ll
  test/Transforms/Coroutines/ex3.ll
  test/Transforms/Coroutines/ex4.ll
  test/Transforms/Coroutines/ex5.ll


Index: test/Transforms/Coroutines/ex5.ll
===================================================================
--- test/Transforms/Coroutines/ex5.ll
+++ test/Transforms/Coroutines/ex5.ll
@@ -4,6 +4,7 @@
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
+  %id2 = call token @llvm.coro.id(i32 0, i8* null, 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)
@@ -27,7 +28,7 @@
   call void @llvm.trap()
   unreachable
 cleanup:
-  %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
+  %mem = call i8* @llvm.coro.free(token %id2, i8* %hdl)
   call void @free(i8* %mem)
   br label %suspend
 suspend:
Index: test/Transforms/Coroutines/ex4.ll
===================================================================
--- test/Transforms/Coroutines/ex4.ll
+++ test/Transforms/Coroutines/ex4.ll
@@ -6,14 +6,17 @@
   %promise = alloca i32
   %pv = bitcast i32* %promise to i8*
   %id = call token @llvm.coro.id(i32 0, i8* %pv, i8* null, i8* null)
+  %cmp = icmp slt i32 %n, 12932
+  br i1 %cmp, label %allo, label %dyn.alloc
+allo:
   %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
   br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
 dyn.alloc:
   %size = call i32 @llvm.coro.size.i32()
   %alloc = call i8* @malloc(i32 %size)
   br label %coro.begin
 coro.begin:
-  %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
+  %phi = phi i8* [ null, %allo ], [ %alloc, %dyn.alloc ]
   %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %phi)
   br label %loop
 loop:
Index: test/Transforms/Coroutines/ex3.ll
===================================================================
--- test/Transforms/Coroutines/ex3.ll
+++ test/Transforms/Coroutines/ex3.ll
@@ -22,6 +22,9 @@
   switch i8 %1, label %suspend [i8 0, label %loop
                                 i8 1, label %cleanup]
 cleanup:
+  %cmp = icmp slt i32 %n, 12932
+  br i1 %cmp, label %free, label %suspend
+free:
   %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
   call void @free(i8* %mem)
   br label %suspend
Index: test/Transforms/Coroutines/ex2.ll
===================================================================
--- test/Transforms/Coroutines/ex2.ll
+++ test/Transforms/Coroutines/ex2.ll
@@ -4,7 +4,8 @@
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
-  %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
+  %id2 = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
+  %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id2)
   br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
 dyn.alloc:
   %size = call i32 @llvm.coro.size.i32()
Index: test/Transforms/Coroutines/ex1.ll
===================================================================
--- test/Transforms/Coroutines/ex1.ll
+++ test/Transforms/Coroutines/ex1.ll
@@ -6,7 +6,7 @@
   %id = call token @llvm.coro.id(i32 0, i8* null, 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)
+  %hdl = call noalias i8* @malloc(i32 %size)
   br label %loop
 loop:
   %n.val = phi i32 [ %n, %entry ], [ %inc, %loop ]
Index: test/Transforms/Coroutines/ex0.ll
===================================================================
--- test/Transforms/Coroutines/ex0.ll
+++ test/Transforms/Coroutines/ex0.ll
@@ -20,8 +20,7 @@
   br label %loop
 
 cleanup:
-  %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
-  call void @free(i8* %mem)
+  call void @free(i8* null)
   br label %suspend
 suspend:
   call void @llvm.coro.end(i8* %hdl, i1 0)  


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30376.89781.patch
Type: text/x-patch
Size: 3730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170225/b3d0ac21/attachment.bin>


More information about the llvm-commits mailing list