-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Flang] Propogate fir.declare attributes through cg-rewrite #137207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3301f3e
353e86a
a26f871
aa366ae
196dfeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,6 +281,20 @@ class DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> { | |
| matchAndRewrite(fir::DeclareOp declareOp, | ||
| mlir::PatternRewriter &rewriter) const override { | ||
| if (!preserveDeclare) { | ||
| auto memrefOp = declareOp.getMemref().getDefiningOp(); | ||
| if (!memrefOp) { | ||
| rewriter.replaceOp(declareOp, declareOp.getMemref()); | ||
|
||
| return mlir::success(); | ||
| } | ||
|
|
||
| // attach metadatas from the fir.declare to its memref (if it's an | ||
| // operation) | ||
| mlir::NamedAttrList elidedAttrs = | ||
| mlir::NamedAttrList{memrefOp->getAttrs()}; | ||
| for (const mlir::NamedAttribute &attr : declareOp->getAttrs()) | ||
| if (!elidedAttrs.get(attr.getName())) | ||
| memrefOp->setAttr(attr.getName(), attr.getValue()); | ||
|
|
||
| rewriter.replaceOp(declareOp, declareOp.getMemref()); | ||
| return mlir::success(); | ||
| } | ||
|
|
@@ -299,11 +313,16 @@ class DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> { | |
| else | ||
| return mlir::failure(); | ||
| } | ||
| // FIXME: Add FortranAttrs and CudaAttrs | ||
|
|
||
| auto xDeclOp = rewriter.create<fir::cg::XDeclareOp>( | ||
| loc, declareOp.getType(), declareOp.getMemref(), shapeOpers, shiftOpers, | ||
| declareOp.getTypeparams(), declareOp.getDummyScope(), | ||
| declareOp.getUniqName()); | ||
|
|
||
| // attach metadatas from fir.declare to fircg.ext_declare | ||
|
||
| for (const mlir::NamedAttribute &attr : declareOp->getAttrs()) | ||
| xDeclOp->setAttr(attr.getName(), attr.getValue()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this not overriding the I would suggest checking if the attributes names are not already used in the xDeclop to avoid any issues. |
||
|
|
||
| LLVM_DEBUG(llvm::dbgs() | ||
| << "rewriting " << declareOp << " to " << xDeclOp << '\n'); | ||
| rewriter.replaceOp(declareOp, xDeclOp.getOperation()->getResults()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a bit weird to propagate the attributes on the declare memref input producing op. First of all, you may end-up in weird situations where a single alloca maps to several declare (looking at you equivalences), so that could conflict.
Why do you need to propagate attribute if the cg declare is not emitted?
It looks like to me that if one wants to preserve language level info, the declare should also be preserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good catch, thanks Jean! I will remove this part and sought solutions downstream. thanks!