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