Skip to content

Commit 5f5eed0

Browse files
committed
For call instructions, make the callee the first operand.
1 parent bf8f182 commit 5f5eed0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ class YkIRWriter {
239239
InstIdx++;
240240
}
241241

242+
void serialiseCallInst(CallInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
243+
unsigned InstIdx) {
244+
// type_index:
245+
OutStreamer.emitSizeT(typeIndex(I->getType()));
246+
// opcode:
247+
serialiseOpcode(OpCode::Call);
248+
// num_operands:
249+
unsigned NumOpers = I->getNumOperands();
250+
OutStreamer.emitInt32(NumOpers);
251+
252+
// OPERAND 0: What to call.
253+
//
254+
// In LLVM IR this is the final operand, which is a cause of confusion.
255+
serialiseOperand(I, VLMap, I->getOperand(NumOpers - 1));
256+
257+
// Now the rest of the operands.
258+
for (unsigned OI = 0; OI < NumOpers - 1; OI++) {
259+
serialiseOperand(I, VLMap, I->getOperand(OI));
260+
}
261+
262+
VLMap[I] = {BBIdx, InstIdx};
263+
InstIdx++;
264+
}
265+
242266
void serialiseInst(Instruction *I, ValueLoweringMap &VLMap, unsigned BBIdx,
243267
unsigned &InstIdx) {
244268
// Macros to help dispatch to serialisers.
@@ -257,14 +281,14 @@ class YkIRWriter {
257281

258282
GENERIC_INST_SERIALISE(I, LoadInst, Load)
259283
GENERIC_INST_SERIALISE(I, StoreInst, Store)
260-
GENERIC_INST_SERIALISE(I, CallInst, Call)
261284
GENERIC_INST_SERIALISE(I, GetElementPtrInst, GetElementPtr)
262285
GENERIC_INST_SERIALISE(I, BranchInst, Branch)
263286
GENERIC_INST_SERIALISE(I, ICmpInst, ICmp)
264287
GENERIC_INST_SERIALISE(I, llvm::BinaryOperator, BinaryOperator)
265288
GENERIC_INST_SERIALISE(I, ReturnInst, Ret)
266289

267290
CUSTOM_INST_SERIALISE(I, AllocaInst, serialiseAllocaInst)
291+
CUSTOM_INST_SERIALISE(I, CallInst, serialiseCallInst)
268292

269293
// GENERIC_INST_SERIALISE and CUSTOM_INST_SERIALISE do an early return upon
270294
// a match, so if we get here then the instruction wasn't handled.

0 commit comments

Comments
 (0)