llvm/mlir/test/lib/Dialect/SCF/TestWhileOpBuilder.cpp

//===- TestWhileOpBuilder.cpp - Pass to test WhileOp::build ---------------===//
//
// 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 a pass to test some builder functions of WhileOp. It
// tests the regression explained in https://reviews.llvm.org/D142952, where
// a WhileOp::build overload crashed when fed with operands of different types
// than the result types.
//
// To test the build function, the pass copies each WhileOp found in the body
// of a FuncOp and adds an additional WhileOp with the same operands and result
// types (but dummy computations) using the builder in question.
//
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/Pass/Pass.h"

usingnamespacemlir;
usingnamespacemlir::arith;
usingnamespacemlir::scf;

namespace {
struct TestSCFWhileOpBuilderPass
    : public PassWrapper<TestSCFWhileOpBuilderPass,
                         OperationPass<func::FuncOp>> {};
} // namespace

namespace mlir {
namespace test {
void registerTestSCFWhileOpBuilderPass() {}
} // namespace test
} // namespace mlir