Skip to content

Commit d885f26

Browse files
authored
Merge pull request rust-lang#151 from ptersilie/indirect_calls
Serialise indirect calls.
2 parents d0314d6 + 94b851a commit d885f26

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum OpCode {
5353
OpCodeCast,
5454
OpCodeSwitch,
5555
OpCodePHI,
56+
OpCodeIndirectCall,
5657
OpCodeUnimplemented = 255, // YKFIXME: Will eventually be deleted.
5758
};
5859

@@ -479,6 +480,29 @@ class YkIRWriter {
479480
}
480481
}
481482

483+
void serialiseIndirectCallInst(CallInst *I, FuncLowerCtxt &FLCtxt,
484+
unsigned BBIdx, unsigned &InstIdx) {
485+
486+
serialiseOpcode(OpCodeIndirectCall);
487+
// function type:
488+
OutStreamer.emitSizeT(typeIndex(I->getFunctionType()));
489+
// callee (operand):
490+
serialiseOperand(I, FLCtxt, I->getCalledOperand());
491+
// num_args:
492+
// (this includes static and varargs arguments)
493+
OutStreamer.emitInt32(I->arg_size());
494+
// args:
495+
for (unsigned OI = 0; OI < I->arg_size(); OI++) {
496+
serialiseOperand(I, FLCtxt, I->getOperand(OI));
497+
}
498+
499+
// If the return type is non-void, then this defines a local.
500+
if (!I->getType()->isVoidTy()) {
501+
FLCtxt.updateVLMap(I, InstIdx);
502+
}
503+
InstIdx++;
504+
}
505+
482506
void serialiseCallInst(CallInst *I, FuncLowerCtxt &FLCtxt, unsigned BBIdx,
483507
unsigned &InstIdx) {
484508
if (I->isInlineAsm()) {
@@ -494,16 +518,19 @@ class YkIRWriter {
494518
return;
495519
}
496520

521+
if (I->isIndirectCall()) {
522+
serialiseIndirectCallInst(I, FLCtxt, BBIdx, InstIdx);
523+
return;
524+
}
525+
497526
// Stackmap calls are serialised on-demand by folding them into the `call`
498527
// or `condbr` instruction which they belong to.
499528
if (I->getCalledFunction()->isIntrinsic() &&
500529
I->getIntrinsicID() == Intrinsic::experimental_stackmap) {
501530
return;
502531
}
503532

504-
// FIXME: indirect calls.
505-
//
506-
// Note that this assertion can also fail if you do a direct call without
533+
// FIXME: Note that this assertion can fail if you do a direct call without
507534
// the correct type annotation at the call site.
508535
//
509536
// e.g. for a functiion:

0 commit comments

Comments
 (0)