brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 6a80f36 Raw
60 lines · plain
1; Check that the return value of @llvm.coro.suspend gets spilled to the frame2; if it may be used across suspend points.3; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s4 5 6; %sp1 should be part of the frame (the i8 value).7; CHECK: %f.Frame = type { ptr, ptr, i1, i8 }8 9; If the coro resumes, %sp1 is set to 0.10; CHECK-LABEL: define{{.*}} void @f.resume11; CHECK: AfterCoroSuspend:12; CHECK: %sp1.spill.addr = getelementptr inbounds %f.Frame13; CHECK: store i8 0, ptr %sp1.spill.addr14 15; In the coro destroy function, %sp1 is reloaded from the frame. Its value16; depends on whether the coroutine was resumed or not.17; CHECK-LABEL: define{{.*}} void @f.destroy18; CHECK: cleanup:19; CHECK: %sp1.reload.addr = getelementptr inbounds %f.Frame20; CHECK: %sp1.reload = load i8, ptr %sp1.reload.addr21; CHECK: call void @print(i8 %sp1.reload)22 23 24define ptr @f(i32 %n) presplitcoroutine {25entry:26  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)27  %size = call i32 @llvm.coro.size.i32()28  %alloc = call ptr @malloc(i32 %size)29  %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)30 31  %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)32  switch i8 %sp1, label %suspend [i8 0, label %resume133                                  i8 1, label %cleanup]34 35resume1:36  %sp2 = call i8 @llvm.coro.suspend(token none, i1 false)37  switch i8 %sp2, label %suspend [i8 0, label %resume238                                  i8 1, label %cleanup]39 40resume2:41  br label %cleanup42 43cleanup:44  ; This use of %sp1 may cross a suspend point (%sp2).45  call void @print(i8 %sp1)46 47  %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)48  call void @free(ptr %mem)49  br label %suspend50 51suspend:52  call void @llvm.coro.end(ptr %hdl, i1 0, token none)53  ret ptr %hdl54}55 56 57declare noalias ptr @malloc(i32)58declare void @print(i8)59declare void @free(ptr)60