@@ -39,13 +39,13 @@ enum OpCode {
39
39
Store,
40
40
Alloca,
41
41
Call,
42
- GetElementPtr,
43
42
Br,
44
43
CondBr,
45
44
ICmp,
46
45
BinaryOperator,
47
46
Ret,
48
47
InsertValue,
48
+ PtrAdd,
49
49
UnimplementedInstruction = 255 , // YKFIXME: Will eventually be deleted.
50
50
};
51
51
@@ -124,6 +124,7 @@ class YkIRWriter {
124
124
private:
125
125
Module &M;
126
126
MCStreamer &OutStreamer;
127
+ DataLayout DL;
127
128
128
129
vector<llvm::Type *> Types;
129
130
vector<llvm::Constant *> Constants;
@@ -326,6 +327,40 @@ class YkIRWriter {
326
327
}
327
328
}
328
329
330
+ void serialiseGetElementPtr (GetElementPtrInst *I, ValueLoweringMap &VLMap,
331
+ unsigned BBIdx, unsigned &InstIdx) {
332
+ unsigned BitWidth = 64 ;
333
+ MapVector<Value *, APInt> Offsets;
334
+ APInt Offset (BitWidth, 0 );
335
+
336
+ bool Res = I->collectOffset (DL, BitWidth, Offsets, Offset);
337
+ assert (Res);
338
+
339
+ // type_index:
340
+ OutStreamer.emitSizeT (typeIndex (I->getType ()));
341
+ // opcode:
342
+ serialiseOpcode (OpCode::PtrAdd);
343
+ // num_operands:
344
+ OutStreamer.emitInt32 (2 );
345
+ // pointer:
346
+ serialiseOperand (I, VLMap, I->getPointerOperand ());
347
+ // offset:
348
+ serialiseOperand (I, VLMap, ConstantInt::get (I->getContext (), Offset));
349
+
350
+ VLMap[I] = {BBIdx, InstIdx};
351
+ InstIdx++;
352
+ }
353
+
354
+ void serialiseStore (StoreInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
355
+ unsigned &InstIdx)
356
+ {
357
+ if (I->getNumOperands () == 2 ) {
358
+ serialiseInstGeneric (I, VLMap, BBIdx, InstIdx, OpCode::Store);
359
+ } else {
360
+ serialiseUnimplementedInstruction (I, VLMap, BBIdx, InstIdx);
361
+ }
362
+ }
363
+
329
364
void serialiseInst (Instruction *I, ValueLoweringMap &VLMap, unsigned BBIdx,
330
365
unsigned &InstIdx) {
331
366
// Macros to help dispatch to serialisers.
@@ -344,7 +379,6 @@ class YkIRWriter {
344
379
345
380
GENERIC_INST_SERIALISE (I, LoadInst, Load)
346
381
GENERIC_INST_SERIALISE (I, StoreInst, Store)
347
- GENERIC_INST_SERIALISE (I, GetElementPtrInst, GetElementPtr)
348
382
GENERIC_INST_SERIALISE (I, ICmpInst, ICmp)
349
383
GENERIC_INST_SERIALISE (I, llvm::BinaryOperator, BinaryOperator)
350
384
GENERIC_INST_SERIALISE (I, ReturnInst, Ret)
@@ -353,6 +387,8 @@ class YkIRWriter {
353
387
CUSTOM_INST_SERIALISE (I, AllocaInst, serialiseAllocaInst)
354
388
CUSTOM_INST_SERIALISE (I, CallInst, serialiseCallInst)
355
389
CUSTOM_INST_SERIALISE (I, BranchInst, serialiseBranchInst)
390
+ CUSTOM_INST_SERIALISE (I, GetElementPtrInst, serialiseGetElementPtr)
391
+ CUSTOM_INST_SERIALISE (I, StoreInst, serialiseStore)
356
392
357
393
// GENERIC_INST_SERIALISE and CUSTOM_INST_SERIALISE do an early return upon
358
394
// a match, so if we get here then the instruction wasn't handled.
@@ -487,7 +523,7 @@ class YkIRWriter {
487
523
488
524
public:
489
525
YkIRWriter (Module &M, MCStreamer &OutStreamer)
490
- : M(M), OutStreamer(OutStreamer) {}
526
+ : M(M), OutStreamer(OutStreamer), DL(&M) {}
491
527
492
528
// Entry point for IR serialisation.
493
529
//
0 commit comments