@@ -143,6 +143,19 @@ struct IRNameHintDecoration : IRDecoration
143
143
}
144
144
};
145
145
146
+ // / A decoration on a RTTIObject providing type size information.
147
+ struct IRRTTITypeSizeDecoration : IRDecoration
148
+ {
149
+ enum { kOp = kIROp_RTTITypeSizeDecoration };
150
+ IR_LEAF_ISA (RTTITypeSizeDecoration)
151
+
152
+ IRIntLit* getTypeSizeOperand () { return cast<IRIntLit>(getOperand (0 )); }
153
+ IRIntegerValue getTypeSize ()
154
+ {
155
+ return getTypeSizeOperand ()->getValue ();
156
+ }
157
+ };
158
+
146
159
#define IR_SIMPLE_DECORATION (NAME ) \
147
160
struct IR ##NAME : IRDecoration \
148
161
{ \
@@ -420,6 +433,26 @@ struct IRLookupWitnessTable : IRInst
420
433
IRUse interfaceType;
421
434
};
422
435
436
+ // / Allocates space from local stack.
437
+ // /
438
+ struct IRAlloca : IRInst
439
+ {
440
+ IR_LEAF_ISA (Alloca)
441
+
442
+ IRInst* getAllocSize () { return getOperand (0 ); }
443
+ };
444
+
445
+ // / Copies `size` bytes from `src` to `dst`.
446
+ // /
447
+ struct IRCopy : IRInst
448
+ {
449
+ IR_LEAF_ISA (Copy)
450
+
451
+ IRInst* getDst () { return getOperand (0 ); }
452
+ IRInst* getSrc () { return getOperand (1 ); }
453
+ IRInst* getSize () { return getOperand (2 ); }
454
+ };
455
+
423
456
// Layout decorations
424
457
425
458
// / A decoration that marks a field key as having been associated
@@ -1122,12 +1155,14 @@ struct IRCall : IRInst
1122
1155
struct IRLoad : IRInst
1123
1156
{
1124
1157
IRUse ptr;
1158
+ IR_LEAF_ISA (Load)
1125
1159
};
1126
1160
1127
1161
struct IRStore : IRInst
1128
1162
{
1129
1163
IRUse ptr;
1130
1164
IRUse val;
1165
+ IR_LEAF_ISA (Store)
1131
1166
};
1132
1167
1133
1168
struct IRFieldExtract : IRInst
@@ -1137,6 +1172,8 @@ struct IRFieldExtract : IRInst
1137
1172
1138
1173
IRInst* getBase () { return base.get (); }
1139
1174
IRInst* getField () { return field.get (); }
1175
+ IR_LEAF_ISA (FieldExtract)
1176
+
1140
1177
};
1141
1178
1142
1179
struct IRFieldAddress : IRInst
@@ -1146,6 +1183,8 @@ struct IRFieldAddress : IRInst
1146
1183
1147
1184
IRInst* getBase () { return base.get (); }
1148
1185
IRInst* getField () { return field.get (); }
1186
+ IR_LEAF_ISA (FieldAddress)
1187
+
1149
1188
};
1150
1189
1151
1190
struct IRGetAddress : IRInst
@@ -1439,6 +1478,16 @@ struct IRWitnessTable : IRInst
1439
1478
IR_LEAF_ISA (WitnessTable)
1440
1479
};
1441
1480
1481
+ // / Represents an RTTI object.
1482
+ // / An IRRTTIObject has 1 operand, specifying the type
1483
+ // / this RTTI object provides info for.
1484
+ // / All type info are encapsualted as `IRRTTI*Decoration`s attached
1485
+ // / to the object.
1486
+ struct IRRTTIObject : IRInst
1487
+ {
1488
+ IR_LEAF_ISA (RTTIObject)
1489
+ };
1490
+
1442
1491
// An instruction that yields an undefined value.
1443
1492
//
1444
1493
// Note that we make this an instruction rather than a value,
@@ -1574,6 +1623,8 @@ struct IRBuilder
1574
1623
IRAssociatedType* getAssociatedType ();
1575
1624
IRThisType* getThisType ();
1576
1625
IRRawPointerType* getRawPointerType ();
1626
+ IRRTTIPointerType* getRTTIPointerType (IRInst* rttiPtr);
1627
+ IRRTTIType* getRTTIType ();
1577
1628
1578
1629
1579
1630
IRBasicBlockType* getBasicBlockType ();
@@ -1681,6 +1732,10 @@ struct IRBuilder
1681
1732
IRInst* witnessTableVal,
1682
1733
IRInst* interfaceMethodVal);
1683
1734
1735
+ IRInst* emitAlloca (IRInst* type, IRInst* rttiObjPtr);
1736
+
1737
+ IRInst* emitCopy (IRInst* dst, IRInst* src, IRInst* rttiObjPtr);
1738
+
1684
1739
IRInst* emitCallInst (
1685
1740
IRType* type,
1686
1741
IRInst* func,
@@ -1712,6 +1767,9 @@ struct IRBuilder
1712
1767
UInt argCount,
1713
1768
IRInst* const * args);
1714
1769
1770
+ // Creates an RTTI object. Result is of `IRRTTIType`.
1771
+ IRInst* emitMakeRTTIObject (IRInst* typeInst);
1772
+
1715
1773
IRInst* emitMakeVector (
1716
1774
IRType* type,
1717
1775
UInt argCount,
@@ -2243,6 +2301,11 @@ struct IRBuilder
2243
2301
{
2244
2302
addDecoration (inst, kIROp_FormatDecoration , format);
2245
2303
}
2304
+
2305
+ void addRTTITypeSizeDecoration (IRInst* inst, IRIntegerValue value)
2306
+ {
2307
+ addDecoration (inst, kIROp_RTTITypeSizeDecoration , getIntValue (getIntType (), value));
2308
+ }
2246
2309
};
2247
2310
2248
2311
void addHoistableInst (
0 commit comments