[PATCH] D113931: [fir] Add fir.box_tdesc conversion
Valentin Clement via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 17 02:27:31 PST 2021
clementval updated this revision to Diff 387881.
clementval added a comment.
Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113931/new/
https://reviews.llvm.org/D113931
Files:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/convert-to-llvm.fir
Index: flang/test/Fir/convert-to-llvm.fir
===================================================================
--- flang/test/Fir/convert-to-llvm.fir
+++ flang/test/Fir/convert-to-llvm.fir
@@ -1319,3 +1319,20 @@
// CHECK-NOT: fir.slice
// CHECK: %{{.*}} = llvm.mlir.constant(0 : index) : i{{.*}}
// CHECK-NEXT: llvm.return
+
+// -----
+
+// Test `fir.box_tdesc` conversion.
+
+func @box_tdesc(%arg0: !fir.box<f64>) {
+ %0 = fir.box_tdesc %arg0 : (!fir.box<f64>) -> !fir.tdesc<f64>
+ return
+}
+
+// CHECK-LABEL: llvm.func @box_tdesc(
+// CHECK-SAME: %[[ARG0:.*]]: !llvm.ptr<struct<(ptr<f64>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>) {
+// CHECK: %[[C0:.*]] = llvm.mlir.constant(0 : i32) : i32
+// CHECK: %[[TYPE_POS:.*]] = llvm.mlir.constant(4 : i32) : i32
+// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG0]][%[[C0]], %[[TYPE_POS]]] : (!llvm.ptr<struct<(ptr<f64>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>, i32, i32) -> !llvm.ptr<i8>
+// CHECK: %[[LOAD:.*]] = llvm.load %[[GEP]] : !llvm.ptr<i{{.*}}>
+// CHECK: %{{.*}} = llvm.inttoptr %[[LOAD]] : i{{.*}} to !llvm.ptr<i{{.*}}>
Index: flang/lib/Optimizer/CodeGen/CodeGen.cpp
===================================================================
--- flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -498,6 +498,26 @@
}
};
+/// Lower `fir.box_tdesc` to the sequence of operations to extract the type
+/// descriptor from the box.
+struct BoxTypeDescOpConversion : public FIROpConversion<fir::BoxTypeDescOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::BoxTypeDescOp boxtypedesc, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ mlir::Value box = adaptor.getOperands()[0];
+ auto loc = boxtypedesc.getLoc();
+ mlir::Type typeTy =
+ fir::getDescFieldTypeModel<kTypePosInBox>()(boxtypedesc.getContext());
+ auto result = getValueFromBox(loc, box, typeTy, rewriter, kTypePosInBox);
+ auto typePtrTy = mlir::LLVM::LLVMPointerType::get(typeTy);
+ rewriter.replaceOpWithNewOp<mlir::LLVM::IntToPtrOp>(boxtypedesc, typePtrTy,
+ result);
+ return success();
+ }
+};
+
// `fir.call` -> `llvm.call`
struct CallOpConversion : public FIROpConversion<fir::CallOp> {
using FIROpConversion::FIROpConversion;
@@ -1664,18 +1684,18 @@
AllocaOpConversion, BoxAddrOpConversion, BoxCharLenOpConversion,
BoxDimsOpConversion, BoxEleSizeOpConversion, BoxIsAllocOpConversion,
BoxIsArrayOpConversion, BoxIsPtrOpConversion, BoxRankOpConversion,
- CallOpConversion, CmpcOpConversion, ConvertOpConversion,
- DispatchOpConversion, DispatchTableOpConversion, DTEntryOpConversion,
- DivcOpConversion, EmboxCharOpConversion, ExtractValueOpConversion,
- HasValueOpConversion, GenTypeDescOpConversion, GlobalLenOpConversion,
- GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion,
- IsPresentOpConversion, LoadOpConversion, NegcOpConversion,
- MulcOpConversion, SelectCaseOpConversion, SelectOpConversion,
- SelectRankOpConversion, SelectTypeOpConversion, ShapeOpConversion,
- ShapeShiftOpConversion, ShiftOpConversion, SliceOpConversion,
- StoreOpConversion, StringLitOpConversion, SubcOpConversion,
- UnboxCharOpConversion, UndefOpConversion, UnreachableOpConversion,
- ZeroOpConversion>(typeConverter);
+ BoxTypeDescOpConversion, CallOpConversion, CmpcOpConversion,
+ ConvertOpConversion, DispatchOpConversion, DispatchTableOpConversion,
+ DTEntryOpConversion, DivcOpConversion, EmboxCharOpConversion,
+ ExtractValueOpConversion, HasValueOpConversion, GenTypeDescOpConversion,
+ GlobalLenOpConversion, GlobalOpConversion, InsertOnRangeOpConversion,
+ InsertValueOpConversion, IsPresentOpConversion, LoadOpConversion,
+ NegcOpConversion, MulcOpConversion, SelectCaseOpConversion,
+ SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion,
+ ShapeOpConversion, ShapeShiftOpConversion, ShiftOpConversion,
+ SliceOpConversion, StoreOpConversion, StringLitOpConversion,
+ SubcOpConversion, UnboxCharOpConversion, UndefOpConversion,
+ UnreachableOpConversion, ZeroOpConversion>(typeConverter);
mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern);
mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter,
pattern);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113931.387881.patch
Type: text/x-patch
Size: 4673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211117/7f76b2c0/attachment.bin>
More information about the llvm-commits
mailing list