Skip to content

Commit

Permalink
[flang][openacc] Add OpenACC pointer interface to FIR pointer types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
razvanlupusoru authored and Razvan Lupusoru committed Apr 19, 2023
1 parent 3e76d01 commit 4bb64da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
8 changes: 8 additions & 0 deletions flang/include/flang/Optimizer/Dialect/FIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -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"> {
Expand Down Expand Up @@ -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"> {
Expand Down
18 changes: 10 additions & 8 deletions flang/include/flang/Tools/PointerModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand Down
18 changes: 13 additions & 5 deletions flang/lib/Optimizer/Dialect/FIRType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 4bb64da

Please sign in to comment.