[flang-commits] [flang] [Flang][MLIR] Teach AddAliasTags getFuncArgName to deal with omp::TargetOp's (PR #92036)
via flang-commits
flang-commits at lists.llvm.org
Mon May 13 14:30:08 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: None (agozillon)
<details>
<summary>Changes</summary>
This PR attempts to fix the name retrieval of getFuncArgName inside of AddAliasTags when used in conjunction with an omp::TargetOp. While omp::TargetOp is function like it does not implement the FunctionOpInterface, so on the occasions where this pass invokes getFuncArgName on it, it will crash.
This PR attempts to address that by adding a special case for TargetOp where we find the map operand corresponding to the block argument and return the name attribute tied to the map operand.
This issue was found in a downstream test case that unfortunately won't run upstream yet as far as I am aware, the below is a variation of the offending block of code (attempted to reduce it a bit..):
```
!$omp target teams distribute parallel do &
!$omp collapse(2) private(i,ib,ic,i1)
do i1=1,3
do ic=1,3
do ib=1,3
do i=1,3
xgnn(1,1,1,1) = 1
end do
end do
end do
end do
!$omp end target teams distribute parallel do
```
When -O3 (or anything larger than default) is set, the AddAliasTags pass will be activated and when we encounter a construct like the above in a function or subroutine we end up ICE'ng the compiler.
---
Full diff: https://github.com/llvm/llvm-project/pull/92036.diff
1 Files Affected:
- (modified) flang/lib/Optimizer/Transforms/AddAliasTags.cpp (+15-2)
``````````diff
diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
index 684aa4462915e..026dfe93d6f11 100644
--- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
+++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
@@ -105,8 +105,21 @@ static std::string getFuncArgName(mlir::Value arg) {
"arg is a function argument");
mlir::FunctionOpInterface func = mlir::dyn_cast<mlir::FunctionOpInterface>(
blockArg.getOwner()->getParentOp());
- mlir::StringAttr attr = func.getArgAttrOfType<mlir::StringAttr>(
- blockArg.getArgNumber(), "fir.bindc_name");
+ mlir::StringAttr attr;
+ if (func) {
+ attr = func.getArgAttrOfType<mlir::StringAttr>(blockArg.getArgNumber(),
+ "fir.bindc_name");
+ } else {
+ if (auto targetOp = mlir::dyn_cast<mlir::omp::TargetOp>(
+ blockArg.getOwner()->getParentOp())) {
+ if (auto mapOp = mlir::dyn_cast<mlir::omp::MapInfoOp>(
+ targetOp.getMapOperands()[blockArg.getArgNumber()]
+ .getDefiningOp())) {
+ attr = mapOp.getNameAttr();
+ }
+ }
+ }
+
if (!attr)
return "";
return attr.str();
``````````
</details>
https://github.com/llvm/llvm-project/pull/92036
More information about the flang-commits
mailing list