From 502ef8f19516337bb913bd62dee00620409c48f8 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Mon, 4 May 2020 17:48:02 -0700 Subject: [PATCH] Create skeleton for 'Basicpy' dialect. * It is time to start adding more python mechanisms. * Running into this for materializing slice() objects. --- .../npcomp/Dialect/Basicpy/BasicpyDialect.h | 31 ++++++++++++ .../npcomp/Dialect/Basicpy/BasicpyDialect.td | 47 +++++++++++++++++++ include/npcomp/Dialect/Basicpy/BasicpyOps.h | 31 ++++++++++++ include/npcomp/Dialect/Basicpy/BasicpyOps.td | 28 +++++++++++ include/npcomp/Dialect/Basicpy/CMakeLists.txt | 3 ++ include/npcomp/Dialect/CMakeLists.txt | 1 + lib/Dialect/Basicpy/BasicpyDialect.cpp | 35 ++++++++++++++ lib/Dialect/Basicpy/BasicpyOps.cpp | 23 +++++++++ lib/Dialect/Basicpy/CMakeLists.txt | 12 +++++ lib/Dialect/CMakeLists.txt | 1 + python/npcomp/mlir_init.cpp | 2 + tools/npcomp-opt/CMakeLists.txt | 1 + tools/npcomp-opt/npcomp-opt.cpp | 2 + 13 files changed, 217 insertions(+) create mode 100644 include/npcomp/Dialect/Basicpy/BasicpyDialect.h create mode 100644 include/npcomp/Dialect/Basicpy/BasicpyDialect.td create mode 100644 include/npcomp/Dialect/Basicpy/BasicpyOps.h create mode 100644 include/npcomp/Dialect/Basicpy/BasicpyOps.td create mode 100644 include/npcomp/Dialect/Basicpy/CMakeLists.txt create mode 100644 lib/Dialect/Basicpy/BasicpyDialect.cpp create mode 100644 lib/Dialect/Basicpy/BasicpyOps.cpp create mode 100644 lib/Dialect/Basicpy/CMakeLists.txt diff --git a/include/npcomp/Dialect/Basicpy/BasicpyDialect.h b/include/npcomp/Dialect/Basicpy/BasicpyDialect.h new file mode 100644 index 000000000..d8cef1fc6 --- /dev/null +++ b/include/npcomp/Dialect/Basicpy/BasicpyDialect.h @@ -0,0 +1,31 @@ +//===- BasicPyDialect.h - Basic Python --------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT_H +#define NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT_H + +#include "mlir/IR/Dialect.h" + +namespace mlir { +namespace NPCOMP { +namespace Basicpy { + +namespace BasicpyTypes { +enum Kind { + PlaceholderType = Type::FIRST_PRIVATE_EXPERIMENTAL_8_TYPE, + LAST_BASICPY_TYPE = PlaceholderType +}; +} // namespace BasicpyTypes + +#include "npcomp/Dialect/Basicpy/BasicpyOpsDialect.h.inc" + +} // namespace Basicpy +} // namespace NPCOMP +} // namespace mlir + +#endif // NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT_H diff --git a/include/npcomp/Dialect/Basicpy/BasicpyDialect.td b/include/npcomp/Dialect/Basicpy/BasicpyDialect.td new file mode 100644 index 000000000..dfd0e0781 --- /dev/null +++ b/include/npcomp/Dialect/Basicpy/BasicpyDialect.td @@ -0,0 +1,47 @@ +//===- BasicPyDialect.td - Basic python dialect ------------*- tablegen -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT +#define NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT + +include "mlir/IR/OpBase.td" + +//===----------------------------------------------------------------------===// +// Dialect definition +//===----------------------------------------------------------------------===// + +def Basicpy_Dialect : Dialect { + let name = "basicpy"; + let summary = "Basic Python dialect"; + let description = [{ + Core types and ops + }]; + let cppNamespace = "Basicpy"; +} + +//===----------------------------------------------------------------------===// +// Op templates +//===----------------------------------------------------------------------===// + +class Basicpy_Op traits = []> : + Op { + let parser = [{ return parse$cppClass(parser, &result); }]; + let printer = [{ return print$cppClass(p, *this); }]; +} + +//===----------------------------------------------------------------------===// +// Dialect types +//===----------------------------------------------------------------------===// + + +//===----------------------------------------------------------------------===// +// Type predicates +//===----------------------------------------------------------------------===// + + +#endif // NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT diff --git a/include/npcomp/Dialect/Basicpy/BasicpyOps.h b/include/npcomp/Dialect/Basicpy/BasicpyOps.h new file mode 100644 index 000000000..918a0f4f2 --- /dev/null +++ b/include/npcomp/Dialect/Basicpy/BasicpyOps.h @@ -0,0 +1,31 @@ +//===- BasicPyOps.h - Basic python ops --------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef NPCOMP_DIALECT_BASICPY_BASICPY_OPS_H +#define NPCOMP_DIALECT_BASICPY_BASICPY_OPS_H + +#include "mlir/IR/Attributes.h" +#include "mlir/IR/Dialect.h" +#include "mlir/IR/FunctionSupport.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/IR/StandardTypes.h" +#include "mlir/IR/SymbolTable.h" +#include "mlir/Interfaces/SideEffects.h" + +namespace mlir { +namespace NPCOMP { +namespace Basicpy { + +#define GET_OP_CLASSES +#include "npcomp/Dialect/Basicpy/BasicpyOps.h.inc" + +} // namespace Basicpy +} // namespace NPCOMP +} // namespace mlir + +#endif // NPCOMP_DIALECT_BASICPY_BASICPY_OPS_H diff --git a/include/npcomp/Dialect/Basicpy/BasicpyOps.td b/include/npcomp/Dialect/Basicpy/BasicpyOps.td new file mode 100644 index 000000000..a5fdb2125 --- /dev/null +++ b/include/npcomp/Dialect/Basicpy/BasicpyOps.td @@ -0,0 +1,28 @@ +//===- BasicPyOps.td - Basic Python ops --------------------*- tablegen -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef NPCOMP_DIALECT_BASICPY_BASICPY_OPS +#define NPCOMP_DIALECT_BASICPY_BASICPY_OPS + +include "BasicpyDialect.td" +include "mlir/Interfaces/SideEffects.td" +include "mlir/IR/SymbolInterfaces.td" + +def Basicpy_ExampleOp : Basicpy_Op<"example", []> { + let summary = "Move along, nothing to see here."; + let description = [{ + }]; + let arguments = (ins); + let results = (outs); + let assemblyFormat = [{ + attr-dict + }]; +} + + +#endif // NPCOMP_DIALECT_BASICPY_BASICPY_OPS diff --git a/include/npcomp/Dialect/Basicpy/CMakeLists.txt b/include/npcomp/Dialect/Basicpy/CMakeLists.txt new file mode 100644 index 000000000..db7f66f67 --- /dev/null +++ b/include/npcomp/Dialect/Basicpy/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(BasicpyOps basicpy) +add_mlir_doc(BasicpyDialect -gen-dialect-doc BasicpyDialect Basicpy/) +add_mlir_doc(BasicpyOps -gen-op-doc BasicpyOps Basicpy/) diff --git a/include/npcomp/Dialect/CMakeLists.txt b/include/npcomp/Dialect/CMakeLists.txt index 0323a7a11..7b66420bd 100644 --- a/include/npcomp/Dialect/CMakeLists.txt +++ b/include/npcomp/Dialect/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(Basicpy) add_subdirectory(Numpy) diff --git a/lib/Dialect/Basicpy/BasicpyDialect.cpp b/lib/Dialect/Basicpy/BasicpyDialect.cpp new file mode 100644 index 000000000..40f2f3195 --- /dev/null +++ b/lib/Dialect/Basicpy/BasicpyDialect.cpp @@ -0,0 +1,35 @@ +//===- BasicpyDialect.cpp - Basic python 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 +// +//===----------------------------------------------------------------------===// + +#include "npcomp/Dialect/Basicpy/BasicpyDialect.h" +#include "mlir/IR/DialectImplementation.h" +#include "npcomp/Dialect/Basicpy/BasicpyOps.h" + +using namespace mlir; +using namespace mlir::NPCOMP::Basicpy; + +BasicpyDialect::BasicpyDialect(MLIRContext *context) + : Dialect(getDialectNamespace(), context) { + addOperations< +#define GET_OP_LIST +#include "npcomp/Dialect/Basicpy/BasicpyOps.cpp.inc" + >(); + // addTypes(); +} + +// Type BasicpyDialect::parseType(DialectAsmParser &parser) const { +// parser.emitError(parser.getNameLoc(), "unknown numpy type"); +// return Type(); +// } + +// void BasicpyDialect::printType(Type type, DialectAsmPrinter &os) const { +// switch (type.getKind()) { +// default: +// llvm_unreachable("unexpected 'basicpy' type kind"); +// } +// } diff --git a/lib/Dialect/Basicpy/BasicpyOps.cpp b/lib/Dialect/Basicpy/BasicpyOps.cpp new file mode 100644 index 000000000..9c16dd9c2 --- /dev/null +++ b/lib/Dialect/Basicpy/BasicpyOps.cpp @@ -0,0 +1,23 @@ +//===- BasicpyOps.cpp - Core numpy dialect ops --------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#include "npcomp/Dialect/Basicpy/BasicpyOps.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/FunctionImplementation.h" +#include "mlir/IR/OpImplementation.h" +#include "npcomp/Dialect/Basicpy/BasicpyDialect.h" + +namespace mlir { +namespace NPCOMP { +namespace Basicpy { +#define GET_OP_CLASSES +#include "npcomp/Dialect/Basicpy/BasicpyOps.cpp.inc" +} // namespace Basicpy +} // namespace NPCOMP +} // namespace mlir diff --git a/lib/Dialect/Basicpy/CMakeLists.txt b/lib/Dialect/Basicpy/CMakeLists.txt new file mode 100644 index 000000000..43017deeb --- /dev/null +++ b/lib/Dialect/Basicpy/CMakeLists.txt @@ -0,0 +1,12 @@ +add_mlir_dialect_library(NPCOMPBasicpyDialect + BasicpyDialect.cpp + BasicpyOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/npcomp/Dialect/Basicpy + + DEPENDS + MLIRBasicpyOpsIncGen +) + +target_link_libraries(NPCOMPBasicpyDialect PUBLIC MLIRIR) diff --git a/lib/Dialect/CMakeLists.txt b/lib/Dialect/CMakeLists.txt index 0323a7a11..7b66420bd 100644 --- a/lib/Dialect/CMakeLists.txt +++ b/lib/Dialect/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(Basicpy) add_subdirectory(Numpy) diff --git a/python/npcomp/mlir_init.cpp b/python/npcomp/mlir_init.cpp index ef20308ba..d2be4b54d 100644 --- a/python/npcomp/mlir_init.cpp +++ b/python/npcomp/mlir_init.cpp @@ -9,6 +9,7 @@ #include "mlir/IR/Dialect.h" #include "mlir/InitAllDialects.h" #include "mlir/Pass/PassManager.h" +#include "npcomp/Dialect/Basicpy/BasicpyDialect.h" #include "npcomp/Dialect/Numpy/NumpyDialect.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/PrettyStackTrace.h" @@ -36,6 +37,7 @@ bool npcompMlirInitialize() { ::mlir::registerAllDialects(); // Local registration. + registerDialect(); registerDialect(); return true; diff --git a/tools/npcomp-opt/CMakeLists.txt b/tools/npcomp-opt/CMakeLists.txt index c7a04e3cf..27ab8079d 100644 --- a/tools/npcomp-opt/CMakeLists.txt +++ b/tools/npcomp-opt/CMakeLists.txt @@ -5,6 +5,7 @@ set(LIBS ${conversion_libs} MLIROptLib NPCOMPNumpyDialect + NPCOMPBasicpyDialect ) add_llvm_executable(npcomp-opt npcomp-opt.cpp) diff --git a/tools/npcomp-opt/npcomp-opt.cpp b/tools/npcomp-opt/npcomp-opt.cpp index 3279573c7..44e5e634e 100644 --- a/tools/npcomp-opt/npcomp-opt.cpp +++ b/tools/npcomp-opt/npcomp-opt.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/ToolOutputFile.h" +#include "npcomp/Dialect/Basicpy/BasicpyDialect.h" #include "npcomp/Dialect/Numpy/NumpyDialect.h" static llvm::cl::opt inputFilename(llvm::cl::Positional, @@ -60,6 +61,7 @@ int main(int argc, char **argv) { mlir::registerAllDialects(); mlir::registerAllPasses(); + mlir::registerDialect(); mlir::registerDialect(); // TODO: Register standalone passes here.