@@ -396,24 +396,17 @@ class YkIRWriter {
396396 InstIdx++;
397397 }
398398
399- void serialiseDeoptSafepointInst (CallInst *I, ValueLoweringMap &VLMap,
400- unsigned BBIdx, unsigned &InstIdx) {
401- serialiseOpcode (OpCodeDeoptSafepoint);
399+ void serialiseStackmapCall (CallInst *I, ValueLoweringMap &VLMap) {
402400 // stackmap ID:
403401 serialiseOperand (I, VLMap, I->getOperand (0 ));
404402
405- // num_shadow_bytes:
406- serialiseOperand (I, VLMap, I->getOperand (1 ));
407-
408403 // num_lives:
409404 OutStreamer.emitInt32 (I->arg_size () - 2 );
410405
411406 // lives:
412407 for (unsigned OI = 2 ; OI < I->arg_size (); OI++) {
413408 serialiseOperand (I, VLMap, I->getOperand (OI));
414409 }
415- InstIdx++;
416- return ;
417410 }
418411
419412 void serialiseCallInst (CallInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
@@ -431,6 +424,13 @@ class YkIRWriter {
431424 return ;
432425 }
433426
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+
434434 // FIXME: indirect calls.
435435 //
436436 // Note that this assertion can also fail if you do a direct call without
@@ -449,13 +449,6 @@ class YkIRWriter {
449449 // call i32 (i32, ...) @f(1i32, 2i32);
450450 assert (I->getCalledFunction ());
451451
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-
459452 serialiseOpcode (OpCodeCall);
460453 // callee:
461454 OutStreamer.emitSizeT (functionIndex (I->getCalledFunction ()));
@@ -466,6 +459,19 @@ class YkIRWriter {
466459 for (unsigned OI = 0 ; OI < I->arg_size (); OI++) {
467460 serialiseOperand (I, VLMap, I->getOperand (OI));
468461 }
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+ }
469475
470476 // If the return type is non-void, then this defines a local.
471477 if (!I->getType ()->isVoidTy ()) {
@@ -498,6 +504,12 @@ class YkIRWriter {
498504 serialiseBlockLabel (I->getSuccessor (0 ));
499505 // false_bb:
500506 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);
501513 }
502514 InstIdx++;
503515 }
0 commit comments