For OpenACC clause ordering, such as maintaining appropriate parent-child relationship ordering, we need to be able to walk references back to their base entities. This introduces the operation interface in the `acc` dialect named `PartialEntityAccessOpInterface` which can be used for this purpose. The interface provides two methods: - `getBaseEntity()`: Returns the base entity being accessed - `isCompleteView()`: Indicates whether the access covers the complete entity to allow this interface to be attached to cases that only conditionally offer a partial view This also adds a utility function `mlir::acc::getBaseEntity()` that uses this interface to retrieve the base entity from a value. This work has some similarities with the ViewLikeOpInterface proposal for FIR: https://github.com/llvm/llvm-project/pull/164020 but it differs in the following ways: - Attached only to operations where we can assume a partial entity access - Includes fir.declare operations due to common block storage associations Tests are included that demonstrate the interface on memref.subview operations, implemented locally in the test since memref operations already have ViewLikeOpInterface for similar purposes.
63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
//===-- FIROpenACCOpsInterfaces.cpp ---------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Implementation of external operation interfaces for FIR.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h"
|
|
|
|
#include "flang/Optimizer/Dialect/FIROps.h"
|
|
#include "flang/Optimizer/HLFIR/HLFIROps.h"
|
|
|
|
namespace fir::acc {
|
|
|
|
template <>
|
|
mlir::Value PartialEntityAccessModel<fir::ArrayCoorOp>::getBaseEntity(
|
|
mlir::Operation *op) const {
|
|
return mlir::cast<fir::ArrayCoorOp>(op).getMemref();
|
|
}
|
|
|
|
template <>
|
|
mlir::Value PartialEntityAccessModel<fir::CoordinateOp>::getBaseEntity(
|
|
mlir::Operation *op) const {
|
|
return mlir::cast<fir::CoordinateOp>(op).getRef();
|
|
}
|
|
|
|
template <>
|
|
mlir::Value PartialEntityAccessModel<hlfir::DesignateOp>::getBaseEntity(
|
|
mlir::Operation *op) const {
|
|
return mlir::cast<hlfir::DesignateOp>(op).getMemref();
|
|
}
|
|
|
|
mlir::Value PartialEntityAccessModel<fir::DeclareOp>::getBaseEntity(
|
|
mlir::Operation *op) const {
|
|
return mlir::cast<fir::DeclareOp>(op).getStorage();
|
|
}
|
|
|
|
bool PartialEntityAccessModel<fir::DeclareOp>::isCompleteView(
|
|
mlir::Operation *op) const {
|
|
// Return false (partial view) only if storage is present
|
|
// Return true (complete view) if storage is absent
|
|
return !getBaseEntity(op);
|
|
}
|
|
|
|
mlir::Value PartialEntityAccessModel<hlfir::DeclareOp>::getBaseEntity(
|
|
mlir::Operation *op) const {
|
|
return mlir::cast<hlfir::DeclareOp>(op).getStorage();
|
|
}
|
|
|
|
bool PartialEntityAccessModel<hlfir::DeclareOp>::isCompleteView(
|
|
mlir::Operation *op) const {
|
|
// Return false (partial view) only if storage is present
|
|
// Return true (complete view) if storage is absent
|
|
return !getBaseEntity(op);
|
|
}
|
|
|
|
} // namespace fir::acc
|