@@ -152,16 +152,6 @@ internal interface CodeContext {
152
152
*/
153
153
fun genGetValue (descriptor : ValueDescriptor ): LLVMValueRef
154
154
155
- /* *
156
- * Gets the exit block for the context owned by specified descriptor.
157
- */
158
- fun getExit (descriptor : CallableDescriptor ): LLVMBasicBlockRef
159
-
160
- /* *
161
- * Gets the result value for the context owned by specified descriptor.
162
- */
163
- fun getResult (descriptor : CallableDescriptor ): LLVMValueRef
164
-
165
155
/* *
166
156
* Returns owning function scope.
167
157
*
@@ -208,10 +198,6 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
208
198
209
199
override fun genGetValue (descriptor : ValueDescriptor ) = unsupported(descriptor)
210
200
211
- override fun getExit (descriptor : CallableDescriptor ): LLVMBasicBlockRef = unsupported(descriptor)
212
-
213
- override fun getResult (descriptor : CallableDescriptor ): LLVMValueRef = unsupported(descriptor)
214
-
215
201
override fun functionScope (): CodeContext = unsupported()
216
202
}
217
203
@@ -1395,35 +1381,31 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
1395
1381
var bbExit : LLVMBasicBlockRef ? = null
1396
1382
var resultPhi : LLVMValueRef ? = null
1397
1383
1398
- override fun getExit (descriptor : CallableDescriptor ): LLVMBasicBlockRef {
1399
- if (descriptor != inlineBody.descriptor)
1400
- return super .getExit(descriptor)
1384
+ private fun getExit (): LLVMBasicBlockRef {
1401
1385
if (bbExit == null ) bbExit = codegen.basicBlock(" inline_body_exit" )
1402
1386
return bbExit!!
1403
1387
}
1404
1388
1405
- override fun getResult (descriptor : CallableDescriptor ): LLVMValueRef {
1406
- if (descriptor != inlineBody.descriptor)
1407
- return super .getResult(descriptor)
1389
+ private fun getResult (): LLVMValueRef {
1408
1390
if (resultPhi == null ) {
1409
1391
val bbCurrent = codegen.currentBlock
1410
- codegen.positionAtEnd(getExit(descriptor ))
1392
+ codegen.positionAtEnd(getExit())
1411
1393
resultPhi = codegen.phi(codegen.getLLVMType(inlineBody.type))
1412
1394
codegen.positionAtEnd(bbCurrent)
1413
1395
}
1414
1396
return resultPhi!!
1415
1397
}
1416
1398
1417
1399
override fun genReturn (target : CallableDescriptor , value : LLVMValueRef ? ) {
1418
- if (target == codegen.functionDescriptor ) { // It is "non local return".
1419
- super .genReturn(target, value) // Generate real "return".
1400
+ if (target != inlineBody.descriptor ) { // It is not our " local return".
1401
+ super .genReturn(target, value)
1420
1402
return
1421
1403
}
1422
- // It is local return.
1423
- codegen.br(getExit(target) !! ) // Generate branch on exit block.
1404
+ // It is local return from current function .
1405
+ codegen.br(getExit()) // Generate branch on exit block.
1424
1406
1425
1407
if (! KotlinBuiltIns .isUnit(inlineBody.type)) { // If function returns more then "unit"
1426
- codegen.assignPhis(getResult(target ) to value!! ) // Assign return value to result PHI node.
1408
+ codegen.assignPhis(getResult() to value!! ) // Assign return value to result PHI node.
1427
1409
}
1428
1410
}
1429
1411
}
@@ -1442,22 +1424,19 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
1442
1424
}
1443
1425
}
1444
1426
1445
- if (inlinedFunctionScope.bbExit != null ) {
1427
+ val bbExit = inlinedFunctionScope.bbExit
1428
+ if (bbExit != null ) {
1446
1429
if (! codegen.isAfterTerminator()) { // TODO should we solve this problem once and for all
1447
1430
if (inlinedFunctionScope.resultPhi != null ) {
1448
1431
codegen.unreachable()
1449
1432
} else {
1450
- codegen.br(inlinedFunctionScope. bbExit!! )
1433
+ codegen.br(bbExit)
1451
1434
}
1452
1435
}
1453
- codegen.positionAtEnd(inlinedFunctionScope. bbExit!! )
1436
+ codegen.positionAtEnd(bbExit)
1454
1437
}
1455
1438
1456
- if (inlinedFunctionScope.resultPhi != null ) {
1457
- return inlinedFunctionScope.resultPhi!!
1458
- } else {
1459
- return codegen.theUnitInstanceRef.llvm
1460
- }
1439
+ return inlinedFunctionScope.resultPhi ? : codegen.theUnitInstanceRef.llvm
1461
1440
}
1462
1441
1463
1442
// -------------------------------------------------------------------------//
0 commit comments