@@ -395,24 +395,17 @@ class YkIRWriter {
395
395
InstIdx++;
396
396
}
397
397
398
- void serialiseDeoptSafepointInst (CallInst *I, ValueLoweringMap &VLMap,
399
- unsigned BBIdx, unsigned &InstIdx) {
400
- serialiseOpcode (OpCodeDeoptSafepoint);
398
+ void serialiseStackmapCall (CallInst *I, ValueLoweringMap &VLMap) {
401
399
// stackmap ID:
402
400
serialiseOperand (I, VLMap, I->getOperand (0 ));
403
401
404
- // num_shadow_bytes:
405
- serialiseOperand (I, VLMap, I->getOperand (1 ));
406
-
407
402
// num_lives:
408
403
OutStreamer.emitInt32 (I->arg_size () - 2 );
409
404
410
405
// lives:
411
406
for (unsigned OI = 2 ; OI < I->arg_size (); OI++) {
412
407
serialiseOperand (I, VLMap, I->getOperand (OI));
413
408
}
414
- InstIdx++;
415
- return ;
416
409
}
417
410
418
411
void serialiseCallInst (CallInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
@@ -430,6 +423,13 @@ class YkIRWriter {
430
423
return ;
431
424
}
432
425
426
+ // Stackmap calls are serialised on-demand by folding them into the `call`
427
+ // or `condbr` instruction which they belong to.
428
+ if (I->getCalledFunction ()->isIntrinsic () &&
429
+ I->getIntrinsicID () == Intrinsic::experimental_stackmap) {
430
+ return ;
431
+ }
432
+
433
433
// FIXME: indirect calls.
434
434
//
435
435
// Note that this assertion can also fail if you do a direct call without
@@ -448,13 +448,6 @@ class YkIRWriter {
448
448
// call i32 (i32, ...) @f(1i32, 2i32);
449
449
assert (I->getCalledFunction ());
450
450
451
- // special case for llvm.experimental.stackmap intrinsic.
452
- if (I->getCalledFunction ()->isIntrinsic () &&
453
- I->getIntrinsicID () == Intrinsic::experimental_stackmap) {
454
- serialiseDeoptSafepointInst (I, VLMap, BBIdx, InstIdx);
455
- return ;
456
- }
457
-
458
451
serialiseOpcode (OpCodeCall);
459
452
// callee:
460
453
OutStreamer.emitSizeT (functionIndex (I->getCalledFunction ()));
@@ -465,6 +458,19 @@ class YkIRWriter {
465
458
for (unsigned OI = 0 ; OI < I->arg_size (); OI++) {
466
459
serialiseOperand (I, VLMap, I->getOperand (OI));
467
460
}
461
+ if (!I->getCalledFunction ()->isDeclaration ()) {
462
+ // The next instruction will be the stackmap entry
463
+ CallInst *SMI = dyn_cast<CallInst>(I->getNextNonDebugInstruction ());
464
+ assert (SMI);
465
+ assert (SMI->getCalledFunction ()->isIntrinsic ());
466
+ assert (SMI->getIntrinsicID () == Intrinsic::experimental_stackmap);
467
+ // has_safepoint = 1:
468
+ OutStreamer.emitInt8 (1 );
469
+ serialiseStackmapCall (SMI, VLMap);
470
+ } else {
471
+ // has_safepoint = 0:
472
+ OutStreamer.emitInt8 (0 );
473
+ }
468
474
469
475
// If the return type is non-void, then this defines a local.
470
476
if (!I->getType ()->isVoidTy ()) {
@@ -497,6 +503,12 @@ class YkIRWriter {
497
503
serialiseBlockLabel (I->getSuccessor (0 ));
498
504
// false_bb:
499
505
serialiseBlockLabel (I->getSuccessor (1 ));
506
+
507
+ CallInst *SMI = dyn_cast<CallInst>(I->getPrevNonDebugInstruction ());
508
+ assert (SMI);
509
+ assert (SMI->getCalledFunction ()->isIntrinsic ());
510
+ assert (SMI->getIntrinsicID () == Intrinsic::experimental_stackmap);
511
+ serialiseStackmapCall (SMI, VLMap);
500
512
}
501
513
InstIdx++;
502
514
}
0 commit comments