-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Add support to fir::cg in alias analysis #127827
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
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Susan Tan (ス-ザン タン) (SusanTan) ChangesCurrently the alias analysis doesn't trace the source whenever there are operations from fir::cg dialect. This PR added support for fir::cg::XEmboxOp, fir::cg::XReboxOp, fir::cg::XDeclareOp for a specific application i'm working on. Full diff: https://github.com/llvm/llvm-project/pull/127827.diff 1 Files Affected:
diff --git a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
index 70fa18ad65b9b..230f1e269c375 100644
--- a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
+++ b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
@@ -19,6 +19,7 @@
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Value.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
+#include "flang/Optimizer/CodeGen/CGOps.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
@@ -591,7 +592,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
followBoxData = true;
approximateSource = true;
})
- .Case<fir::EmboxOp, fir::ReboxOp>([&](auto op) {
+ .Case<fir::EmboxOp, fir::ReboxOp, fir::cg::XEmboxOp, fir::cg::XReboxOp>([&](auto op) {
if (followBoxData) {
v = op->getOperand(0);
defOp = v.getDefiningOp();
@@ -604,6 +605,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
Operation *loadMemrefOp = op.getMemref().getDefiningOp();
bool isDeclareOp =
llvm::isa_and_present<fir::DeclareOp>(loadMemrefOp) ||
+ llvm::isa_and_present<fir::cg::XDeclareOp>(loadMemrefOp) ||
llvm::isa_and_present<hlfir::DeclareOp>(loadMemrefOp);
if (isDeclareOp &&
llvm::isa<omp::TargetOp>(loadMemrefOp->getParentOp())) {
@@ -666,7 +668,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
global = llvm::cast<fir::AddrOfOp>(op).getSymbol();
breakFromLoop = true;
})
- .Case<hlfir::DeclareOp, fir::DeclareOp>([&](auto op) {
+ .Case<hlfir::DeclareOp, fir::DeclareOp, fir::cg::XDeclareOp>([&](auto op) {
bool isPrivateItem = false;
if (omp::BlockArgOpenMPOpInterface argIface =
dyn_cast<omp::BlockArgOpenMPOpInterface>(op->getParentOp())) {
@@ -700,30 +702,32 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
return;
}
}
- auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
- // While going through a declare operation collect
- // the variable attributes from it. Right now, some
- // of the attributes are duplicated, e.g. a TARGET dummy
- // argument has the target attribute both on its declare
- // operation and on the entry block argument.
- // In case of host associated use, the declare operation
- // is the only carrier of the variable attributes,
- // so we have to collect them here.
- attributes |= getAttrsFromVariable(varIf);
- isCapturedInInternalProcedure |=
- varIf.isCapturedInInternalProcedure();
- if (varIf.isHostAssoc()) {
- // Do not track past such DeclareOp, because it does not
- // currently provide any useful information. The host associated
- // access will end up dereferencing the host association tuple,
- // so we may as well stop right now.
- v = defOp->getResult(0);
- // TODO: if the host associated variable is a dummy argument
- // of the host, I think, we can treat it as SourceKind::Argument
- // for the purpose of alias analysis inside the internal procedure.
- type = SourceKind::HostAssoc;
- breakFromLoop = true;
- return;
+ auto varIf = llvm::dyn_cast<fir::FortranVariableOpInterface>(defOp);
+ if(varIf){
+ // While going through a declare operation collect
+ // the variable attributes from it. Right now, some
+ // of the attributes are duplicated, e.g. a TARGET dummy
+ // argument has the target attribute both on its declare
+ // operation and on the entry block argument.
+ // In case of host associated use, the declare operation
+ // is the only carrier of the variable attributes,
+ // so we have to collect them here.
+ attributes |= getAttrsFromVariable(varIf);
+ isCapturedInInternalProcedure |=
+ varIf.isCapturedInInternalProcedure();
+ if (varIf.isHostAssoc()) {
+ // Do not track past such DeclareOp, because it does not
+ // currently provide any useful information. The host associated
+ // access will end up dereferencing the host association tuple,
+ // so we may as well stop right now.
+ v = defOp->getResult(0);
+ // TODO: if the host associated variable is a dummy argument
+ // of the host, I think, we can treat it as SourceKind::Argument
+ // for the purpose of alias analysis inside the internal procedure.
+ type = SourceKind::HostAssoc;
+ breakFromLoop = true;
+ return;
+ }
}
if (getLastInstantiationPoint) {
// Fetch only the innermost instantiation point.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
The code changes look good to me, thanks!
Out of curiosity, what are you using this for?
@tblah Hi Tom, it is for a downstream project where we use the FIR aa at a later stage down the FIR pipeline! |
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.
Thank you!
6ab16e6
to
1b86576
Compare
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.
Thank you for the test and the formatting changes.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/1262 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/1242 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/2452 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/17040 Here is the relevant piece of the build log for the reference
|
Currently the alias analysis doesn't trace the source whenever there are operations from fir::cg dialect. This PR added support for fir::cg::XEmboxOp, fir::cg::XReboxOp, fir::cg::XDeclareOp for a specific application i'm working on.