Skip to content

Commit

Permalink
[flang][hlfir] Propagate acc.declare from hlfir.declare to fir.declare.
Browse files Browse the repository at this point in the history
The declare enter operations are failing verification after HLFIR to FIR
conversion, because we drop acc.declare attribute when converting
hlfir.declare to fir.declare. This patch just propagates all attributes
during the conversion. This may need to be changed in future, if some
attributes are invalid for fir.declare or they need to be mapped
into other attributes.

The added LIT test is a copy of Lower/OpenACC/acc-declare.f90
with the updated checks. It tests HLFIR after lowering and FIR
after HLFIR-to-FIR conversion.

The Lower/OpenACC/acc-declare.f90 is being actively changed, so
it may be better to put the new RUN commands and the new checks
into the original file. For example, when you add more testing
for OpenACC declare in Lower/OpenACC/acc-declare.f90, you
add checks just for FIR-lowering path. I will be able to add
HLFIR checks later for those pieces. When you change something
for the existing OpenACC declare, you will have to update
the checks for all three pipelines. Alternatively, we can keep
it in a separate file, but this will complicate the migration
a little bit. Please let me know what you would prefer.

Reviewed By: razvanlupusoru, clementval

Differential Revision: https://reviews.llvm.org/D157560
  • Loading branch information
vzakhari committed Aug 11, 2023
1 parent 14292d9 commit 6ffd67a
Show file tree
Hide file tree
Showing 2 changed files with 346 additions and 6 deletions.
20 changes: 14 additions & 6 deletions flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,20 @@ class DeclareOpConversion : public mlir::OpRewritePattern<hlfir::DeclareOp> {
if (auto attrs = declareOp.getFortranAttrs())
fortranAttrs =
fir::FortranVariableFlagsAttr::get(rewriter.getContext(), *attrs);
auto firBase = rewriter
.create<fir::DeclareOp>(
loc, memref.getType(), memref, declareOp.getShape(),
declareOp.getTypeparams(), declareOp.getUniqName(),
fortranAttrs)
.getResult();
auto firDeclareOp = rewriter.create<fir::DeclareOp>(
loc, memref.getType(), memref, declareOp.getShape(),
declareOp.getTypeparams(), declareOp.getUniqName(), fortranAttrs);

// Propagate other attributes from hlfir.declare to fir.declare.
// OpenACC's acc.declare is one example. Right now, the propagation
// is verbatim.
mlir::NamedAttrList elidedAttrs =
mlir::NamedAttrList{firDeclareOp->getAttrs()};
for (const mlir::NamedAttribute &attr : declareOp->getAttrs())
if (!elidedAttrs.get(attr.getName()))
firDeclareOp->setAttr(attr.getName(), attr.getValue());

auto firBase = firDeclareOp.getResult();
mlir::Value hlfirBase;
mlir::Type hlfirBaseType = declareOp.getBase().getType();
if (hlfirBaseType.isa<fir::BaseBoxType>()) {
Expand Down
Loading

0 comments on commit 6ffd67a

Please sign in to comment.