[flang-commits] [clang] [flang] [flang][OpenMP] Add -f[no]-openmp-simd (PR #150269)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Wed Aug 6 02:33:34 PDT 2025
================
@@ -67,6 +81,28 @@ class SimdOnlyConversionPattern : public mlir::RewritePattern {
LLVM_DEBUG(llvm::dbgs() << "SimdOnlyPass matched OpenMP op:\n");
LLVM_DEBUG(op->dump());
+ auto eraseUnlessUsedBySimd = [&](mlir::Operation *ompOp,
+ mlir::StringAttr name) {
+ if (auto uses =
+ mlir::SymbolTable::getSymbolUses(name, op->getParentOp())) {
+ for (auto &use : *uses)
+ if (mlir::isa<mlir::omp::SimdOp>(use.getUser()))
+ return rewriter.notifyMatchFailure(op,
+ "Op used by a simd construct");
+ }
+ rewriter.eraseOp(ompOp);
+ return mlir::success();
+ };
+
+ if (auto ompOp = mlir::dyn_cast<mlir::omp::PrivateClauseOp>(op))
+ return eraseUnlessUsedBySimd(ompOp, ompOp.getSymNameAttr());
+ if (auto ompOp = mlir::dyn_cast<mlir::omp::DeclareReductionOp>(op))
+ return eraseUnlessUsedBySimd(ompOp, ompOp.getSymNameAttr());
+ if (auto ompOp = mlir::dyn_cast<mlir::omp::CriticalDeclareOp>(op))
+ return eraseUnlessUsedBySimd(ompOp, ompOp.getSymNameAttr());
+ if (auto ompOp = mlir::dyn_cast<mlir::omp::DeclareMapperOp>(op))
+ return eraseUnlessUsedBySimd(ompOp, ompOp.getSymNameAttr());
----------------
tblah wrote:
I don't think these two can be used inside of simd, so it would be cheaper to just erase them. I think it is worth special-casing this because `SymbolTable::getSymbolUses` is expensive (it walks all operations).
https://github.com/llvm/llvm-project/pull/150269
More information about the flang-commits
mailing list