================ @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits