[llvm-branch-commits] [flang] [flang][NFC] move extractSequenceType helper out of OpenACC to share code (PR #84957)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Mar 12 10:34:53 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Tom Eccles (tblah)
<details>
<summary>Changes</summary>
Moving extractSequenceType to FIRType.h so that this can also be used from OpenMP.
OpenMP array reductions 5/6
---
Full diff: https://github.com/llvm/llvm-project/pull/84957.diff
3 Files Affected:
- (modified) flang/include/flang/Optimizer/Dialect/FIRType.h (+3)
- (modified) flang/lib/Lower/OpenACC.cpp (+4-17)
- (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+12)
``````````diff
diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index a526b4ddf3b98c..7fcd9c1babf24f 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -237,6 +237,9 @@ inline mlir::Type unwrapSequenceType(mlir::Type t) {
return t;
}
+/// Return the nested sequence type if any.
+mlir::Type extractSequenceType(mlir::Type ty);
+
inline mlir::Type unwrapRefType(mlir::Type t) {
if (auto eleTy = dyn_cast_ptrEleTy(t))
return eleTy;
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index d2c6006ecf914a..6539de4d88304c 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -406,19 +406,6 @@ fir::ShapeOp genShapeOp(mlir::OpBuilder &builder, fir::SequenceType seqTy,
return builder.create<fir::ShapeOp>(loc, extents);
}
-/// Return the nested sequence type if any.
-static mlir::Type extractSequenceType(mlir::Type ty) {
- if (mlir::isa<fir::SequenceType>(ty))
- return ty;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty))
- return extractSequenceType(boxTy.getEleTy());
- if (auto heapTy = mlir::dyn_cast<fir::HeapType>(ty))
- return extractSequenceType(heapTy.getEleTy());
- if (auto ptrTy = mlir::dyn_cast<fir::PointerType>(ty))
- return extractSequenceType(ptrTy.getEleTy());
- return mlir::Type{};
-}
-
template <typename RecipeOp>
static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe,
mlir::Type ty, mlir::Location loc) {
@@ -454,7 +441,7 @@ static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe,
}
}
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) {
- mlir::Type innerTy = extractSequenceType(boxTy);
+ mlir::Type innerTy = fir::extractSequenceType(boxTy);
if (!innerTy)
TODO(loc, "Unsupported boxed type in OpenACC privatization");
fir::FirOpBuilder firBuilder{builder, recipe.getOperation()};
@@ -688,7 +675,7 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe(
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) {
fir::FirOpBuilder firBuilder{builder, recipe.getOperation()};
llvm::SmallVector<mlir::Value> tripletArgs;
- mlir::Type innerTy = extractSequenceType(boxTy);
+ mlir::Type innerTy = fir::extractSequenceType(boxTy);
fir::SequenceType seqTy =
mlir::dyn_cast_or_null<fir::SequenceType>(innerTy);
if (!seqTy)
@@ -1018,7 +1005,7 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder,
return declareOp.getBase();
}
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) {
- mlir::Type innerTy = extractSequenceType(boxTy);
+ mlir::Type innerTy = fir::extractSequenceType(boxTy);
if (!mlir::isa<fir::SequenceType>(innerTy))
TODO(loc, "Unsupported boxed type for reduction");
// Create the private copy from the initial fir.box.
@@ -1230,7 +1217,7 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc,
builder.create<fir::StoreOp>(loc, res, addr1);
builder.setInsertionPointAfter(loops[0]);
} else if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
- mlir::Type innerTy = extractSequenceType(boxTy);
+ mlir::Type innerTy = fir::extractSequenceType(boxTy);
fir::SequenceType seqTy =
mlir::dyn_cast_or_null<fir::SequenceType>(innerTy);
if (!seqTy)
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 8a2c681d958609..5c4cad6d208344 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -254,6 +254,18 @@ bool hasDynamicSize(mlir::Type t) {
return false;
}
+mlir::Type extractSequenceType(mlir::Type ty) {
+ if (mlir::isa<fir::SequenceType>(ty))
+ return ty;
+ if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty))
+ return extractSequenceType(boxTy.getEleTy());
+ if (auto heapTy = mlir::dyn_cast<fir::HeapType>(ty))
+ return extractSequenceType(heapTy.getEleTy());
+ if (auto ptrTy = mlir::dyn_cast<fir::PointerType>(ty))
+ return extractSequenceType(ptrTy.getEleTy());
+ return mlir::Type{};
+}
+
bool isPointerType(mlir::Type ty) {
if (auto refTy = fir::dyn_cast_ptrEleTy(ty))
ty = refTy;
``````````
</details>
https://github.com/llvm/llvm-project/pull/84957
More information about the llvm-branch-commits
mailing list