================ @@ -0,0 +1,360 @@ +#include "flang/Optimizer/Builder/FIRBuilder.h" +#include "flang/Optimizer/Transforms/Utils.h" +#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/IR/IRMapping.h" +#include "mlir/Pass/Pass.h" +#include "mlir/Transforms/DialectConversion.h" +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" +#include <llvm/Support/Debug.h> +#include <mlir/IR/MLIRContext.h> +#include <mlir/IR/Operation.h> +#include <mlir/IR/PatternMatch.h> +#include <mlir/Support/LLVM.h> + +namespace flangomp { +#define GEN_PASS_DEF_SIMDONLYPASS +#include "flang/Optimizer/OpenMP/Passes.h.inc" +} // namespace flangomp + +namespace { + +#define DEBUG_TYPE "omp-simd-only-pass" + +class SimdOnlyConversionPattern : public mlir::RewritePattern { +public: + SimdOnlyConversionPattern(mlir::MLIRContext *ctx) + : mlir::RewritePattern(MatchAnyOpTypeTag{}, 1, ctx) {} + + mlir::LogicalResult + matchAndRewrite(mlir::Operation *op, + mlir::PatternRewriter &rewriter) const override { + if (op->getDialect()->getNamespace() != + mlir::omp::OpenMPDialect::getDialectNamespace()) + return rewriter.notifyMatchFailure(op, "Not an OpenMP op"); + + if (auto simdOp = mlir::dyn_cast<mlir::omp::SimdOp>(op)) { + // Remove the composite attr given that the op will no longer be composite + if (simdOp.isComposite()) { + simdOp.setComposite(false); + return mlir::success(); + } + + return rewriter.notifyMatchFailure(op, "Op is a plain SimdOp"); + } + + if (op->getParentOfType<mlir::omp::SimdOp>()) + return rewriter.notifyMatchFailure(op, "Op is nested under a SimdOp"); + + if (!mlir::isa<mlir::func::FuncOp>(op->getParentOp()) && ---------------- mrkajetanp wrote:
This is just so that the greedy rewriter doesn't match a yield or terminator that's _not_ top level, since those are meant to be handled by the logic for the operations they actually belong to. I added the top-level check so that if there is a top-level yield or terminator it will hit the "unhandled operation" error at the end of the pass instead of just failing the verifier later on. There is never supposed to be one, unless there's a bug in the rest of the logic. 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