text: // Copyright 2021 The IREE Authors
  //
  // Licensed 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
  
  #include "iree/compiler/Dialect/Stream/IR/StreamDialect.h"
  
  #include "iree/compiler/Dialect/Stream/IR/StreamOps.h"
  #include "iree/compiler/Dialect/Stream/IR/StreamTypes.h"
  #include "llvm/Support/SourceMgr.h"
  #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
  #include "mlir/Dialect/StandardOps/IR/Ops.h"
  #include "mlir/Dialect/Tensor/IR/Tensor.h"
  #include "mlir/IR/Attributes.h"
  #include "mlir/IR/DialectImplementation.h"
  #include "mlir/IR/OpImplementation.h"
  #include "mlir/Parser.h"
  #include "mlir/Transforms/FoldUtils.h"
  #include "mlir/Transforms/InliningUtils.h"
  
  namespace mlir {
  namespace iree_compiler {
  namespace IREE {
  namespace Stream {
  
  namespace {
  
  // Used to control inlining behavior.
  struct StreamInlinerInterface : public DialectInlinerInterface {
    using DialectInlinerInterface::DialectInlinerInterface;
  
    bool isLegalToInline(Operation *call, Operation *callable,
                         bool wouldBeCloned) const final {
      // Sure!
      return true;
    }
    bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
                         BlockAndValueMapping &valueMapping) const final {
      // Sure!
      return true;
    }
  
    bool isLegalToInline(Operation *op, Region *dest, bool wouldBeCloned,
                         BlockAndValueMapping &valueMapping) const final {
      // Sure!
      return true;
    }
  };
  
  struct StreamFolderInterface : public DialectFoldInterface {
    using DialectFoldInterface::DialectFoldInterface;
  
    bool shouldMaterializeInto(Region *region) const override {
      // TODO(benvanik): redirect constants to the region scope when small.
      return false;
    }
  };
  
  }  // namespace
  
  StreamDialect::StreamDialect(MLIRContext *context)
      : Dialect(getDialectNamespace(), context, TypeID::get<StreamDialect>()) {
    registerAttributes();
    registerTypes();
  
  #define GET_OP_LIST
    addOperations<
  #include "iree/compiler/Dialect/Stream/IR/StreamOps.cpp.inc"
        >();
    addInterfaces<StreamInlinerInterface, StreamFolderInterface>();
  }
  
  Operation *StreamDialect::materializeConstant(OpBuilder &builder,
                                                Attribute value, Type type,
                                                Location loc) {
    if (mlir::ConstantOp::isBuildableWith(value, type)) {
      return builder.create<mlir::ConstantOp>(loc, type, value);
    } else if (arith::ConstantOp::isBuildableWith(value, type)) {
      return builder.create<arith::ConstantOp>(loc, type, value);
    } else if (value.isa<IREE::Stream::TimepointAttr>()) {
      return builder.create<IREE::Stream::TimepointImmediateOp>(loc);
    }
    return nullptr;
  }
  
  }  // namespace Stream
  }  // namespace IREE
  }  // namespace iree_compiler
  }  // namespace mlir
  