================ @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements pass that inlines CIR operations regions into the parent +// function region. +// +//===----------------------------------------------------------------------===// + +#include "PassDetail.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/IR/PatternMatch.h" +#include "mlir/Support/LogicalResult.h" +#include "mlir/Transforms/DialectConversion.h" +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" +#include "clang/CIR/Dialect/IR/CIRDialect.h" +#include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/MissingFeatures.h" + +using namespace mlir; +using namespace cir; + +namespace { + +struct CIRFlattenCFGPass : public CIRFlattenCFGBase<CIRFlattenCFGPass> { + + CIRFlattenCFGPass() = default; + void runOnOperation() override; +}; + +class CIRScopeOpFlattening : public mlir::OpRewritePattern<cir::ScopeOp> { +public: + using OpRewritePattern<cir::ScopeOp>::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(cir::ScopeOp scopeOp, + mlir::PatternRewriter &rewriter) const override { + mlir::OpBuilder::InsertionGuard guard(rewriter); + mlir::Location loc = scopeOp.getLoc(); + + // Empty scope: just remove it. + // TODO: Remove this logic once CIR uses MLIR infrastructure to remove + // trivially dead operations ---------------- bcardosolopes wrote:
Context for other reviewers: MLIR canonicalizer is too aggressive and we need to either (a) make sure all our ops are modeling side-effects and/or (b) have more options in the canonicalizer in MLIR to temper aggressiveness level. https://github.com/llvm/llvm-project/pull/130648 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits