[flang-commits] [flang] 4bb64da - [flang][openacc] Add OpenACC pointer interface to FIR pointer types

Razvan Lupusoru via flang-commits flang-commits at lists.llvm.org
Wed Apr 19 07:33:00 PDT 2023


Author: Razvan Lupusoru
Date: 2023-04-19T07:32:41-07:00
New Revision: 4bb64daf34aa3463786f531b5b42d13ab5f47869

URL: https://github.com/llvm/llvm-project/commit/4bb64daf34aa3463786f531b5b42d13ab5f47869
DIFF: https://github.com/llvm/llvm-project/commit/4bb64daf34aa3463786f531b5b42d13ab5f47869.diff

LOG: [flang][openacc] Add OpenACC pointer interface to FIR pointer types

The OpenACC dialect data clauses require for variables appearing in data
operations to implement the `PointerLikeType` interface (similarly to
OpenMP dialect). Thus, this interface needs attached to FIR types.

Two of the FIR types, HeapType and LLVMPointerType, did not provide
getElementType - now they do by calling getEleTy. This cleans up the
interface attachment for both OpenACC and OpenMP dialects.

Reviewed By: clementval, jeanPerier

Differential Revision: https://reviews.llvm.org/D148560

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIRTypes.td
    flang/include/flang/Tools/PointerModels.h
    flang/lib/Optimizer/Dialect/FIRType.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 75694071818dc..51608e3c1d63e 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -211,6 +211,10 @@ def fir_HeapType : FIR_Type<"Heap", "heap"> {
       return Base::get(elementType.getContext(), elementType);
     }]>,
   ];
+
+  let extraClassDeclaration = [{
+    mlir::Type getElementType() const { return getEleTy(); }
+  }];
 }
 
 def fir_IntegerType : FIR_Type<"Integer", "int"> {
@@ -275,6 +279,10 @@ def fir_LLVMPointerType : FIR_Type<"LLVMPointer", "llvm_ptr"> {
       return Base::get(elementType.getContext(), elementType);
     }]>,
   ];
+
+  let extraClassDeclaration = [{
+    mlir::Type getElementType() const { return getEleTy(); }
+  }];
 }
 
 def fir_PointerType : FIR_Type<"Pointer", "ptr"> {

diff  --git a/flang/include/flang/Tools/PointerModels.h b/flang/include/flang/Tools/PointerModels.h
index 915a7afb18b37..7acaf2f9fda5b 100644
--- a/flang/include/flang/Tools/PointerModels.h
+++ b/flang/include/flang/Tools/PointerModels.h
@@ -9,25 +9,27 @@
 #ifndef FORTRAN_TOOLS_POINTER_MODELS_H
 #define FORTRAN_TOOLS_POINTER_MODELS_H
 
+#include "mlir/Dialect/OpenACC/OpenACC.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 
-/// models for FIR pointer like types that already provide a `getElementType` or
-/// a `getEleTy` method
+/// models for FIR pointer like types that already provide a `getElementType`
+/// method
 
 template <typename T>
-struct PointerLikeModel
-    : public mlir::omp::PointerLikeType::ExternalModel<PointerLikeModel<T>, T> {
+struct OpenMPPointerLikeModel
+    : public mlir::omp::PointerLikeType::ExternalModel<
+          OpenMPPointerLikeModel<T>, T> {
   mlir::Type getElementType(mlir::Type pointer) const {
     return pointer.cast<T>().getElementType();
   }
 };
 
 template <typename T>
-struct AlternativePointerLikeModel
-    : public mlir::omp::PointerLikeType::ExternalModel<
-          AlternativePointerLikeModel<T>, T> {
+struct OpenACCPointerLikeModel
+    : public mlir::acc::PointerLikeType::ExternalModel<
+          OpenACCPointerLikeModel<T>, T> {
   mlir::Type getElementType(mlir::Type pointer) const {
-    return pointer.cast<T>().getEleTy();
+    return pointer.cast<T>().getElementType();
   }
 };
 

diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 6237fd571dd89..9ab1818fa88aa 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -1131,15 +1131,23 @@ void FIROpsDialect::registerTypes() {
            LogicalType, LLVMPointerType, PointerType, RealType, RecordType,
            ReferenceType, SequenceType, ShapeType, ShapeShiftType, ShiftType,
            SliceType, TypeDescType, fir::VectorType>();
-  fir::ReferenceType::attachInterface<PointerLikeModel<fir::ReferenceType>>(
-      *getContext());
+  fir::ReferenceType::attachInterface<
+      OpenMPPointerLikeModel<fir::ReferenceType>>(*getContext());
+  fir::ReferenceType::attachInterface<
+      OpenACCPointerLikeModel<fir::ReferenceType>>(*getContext());
 
-  fir::PointerType::attachInterface<PointerLikeModel<fir::PointerType>>(
+  fir::PointerType::attachInterface<OpenMPPointerLikeModel<fir::PointerType>>(
+      *getContext());
+  fir::PointerType::attachInterface<OpenACCPointerLikeModel<fir::PointerType>>(
       *getContext());
 
-  fir::HeapType::attachInterface<AlternativePointerLikeModel<fir::HeapType>>(
+  fir::HeapType::attachInterface<OpenMPPointerLikeModel<fir::HeapType>>(
+      *getContext());
+  fir::HeapType::attachInterface<OpenACCPointerLikeModel<fir::HeapType>>(
       *getContext());
 
   fir::LLVMPointerType::attachInterface<
-      AlternativePointerLikeModel<fir::LLVMPointerType>>(*getContext());
+      OpenMPPointerLikeModel<fir::LLVMPointerType>>(*getContext());
+  fir::LLVMPointerType::attachInterface<
+      OpenACCPointerLikeModel<fir::LLVMPointerType>>(*getContext());
 }


        


More information about the flang-commits mailing list