@@ -256,14 +256,14 @@ class SubscriptOpLowering : public OpConversionPattern<cxx::SubscriptOp> {
256
256
auto typeConverter = getTypeConverter ();
257
257
auto context = getContext ();
258
258
259
- auto ptrType = dyn_cast_or_null <cxx::PointerType>(op.getBase ().getType ());
259
+ auto ptrType = dyn_cast <cxx::PointerType>(op.getBase ().getType ());
260
260
261
261
if (!ptrType) {
262
262
return rewriter.notifyMatchFailure (
263
263
op, " failed to convert subscript operation type" );
264
264
}
265
265
266
- auto arrayType = dyn_cast_or_null <cxx::ArrayType>(ptrType.getElementType ());
266
+ auto arrayType = dyn_cast <cxx::ArrayType>(ptrType.getElementType ());
267
267
if (!arrayType) {
268
268
return rewriter.notifyMatchFailure (
269
269
op, " expected base type of subscript to be an array type" );
@@ -435,6 +435,45 @@ class IntToBoolOpLowering : public OpConversionPattern<cxx::IntToBoolOp> {
435
435
}
436
436
};
437
437
438
+ class ArrayToPointerOpLowering
439
+ : public OpConversionPattern<cxx::ArrayToPointerOp> {
440
+ public:
441
+ using OpConversionPattern::OpConversionPattern;
442
+
443
+ auto matchAndRewrite (cxx::ArrayToPointerOp op, OpAdaptor adaptor,
444
+ ConversionPatternRewriter &rewriter) const
445
+ -> LogicalResult override {
446
+ auto typeConverter = getTypeConverter ();
447
+ auto context = getContext ();
448
+
449
+ auto ptrType = dyn_cast<cxx::PointerType>(op.getValue ().getType ());
450
+
451
+ if (!ptrType) {
452
+ return rewriter.notifyMatchFailure (
453
+ op, " failed to convert subscript operation type" );
454
+ }
455
+
456
+ auto arrayType = dyn_cast<cxx::ArrayType>(ptrType.getElementType ());
457
+ if (!arrayType) {
458
+ return rewriter.notifyMatchFailure (
459
+ op, " expected base type of subscript to be an array type" );
460
+ }
461
+
462
+ SmallVector<LLVM::GEPArg> indices;
463
+
464
+ indices.push_back (0 );
465
+ indices.push_back (0 );
466
+
467
+ auto resultType = LLVM::LLVMPointerType::get (context);
468
+ auto elementType = typeConverter->convertType (ptrType.getElementType ());
469
+
470
+ rewriter.replaceOpWithNewOp <LLVM::GEPOp>(op, resultType, elementType,
471
+ adaptor.getValue (), indices);
472
+
473
+ return success ();
474
+ }
475
+ };
476
+
438
477
class BoolToIntOpLowering : public OpConversionPattern <cxx::BoolToIntOp> {
439
478
public:
440
479
using OpConversionPattern::OpConversionPattern;
@@ -1225,9 +1264,9 @@ void CxxToLLVMLoweringPass::runOnOperation() {
1225
1264
SubscriptOpLowering>(typeConverter, dataLayout, context);
1226
1265
1227
1266
// cast operations
1228
- patterns
1229
- . insert <IntToBoolOpLowering, BoolToIntOpLowering, IntegralCastOpLowering>(
1230
- typeConverter, context);
1267
+ patterns. insert <IntToBoolOpLowering, BoolToIntOpLowering,
1268
+ IntegralCastOpLowering, ArrayToPointerOpLowering >(
1269
+ typeConverter, context);
1231
1270
1232
1271
// constant operations
1233
1272
patterns.insert <BoolConstantOpLowering, IntConstantOpLowering,
0 commit comments