@@ -93,6 +93,7 @@ class CallBase;
93
93
class CallInst ;
94
94
class InvokeInst ;
95
95
class CallBrInst ;
96
+ class GetElementPtrInst ;
96
97
97
98
// / Iterator for the `Use` edges of a User's operands.
98
99
// / \Returns the operand `Use` when dereferenced.
@@ -196,18 +197,19 @@ class Value {
196
197
// / order.
197
198
llvm::Value *Val = nullptr ;
198
199
199
- friend class Context ; // For getting `Val`.
200
- friend class User ; // For getting `Val`.
201
- friend class Use ; // For getting `Val`.
202
- friend class SelectInst ; // For getting `Val`.
203
- friend class BranchInst ; // For getting `Val`.
204
- friend class LoadInst ; // For getting `Val`.
205
- friend class StoreInst ; // For getting `Val`.
206
- friend class ReturnInst ; // For getting `Val`.
207
- friend class CallBase ; // For getting `Val`.
208
- friend class CallInst ; // For getting `Val`.
209
- friend class InvokeInst ; // For getting `Val`.
210
- friend class CallBrInst ; // For getting `Val`.
200
+ friend class Context ; // For getting `Val`.
201
+ friend class User ; // For getting `Val`.
202
+ friend class Use ; // For getting `Val`.
203
+ friend class SelectInst ; // For getting `Val`.
204
+ friend class BranchInst ; // For getting `Val`.
205
+ friend class LoadInst ; // For getting `Val`.
206
+ friend class StoreInst ; // For getting `Val`.
207
+ friend class ReturnInst ; // For getting `Val`.
208
+ friend class CallBase ; // For getting `Val`.
209
+ friend class CallInst ; // For getting `Val`.
210
+ friend class InvokeInst ; // For getting `Val`.
211
+ friend class CallBrInst ; // For getting `Val`.
212
+ friend class GetElementPtrInst ; // For getting `Val`.
211
213
212
214
// / All values point to the context.
213
215
Context &Ctx;
@@ -540,14 +542,15 @@ class Instruction : public sandboxir::User {
540
542
// / A SandboxIR Instruction may map to multiple LLVM IR Instruction. This
541
543
// / returns its topmost LLVM IR instruction.
542
544
llvm::Instruction *getTopmostLLVMInstruction () const ;
543
- friend class SelectInst ; // For getTopmostLLVMInstruction().
544
- friend class BranchInst ; // For getTopmostLLVMInstruction().
545
- friend class LoadInst ; // For getTopmostLLVMInstruction().
546
- friend class StoreInst ; // For getTopmostLLVMInstruction().
547
- friend class ReturnInst ; // For getTopmostLLVMInstruction().
548
- friend class CallInst ; // For getTopmostLLVMInstruction().
549
- friend class InvokeInst ; // For getTopmostLLVMInstruction().
550
- friend class CallBrInst ; // For getTopmostLLVMInstruction().
545
+ friend class SelectInst ; // For getTopmostLLVMInstruction().
546
+ friend class BranchInst ; // For getTopmostLLVMInstruction().
547
+ friend class LoadInst ; // For getTopmostLLVMInstruction().
548
+ friend class StoreInst ; // For getTopmostLLVMInstruction().
549
+ friend class ReturnInst ; // For getTopmostLLVMInstruction().
550
+ friend class CallInst ; // For getTopmostLLVMInstruction().
551
+ friend class InvokeInst ; // For getTopmostLLVMInstruction().
552
+ friend class CallBrInst ; // For getTopmostLLVMInstruction().
553
+ friend class GetElementPtrInst ; // For getTopmostLLVMInstruction().
551
554
552
555
// / \Returns the LLVM IR Instructions that this SandboxIR maps to in program
553
556
// / order.
@@ -1175,6 +1178,110 @@ class CallBrInst final : public CallBase {
1175
1178
#endif
1176
1179
};
1177
1180
1181
+ class GetElementPtrInst final : public Instruction {
1182
+ // / Use Context::createGetElementPtrInst(). Don't call
1183
+ // / the constructor directly.
1184
+ GetElementPtrInst (llvm::Instruction *I, Context &Ctx)
1185
+ : Instruction(ClassID::GetElementPtr, Opcode::GetElementPtr, I, Ctx) {}
1186
+ GetElementPtrInst (ClassID SubclassID, llvm::Instruction *I, Context &Ctx)
1187
+ : Instruction(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
1188
+ friend class Context ; // For accessing the constructor in
1189
+ // create*()
1190
+ Use getOperandUseInternal (unsigned OpIdx, bool Verify) const final {
1191
+ return getOperandUseDefault (OpIdx, Verify);
1192
+ }
1193
+ SmallVector<llvm::Instruction *, 1 > getLLVMInstrs () const final {
1194
+ return {cast<llvm::Instruction>(Val)};
1195
+ }
1196
+
1197
+ public:
1198
+ static Value *create (Type *Ty, Value *Ptr , ArrayRef<Value *> IdxList,
1199
+ BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
1200
+ const Twine &NameStr = " " );
1201
+ static Value *create (Type *Ty, Value *Ptr , ArrayRef<Value *> IdxList,
1202
+ Instruction *InsertBefore, Context &Ctx,
1203
+ const Twine &NameStr = " " );
1204
+ static Value *create (Type *Ty, Value *Ptr , ArrayRef<Value *> IdxList,
1205
+ BasicBlock *InsertAtEnd, Context &Ctx,
1206
+ const Twine &NameStr = " " );
1207
+
1208
+ static bool classof (const Value *From) {
1209
+ return From->getSubclassID () == ClassID::GetElementPtr;
1210
+ }
1211
+ unsigned getUseOperandNo (const Use &Use) const final {
1212
+ return getUseOperandNoDefault (Use);
1213
+ }
1214
+ unsigned getNumOfIRInstrs () const final { return 1u ; }
1215
+
1216
+ Type *getSourceElementType () const {
1217
+ return cast<llvm::GetElementPtrInst>(Val)->getSourceElementType ();
1218
+ }
1219
+ Type *getResultElementType () const {
1220
+ return cast<llvm::GetElementPtrInst>(Val)->getResultElementType ();
1221
+ }
1222
+ unsigned getAddressSpace () const {
1223
+ return cast<llvm::GetElementPtrInst>(Val)->getAddressSpace ();
1224
+ }
1225
+
1226
+ inline op_iterator idx_begin () { return op_begin () + 1 ; }
1227
+ inline const_op_iterator idx_begin () const {
1228
+ return const_cast <GetElementPtrInst *>(this )->idx_begin ();
1229
+ }
1230
+ inline op_iterator idx_end () { return op_end (); }
1231
+ inline const_op_iterator idx_end () const {
1232
+ return const_cast <GetElementPtrInst *>(this )->idx_end ();
1233
+ }
1234
+ inline iterator_range<op_iterator> indices () {
1235
+ return make_range (idx_begin (), idx_end ());
1236
+ }
1237
+ inline iterator_range<const_op_iterator> indices () const {
1238
+ return const_cast <GetElementPtrInst *>(this )->indices ();
1239
+ }
1240
+
1241
+ Value *getPointerOperand () const ;
1242
+ static unsigned getPointerOperandIndex () {
1243
+ return llvm::GetElementPtrInst::getPointerOperandIndex ();
1244
+ }
1245
+ Type *getPointerOperandType () const {
1246
+ return cast<llvm::GetElementPtrInst>(Val)->getPointerOperandType ();
1247
+ }
1248
+ unsigned getPointerAddressSpace () const {
1249
+ return cast<llvm::GetElementPtrInst>(Val)->getPointerAddressSpace ();
1250
+ }
1251
+ unsigned getNumIndices () const {
1252
+ return cast<llvm::GetElementPtrInst>(Val)->getNumIndices ();
1253
+ }
1254
+ bool hasIndices () const {
1255
+ return cast<llvm::GetElementPtrInst>(Val)->hasIndices ();
1256
+ }
1257
+ bool hasAllConstantIndices () const {
1258
+ return cast<llvm::GetElementPtrInst>(Val)->hasAllConstantIndices ();
1259
+ }
1260
+ GEPNoWrapFlags getNoWrapFlags () const {
1261
+ return cast<llvm::GetElementPtrInst>(Val)->getNoWrapFlags ();
1262
+ }
1263
+ bool isInBounds () const {
1264
+ return cast<llvm::GetElementPtrInst>(Val)->isInBounds ();
1265
+ }
1266
+ bool hasNoUnsignedSignedWrap () const {
1267
+ return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedSignedWrap ();
1268
+ }
1269
+ bool hasNoUnsignedWrap () const {
1270
+ return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedWrap ();
1271
+ }
1272
+ bool accumulateConstantOffset (const DataLayout &DL, APInt &Offset) const {
1273
+ return cast<llvm::GetElementPtrInst>(Val)->accumulateConstantOffset (DL,
1274
+ Offset);
1275
+ }
1276
+ // TODO: Add missing member functions.
1277
+
1278
+ #ifndef NDEBUG
1279
+ void verify () const final {}
1280
+ void dump (raw_ostream &OS) const override ;
1281
+ LLVM_DUMP_METHOD void dump () const override ;
1282
+ #endif
1283
+ };
1284
+
1178
1285
// / An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
1179
1286
// / an OpaqueInstr.
1180
1287
class OpaqueInst : public sandboxir ::Instruction {
@@ -1329,6 +1436,8 @@ class Context {
1329
1436
friend InvokeInst; // For createInvokeInst()
1330
1437
CallBrInst *createCallBrInst (llvm::CallBrInst *I);
1331
1438
friend CallBrInst; // For createCallBrInst()
1439
+ GetElementPtrInst *createGetElementPtrInst (llvm::GetElementPtrInst *I);
1440
+ friend GetElementPtrInst; // For createGetElementPtrInst()
1332
1441
1333
1442
public:
1334
1443
Context (LLVMContext &LLVMCtx)
0 commit comments