/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|*                                                                            *|
|* Rewriters                                                                  *|
|*                                                                            *|
|* Automatically generated file, do not edit!                                 *|
|* From: CanonicalizationPatterns.td                                          *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

static ::llvm::LogicalResult static_dag_matcher_0(::mlir::PatternRewriter &rewriter, ::mlir::Operation *op0, ::llvm::SmallVector<::mlir::Operation *, 4> &tblgen_ops, ::mlir::Operation::operand_range &arg, ::fir::ConvertOp &res, ::fir::ConvertOp &irm) {
  (void)tblgen_ops;
  auto castedOp1 = ::llvm::dyn_cast<::fir::ConvertOp>(op0); (void)castedOp1;
  if (!(castedOp1)){
    return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
      diag << "castedOp1 is not ::fir::ConvertOp type";
    });
  }
  res = castedOp1;
  {
    auto *op2 = (*castedOp1.getODSOperands(0).begin()).getDefiningOp();
    if (!(op2)){
      return rewriter.notifyMatchFailure(castedOp1, [&](::mlir::Diagnostic &diag) {
        diag << "There's no operation that defines operand 0 of castedOp1";
      });
    }
    auto castedOp2 = ::llvm::dyn_cast<::fir::ConvertOp>(op2); (void)castedOp2;
    if (!(castedOp2)){
      return rewriter.notifyMatchFailure(op2, [&](::mlir::Diagnostic &diag) {
        diag << "castedOp2 is not ::fir::ConvertOp type";
      });
    }
    irm = castedOp2;
    arg = castedOp2.getODSOperands(0);
    tblgen_ops.push_back(op2);
  }
  return ::mlir::success();
}

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:127
*/
struct ChainedPointerConvertsPattern : public ::mlir::RewritePattern {
  ChainedPointerConvertsPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {"fir.convert"}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::fir::ConvertOp irm;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    if(::mlir::failed(static_dag_matcher_0(rewriter, op0, tblgen_ops, arg, res, irm))) {
      return ::mlir::failure();
    }
    auto castedOp0 = ::llvm::dyn_cast_or_null<::fir::ConvertOp>(op0); (void)castedOp0;
    if (!((fir::ConvertOp::isPointerCompatible((*arg.begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg' failed to satisfy constraint: ''";
      });
    }
    if (!((fir::ConvertOp::isPointerCompatible((*irm.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'irm' failed to satisfy constraint: ''";
      });
    }
    if (!((fir::ConvertOp::isPointerCompatible((*res.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;
    ::fir::ConvertOp tblgen_ConvertOp_0;
    {
      ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values;
      ::fir::ConvertOp::Properties tblgen_props; (void)tblgen_props;
      tblgen_values.push_back((*arg.begin()));
      ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types;
      for (auto v: castedOp0.getODSResults(0)) {
        tblgen_types.push_back(v.getType());
      }
      tblgen_ConvertOp_0 = ::fir::ConvertOp::create(rewriter, odsLoc, tblgen_types, tblgen_values, tblgen_props);
    }

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConvertOp_0.getODSResults(0) }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:94
*/
struct CombineConvertOptPattern : public ::mlir::RewritePattern {
  CombineConvertOptPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::fir::ConvertOp irm;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    if(::mlir::failed(static_dag_matcher_0(rewriter, op0, tblgen_ops, arg, res, irm))) {
      return ::mlir::failure();
    }
    auto castedOp0 = ::llvm::dyn_cast_or_null<::fir::ConvertOp>(op0); (void)castedOp0;
    if (!((mlir::isa<mlir::IntegerType>((*res.getODSResults(0).begin()).getType()) && mlir::isa<mlir::IntegerType>((*arg.begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, arg' failed to satisfy constraint: ''";
      });
    }
    if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, arg' failed to satisfy constraint: ''";
      });
    }
    if (!((mlir::isa<mlir::IntegerType>((*arg.begin()).getType()) && mlir::isa<mlir::IntegerType>((*irm.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg, irm' failed to satisfy constraint: ''";
      });
    }
    if (!(((*arg.begin()).getType().getIntOrFloatBitWidth() <= (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg, irm' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:101
*/
struct CombineConvertTruncOptPattern : public ::mlir::RewritePattern {
  CombineConvertTruncOptPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {"fir.convert"}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::fir::ConvertOp irm;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    if(::mlir::failed(static_dag_matcher_0(rewriter, op0, tblgen_ops, arg, res, irm))) {
      return ::mlir::failure();
    }
    auto castedOp0 = ::llvm::dyn_cast_or_null<::fir::ConvertOp>(op0); (void)castedOp0;
    if (!((mlir::isa<mlir::IntegerType>((*res.getODSResults(0).begin()).getType()) && mlir::isa<mlir::IntegerType>((*arg.begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, arg' failed to satisfy constraint: ''";
      });
    }
    if (!(((*res.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() < (*arg.begin()).getType().getIntOrFloatBitWidth()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, arg' failed to satisfy constraint: ''";
      });
    }
    if (!((mlir::isa<mlir::IntegerType>((*arg.begin()).getType()) && mlir::isa<mlir::IntegerType>((*irm.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg, irm' failed to satisfy constraint: ''";
      });
    }
    if (!(((*arg.begin()).getType().getIntOrFloatBitWidth() <= (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg, irm' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;
    ::fir::ConvertOp tblgen_ConvertOp_0;
    {
      ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values;
      ::fir::ConvertOp::Properties tblgen_props; (void)tblgen_props;
      tblgen_values.push_back((*arg.begin()));
      ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types;
      for (auto v: castedOp0.getODSResults(0)) {
        tblgen_types.push_back(v.getType());
      }
      tblgen_ConvertOp_0 = ::fir::ConvertOp::create(rewriter, odsLoc, tblgen_types, tblgen_values, tblgen_props);
    }

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConvertOp_0.getODSResults(0) }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:72
*/
struct ConvertAscendingIndexOptPattern : public ::mlir::RewritePattern {
  ConvertAscendingIndexOptPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {"fir.convert"}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::fir::ConvertOp irm;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    if(::mlir::failed(static_dag_matcher_0(rewriter, op0, tblgen_ops, arg, res, irm))) {
      return ::mlir::failure();
    }
    auto castedOp0 = ::llvm::dyn_cast_or_null<::fir::ConvertOp>(op0); (void)castedOp0;
    if (!((mlir::isa<mlir::IndexType>((*res.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res' failed to satisfy constraint: ''";
      });
    }
    if (!((mlir::isa<mlir::IntegerType>((*irm.getODSResults(0).begin()).getType()) && mlir::isa<mlir::IntegerType>((*arg.begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'irm, arg' failed to satisfy constraint: ''";
      });
    }
    if (!(((*arg.begin()).getType().getIntOrFloatBitWidth() <= (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg, irm' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;
    ::fir::ConvertOp tblgen_ConvertOp_0;
    {
      ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values;
      ::fir::ConvertOp::Properties tblgen_props; (void)tblgen_props;
      tblgen_values.push_back((*arg.begin()));
      ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types;
      for (auto v: castedOp0.getODSResults(0)) {
        tblgen_types.push_back(v.getType());
      }
      tblgen_ConvertOp_0 = ::fir::ConvertOp::create(rewriter, odsLoc, tblgen_types, tblgen_values, tblgen_props);
    }

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConvertOp_0.getODSResults(0) }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:64
*/
struct ConvertConvertOptPattern : public ::mlir::RewritePattern {
  ConvertConvertOptPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {"fir.convert"}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::fir::ConvertOp irm;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    if(::mlir::failed(static_dag_matcher_0(rewriter, op0, tblgen_ops, arg, res, irm))) {
      return ::mlir::failure();
    }
    auto castedOp0 = ::llvm::dyn_cast_or_null<::fir::ConvertOp>(op0); (void)castedOp0;
    if (!((((mlir::isa<mlir::IntegerType>((*res.getODSResults(0).begin()).getType()) &&   mlir::isa<mlir::IntegerType>((*irm.getODSResults(0).begin()).getType()) &&   mlir::isa<mlir::IntegerType>((*arg.begin()).getType()) &&   (*res.getODSResults(0).begin()).getType().isUnsignedInteger() == (*irm.getODSResults(0).begin()).getType().isUnsignedInteger() &&   (*irm.getODSResults(0).begin()).getType().isUnsignedInteger() == (*arg.begin()).getType().isUnsignedInteger()) ||  (mlir::isa<mlir::FloatType>((*res.getODSResults(0).begin()).getType()) &&   mlir::isa<mlir::FloatType>((*irm.getODSResults(0).begin()).getType()) &&   mlir::isa<mlir::FloatType>((*arg.begin()).getType()))) && (((*res.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() <=   (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() &&   (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() <=   (*arg.begin()).getType().getIntOrFloatBitWidth()) ||  ((*res.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() >=   (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() &&   (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() >=   (*arg.begin()).getType().getIntOrFloatBitWidth()))))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, irm, arg' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;
    ::fir::ConvertOp tblgen_ConvertOp_0;
    {
      ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values;
      ::fir::ConvertOp::Properties tblgen_props; (void)tblgen_props;
      tblgen_values.push_back((*arg.begin()));
      ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types;
      for (auto v: castedOp0.getODSResults(0)) {
        tblgen_types.push_back(v.getType());
      }
      tblgen_ConvertOp_0 = ::fir::ConvertOp::create(rewriter, odsLoc, tblgen_types, tblgen_values, tblgen_props);
    }

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConvertOp_0.getODSResults(0) }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:81
*/
struct ConvertDescendingIndexOptPattern : public ::mlir::RewritePattern {
  ConvertDescendingIndexOptPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {"fir.convert"}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::fir::ConvertOp irm;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    if(::mlir::failed(static_dag_matcher_0(rewriter, op0, tblgen_ops, arg, res, irm))) {
      return ::mlir::failure();
    }
    auto castedOp0 = ::llvm::dyn_cast_or_null<::fir::ConvertOp>(op0); (void)castedOp0;
    if (!((mlir::isa<mlir::IndexType>((*arg.begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'arg' failed to satisfy constraint: ''";
      });
    }
    if (!((mlir::isa<mlir::IntegerType>((*irm.getODSResults(0).begin()).getType()) && mlir::isa<mlir::IntegerType>((*res.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'irm, res' failed to satisfy constraint: ''";
      });
    }
    if (!(((*res.getODSResults(0).begin()).getType().getIntOrFloatBitWidth() <= (*irm.getODSResults(0).begin()).getType().getIntOrFloatBitWidth()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, irm' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;
    ::fir::ConvertOp tblgen_ConvertOp_0;
    {
      ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values;
      ::fir::ConvertOp::Properties tblgen_props; (void)tblgen_props;
      tblgen_values.push_back((*arg.begin()));
      ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types;
      for (auto v: castedOp0.getODSResults(0)) {
        tblgen_types.push_back(v.getType());
      }
      tblgen_ConvertOp_0 = ::fir::ConvertOp::create(rewriter, odsLoc, tblgen_types, tblgen_values, tblgen_props);
    }

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConvertOp_0.getODSResults(0) }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:113
*/
struct ForwardConstantConvertPattern : public ::mlir::RewritePattern {
  ForwardConstantConvertPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 2, context, {}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::TypedAttr attr;
    ::mlir::arith::ConstantOp cnt;
    ::fir::ConvertOp res;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    auto castedOp0 = ::llvm::dyn_cast<::fir::ConvertOp>(op0); (void)castedOp0;
    res = castedOp0;
    {
      auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp();
      if (!(op1)){
        return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) {
          diag << "There's no operation that defines operand 0 of castedOp0";
        });
      }
      auto castedOp1 = ::llvm::dyn_cast<::mlir::arith::ConstantOp>(op1); (void)castedOp1;
      if (!(castedOp1)){
        return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) {
          diag << "castedOp1 is not ::mlir::arith::ConstantOp type";
        });
      }
      cnt = castedOp1;
      {
        [[maybe_unused]] auto tblgen_attr = castedOp1.getProperties().getValue();
        if (!(tblgen_attr)){
          return rewriter.notifyMatchFailure(castedOp1, [&](::mlir::Diagnostic &diag) {
            diag << "expected op 'arith.constant' to have attribute 'value' of type '::mlir::TypedAttr'";
          });
        }
        attr = tblgen_attr;
      }
      tblgen_ops.push_back(op1);
    }
    if (!((mlir::isa<mlir::IndexType>((*res.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res' failed to satisfy constraint: ''";
      });
    }
    if (!((fir::isa_integer((*cnt.getODSResults(0).begin()).getType())))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'cnt' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;
    auto nativeVar_0 = mlir::arith::ConstantOp::create(rewriter, odsLoc, rewriter.getIndexType(), rewriter.getIndexAttr(mlir::dyn_cast<mlir::IntegerAttr>(attr).getInt())); (void)nativeVar_0;

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ {nativeVar_0} }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

/* Generated from:
    /__w/TheRock/TheRock/compiler/amd-llvm/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td:88
*/
struct RedundantConvertOptPattern : public ::mlir::RewritePattern {
  RedundantConvertOptPattern(::mlir::MLIRContext *context)
      : ::mlir::RewritePattern("fir.convert", 1, context, {}) {}
  ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0,
      ::mlir::PatternRewriter &rewriter) const override {
    // Variables for capturing values and attributes used while creating ops
    ::mlir::Operation::operand_range arg(op0->getOperands());
    ::fir::ConvertOp res;
    ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;

    // Match
    tblgen_ops.push_back(op0);
    auto castedOp0 = ::llvm::dyn_cast<::fir::ConvertOp>(op0); (void)castedOp0;
    res = castedOp0;
    arg = castedOp0.getODSOperands(0);
    if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){
      return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) {
        diag << "entities 'res, arg' failed to satisfy constraint: ''";
      });
    }

    // Rewrite
    auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc()}); (void)odsLoc;
    ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;

    for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) {
      tblgen_repl_values.push_back(v);
    }

    rewriter.replaceOp(op0, tblgen_repl_values);
    return ::mlir::success();
  }
};

[[maybe_unused]] void populateWithGenerated(::mlir::RewritePatternSet &patterns) {
  patterns.add<ChainedPointerConvertsPattern>(patterns.getContext());
  patterns.add<CombineConvertOptPattern>(patterns.getContext());
  patterns.add<CombineConvertTruncOptPattern>(patterns.getContext());
  patterns.add<ConvertAscendingIndexOptPattern>(patterns.getContext());
  patterns.add<ConvertConvertOptPattern>(patterns.getContext());
  patterns.add<ConvertDescendingIndexOptPattern>(patterns.getContext());
  patterns.add<ForwardConstantConvertPattern>(patterns.getContext());
  patterns.add<RedundantConvertOptPattern>(patterns.getContext());
}
