[flang-commits] [flang] [Flang] [OpenMP] Run `MarkDeclareTarget` pass again after `ConvertMathToFuncs` (PR #210049)
via flang-commits
flang-commits at lists.llvm.org
Thu Jul 16 06:05:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Soham Karandikar (skadewdl3)
<details>
<summary>Changes</summary>
Fixes #<!-- -->209123.
The power operation `math.ipowi` is converted to a function by `ConvertMathToFuncs`. When used in a target region, this pass runs well after `MarkDeclareTarget` which causes the newly created power function to not have the `omp.declare_target` attribute - thus causing lowering issues. Detailed investigation [here](https://github.com/llvm/llvm-project/issues/209123#issuecomment-4991765854).
Right now, I've just added a couple of lines to run `MarkDeclareTarget` again, after `ConvertMathToFuncs`. Since I'm quite new to this, I'd like some help on whether this is acceptable, or should the `MarkDeclareTarget` pass be moved to after `ConvertMathToFuncs`.
---
Full diff: https://github.com/llvm/llvm-project/pull/210049.diff
1 Files Affected:
- (modified) flang/lib/Optimizer/Passes/Pipelines.cpp (+5)
``````````diff
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 879a224824119..7fe8bccc14d54 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -464,6 +464,11 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
pm.addPass(fir::createEmitMIFGlobalCtors());
if (config.EnableOpenMP && !config.EnableOpenMPSimd) {
+ // Since some math operations may be converted to function calls by the
+ // ConvertMathToFuncs pass, we need to mark them with the omp.declare_target
+ // attribute if they're called from a target region.
+ pm.addPass(mlir::omp::createMarkDeclareTargetPass());
+
// Remove all non target-related operations from host functions still
// remaining at this point, if compiling for an OpenMP target device. This
// is required before translating 'omp' dialect operations to LLVM IR.
``````````
</details>
https://github.com/llvm/llvm-project/pull/210049
More information about the flang-commits
mailing list