@@ -41,17 +41,17 @@ func (b *builder) createChanSend(instr *ssa.Send) {
41
41
b .CreateStore (chanValue , valueAlloca )
42
42
}
43
43
44
- // Allocate blockedlist buffer.
45
- channelBlockedList := b .getLLVMRuntimeType ("channelBlockedList " )
46
- channelBlockedListAlloca , channelBlockedListAllocaSize := b .createTemporaryAlloca (channelBlockedList , "chan.blockedList " )
44
+ // Allocate buffer for the channel operation .
45
+ channelOp := b .getLLVMRuntimeType ("channelOp " )
46
+ channelOpAlloca , channelOpAllocaSize := b .createTemporaryAlloca (channelOp , "chan.op " )
47
47
48
48
// Do the send.
49
- b .createRuntimeCall ("chanSend" , []llvm.Value {ch , valueAlloca , channelBlockedListAlloca }, "" )
49
+ b .createRuntimeCall ("chanSend" , []llvm.Value {ch , valueAlloca , channelOpAlloca }, "" )
50
50
51
51
// End the lifetime of the allocas.
52
52
// This also works around a bug in CoroSplit, at least in LLVM 8:
53
53
// https://bugs.llvm.org/show_bug.cgi?id=41742
54
- b .emitLifetimeEnd (channelBlockedListAlloca , channelBlockedListAllocaSize )
54
+ b .emitLifetimeEnd (channelOpAlloca , channelOpAllocaSize )
55
55
if ! isZeroSize {
56
56
b .emitLifetimeEnd (valueAlloca , valueAllocaSize )
57
57
}
@@ -72,20 +72,20 @@ func (b *builder) createChanRecv(unop *ssa.UnOp) llvm.Value {
72
72
valueAlloca , valueAllocaSize = b .createTemporaryAlloca (valueType , "chan.value" )
73
73
}
74
74
75
- // Allocate blockedlist buffer.
76
- channelBlockedList := b .getLLVMRuntimeType ("channelBlockedList " )
77
- channelBlockedListAlloca , channelBlockedListAllocaSize := b .createTemporaryAlloca (channelBlockedList , "chan.blockedList " )
75
+ // Allocate buffer for the channel operation .
76
+ channelOp := b .getLLVMRuntimeType ("channelOp " )
77
+ channelOpAlloca , channelOpAllocaSize := b .createTemporaryAlloca (channelOp , "chan.op " )
78
78
79
79
// Do the receive.
80
- commaOk := b .createRuntimeCall ("chanRecv" , []llvm.Value {ch , valueAlloca , channelBlockedListAlloca }, "" )
80
+ commaOk := b .createRuntimeCall ("chanRecv" , []llvm.Value {ch , valueAlloca , channelOpAlloca }, "" )
81
81
var received llvm.Value
82
82
if isZeroSize {
83
83
received = llvm .ConstNull (valueType )
84
84
} else {
85
85
received = b .CreateLoad (valueType , valueAlloca , "chan.received" )
86
86
b .emitLifetimeEnd (valueAlloca , valueAllocaSize )
87
87
}
88
- b .emitLifetimeEnd (channelBlockedListAlloca , channelBlockedListAllocaSize )
88
+ b .emitLifetimeEnd (channelOpAlloca , channelOpAllocaSize )
89
89
90
90
if unop .CommaOk {
91
91
tuple := llvm .Undef (b .ctx .StructType ([]llvm.Type {valueType , b .ctx .Int1Type ()}, false ))
@@ -198,26 +198,29 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value {
198
198
if expr .Blocking {
199
199
// Stack-allocate operation structures.
200
200
// If these were simply created as a slice, they would heap-allocate.
201
- chBlockAllocaType := llvm .ArrayType (b .getLLVMRuntimeType ("channelBlockedList " ), len (selectStates ))
202
- chBlockAlloca , chBlockSize := b .createTemporaryAlloca (chBlockAllocaType , "select.block.alloca" )
203
- chBlockLen := llvm .ConstInt (b .uintptrType , uint64 (len (selectStates )), false )
204
- chBlockPtr := b .CreateGEP (chBlockAllocaType , chBlockAlloca , []llvm.Value {
201
+ opsAllocaType := llvm .ArrayType (b .getLLVMRuntimeType ("channelOp " ), len (selectStates ))
202
+ opsAlloca , opsSize := b .createTemporaryAlloca (opsAllocaType , "select.block.alloca" )
203
+ opsLen := llvm .ConstInt (b .uintptrType , uint64 (len (selectStates )), false )
204
+ opsPtr := b .CreateGEP (opsAllocaType , opsAlloca , []llvm.Value {
205
205
llvm .ConstInt (b .ctx .Int32Type (), 0 , false ),
206
206
llvm .ConstInt (b .ctx .Int32Type (), 0 , false ),
207
207
}, "select.block" )
208
208
209
209
results = b .createRuntimeCall ("chanSelect" , []llvm.Value {
210
210
recvbuf ,
211
211
statesPtr , statesLen , statesLen , // []chanSelectState
212
- chBlockPtr , chBlockLen , chBlockLen , // []channelBlockList
212
+ opsPtr , opsLen , opsLen , // []channelOp
213
213
}, "select.result" )
214
214
215
215
// Terminate the lifetime of the operation structures.
216
- b .emitLifetimeEnd (chBlockAlloca , chBlockSize )
216
+ b .emitLifetimeEnd (opsAlloca , opsSize )
217
217
} else {
218
- results = b .createRuntimeCall ("tryChanSelect" , []llvm.Value {
218
+ opsPtr := llvm .ConstNull (b .dataPtrType )
219
+ opsLen := llvm .ConstInt (b .uintptrType , 0 , false )
220
+ results = b .createRuntimeCall ("chanSelect" , []llvm.Value {
219
221
recvbuf ,
220
222
statesPtr , statesLen , statesLen , // []chanSelectState
223
+ opsPtr , opsLen , opsLen , // []channelOp (nil slice)
221
224
}, "select.result" )
222
225
}
223
226
0 commit comments