2020-04-27 08:20:58 +08:00
|
|
|
//===- NumpyDialect.h - Core numpy dialect ----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// This file is 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-06-10 10:22:24 +08:00
|
|
|
#ifndef NPCOMP_DIALECT_NUMPY_IR_NUMPY_DIALECT_H
|
|
|
|
#define NPCOMP_DIALECT_NUMPY_IR_NUMPY_DIALECT_H
|
2020-04-27 08:20:58 +08:00
|
|
|
|
2020-12-12 06:43:38 +08:00
|
|
|
#include "mlir/IR/BuiltinTypes.h"
|
2020-04-27 08:20:58 +08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
2020-07-05 07:40:02 +08:00
|
|
|
#include "npcomp/Typing/Analysis/CPA/Interfaces.h"
|
2020-04-27 08:20:58 +08:00
|
|
|
|
|
|
|
namespace mlir {
|
2020-04-30 08:10:10 +08:00
|
|
|
namespace NPCOMP {
|
2020-04-30 09:20:42 +08:00
|
|
|
namespace Numpy {
|
|
|
|
|
2020-06-29 08:37:20 +08:00
|
|
|
namespace detail {
|
|
|
|
struct NdArrayTypeStorage;
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
/// The singleton type representing an unknown dtype.
|
2020-07-03 02:24:05 +08:00
|
|
|
class AnyDtypeType : public Type::TypeBase<AnyDtypeType, Type, TypeStorage> {
|
2020-04-30 09:20:42 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
|
|
|
|
2020-08-28 06:09:10 +08:00
|
|
|
static AnyDtypeType get(MLIRContext *context) { return Base::get(context); }
|
2020-04-30 09:20:42 +08:00
|
|
|
};
|
2020-04-27 08:20:58 +08:00
|
|
|
|
2020-06-29 08:37:20 +08:00
|
|
|
class NdArrayType
|
2020-07-04 07:38:10 +08:00
|
|
|
: public Type::TypeBase<NdArrayType, Type, detail::NdArrayTypeStorage,
|
2020-07-04 09:16:34 +08:00
|
|
|
NPCOMPTypingTypeMapInterface::Trait> {
|
2020-06-29 08:37:20 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-07-06 08:34:03 +08:00
|
|
|
|
|
|
|
/// Constructs an NdArray with a dtype and no shape. Setting the dtype
|
|
|
|
/// to !basicpy.UnknownType will print as ?.
|
|
|
|
static NdArrayType get(Type dtype,
|
|
|
|
llvm::Optional<ArrayRef<int64_t>> shape = llvm::None);
|
|
|
|
|
2020-10-16 09:28:30 +08:00
|
|
|
/// Helper that gets an equivalent NdArrayType from a ShapedType.
|
|
|
|
static NdArrayType getFromShapedType(ShapedType shapedType);
|
|
|
|
|
2020-07-06 08:34:03 +08:00
|
|
|
/// Returns whether the dtype is a concrete type (versus
|
|
|
|
/// !basicpy.UnknownType).
|
2020-07-04 07:38:10 +08:00
|
|
|
bool hasKnownDtype();
|
2020-06-30 06:27:39 +08:00
|
|
|
Type getDtype();
|
2020-07-04 07:38:10 +08:00
|
|
|
|
2020-07-06 08:34:03 +08:00
|
|
|
/// If the shape has been partially specified, this will have a value.
|
|
|
|
/// unknown dimensions are -1.
|
|
|
|
llvm::Optional<ArrayRef<int64_t>> getOptionalShape();
|
|
|
|
|
2020-07-09 13:51:54 +08:00
|
|
|
/// Converts to an equivalent TensorType.
|
|
|
|
TensorType toTensorType();
|
|
|
|
|
2020-07-04 07:38:10 +08:00
|
|
|
// CPA::TypeMapInterface methods.
|
|
|
|
Typing::CPA::TypeNode *mapToCPAType(Typing::CPA::Context &context);
|
2020-06-29 08:37:20 +08:00
|
|
|
};
|
|
|
|
|
2020-04-30 09:20:42 +08:00
|
|
|
} // namespace Numpy
|
2020-04-30 08:10:10 +08:00
|
|
|
} // namespace NPCOMP
|
2020-04-27 08:20:58 +08:00
|
|
|
} // namespace mlir
|
|
|
|
|
2020-09-17 06:52:15 +08:00
|
|
|
#include "npcomp/Dialect/Numpy/IR/NumpyOpsDialect.h.inc"
|
|
|
|
|
2020-06-10 10:22:24 +08:00
|
|
|
#endif // NPCOMP_DIALECT_NUMPY_IR_NUMPY_DIALECT_H
|