[flang-commits] [flang] [flang] add fir.box_offset operation (PR #73641)

via flang-commits flang-commits at lists.llvm.org
Wed Nov 29 07:42:47 PST 2023


================
@@ -3656,6 +3656,27 @@ struct NegcOpConversion : public FIROpConversion<fir::NegcOp> {
   }
 };
 
+struct BoxOffsetOpConversion : public FIROpConversion<fir::BoxOffsetOp> {
+  using FIROpConversion::FIROpConversion;
+
+  mlir::LogicalResult
+  matchAndRewrite(fir::BoxOffsetOp boxOffset, OpAdaptor adaptor,
+                  mlir::ConversionPatternRewriter &rewriter) const override {
+
+    mlir::Type pty = ::getLlvmPtrType(boxOffset.getContext());
+    mlir::Type boxType = fir::unwrapRefType(boxOffset.getBoxRef().getType());
+    mlir::Type llvmBoxTy =
+        lowerTy().convertBoxTypeAsStruct(mlir::cast<fir::BaseBoxType>(boxType));
+    unsigned fieldId = boxOffset.getField() == fir::BoxFieldAttr::derived_type
+                           ? getTypeDescFieldId(boxType)
+                           : kAddrPosInBox;
+    rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
+        boxOffset, pty, llvmBoxTy, adaptor.getBoxRef(),
+        llvm::ArrayRef<mlir::LLVM::GEPArg>{0, fieldId});
----------------
jeanPerier wrote:

https://github.com/llvm/llvm-project/pull/73808

https://github.com/llvm/llvm-project/pull/73641


More information about the flang-commits mailing list