mirror of https://github.com/llvm/torch-mlir
Create skeleton for 'Basicpy' dialect.
* It is time to start adding more python mechanisms. * Running into this for materializing slice() objects.pull/1/head
parent
ebb5bcf6af
commit
502ef8f195
|
@ -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
|
|
@ -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<string mnemonic, list<OpTrait> traits = []> :
|
||||||
|
Op<Basicpy_Dialect, mnemonic, traits> {
|
||||||
|
let parser = [{ return parse$cppClass(parser, &result); }];
|
||||||
|
let printer = [{ return print$cppClass(p, *this); }];
|
||||||
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Dialect types
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Type predicates
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
#endif // NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT
|
|
@ -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
|
|
@ -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
|
|
@ -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/)
|
|
@ -1 +1,2 @@
|
||||||
|
add_subdirectory(Basicpy)
|
||||||
add_subdirectory(Numpy)
|
add_subdirectory(Numpy)
|
||||||
|
|
|
@ -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<AnyDtypeType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
// }
|
||||||
|
// }
|
|
@ -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
|
|
@ -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)
|
|
@ -1 +1,2 @@
|
||||||
|
add_subdirectory(Basicpy)
|
||||||
add_subdirectory(Numpy)
|
add_subdirectory(Numpy)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "mlir/IR/Dialect.h"
|
#include "mlir/IR/Dialect.h"
|
||||||
#include "mlir/InitAllDialects.h"
|
#include "mlir/InitAllDialects.h"
|
||||||
#include "mlir/Pass/PassManager.h"
|
#include "mlir/Pass/PassManager.h"
|
||||||
|
#include "npcomp/Dialect/Basicpy/BasicpyDialect.h"
|
||||||
#include "npcomp/Dialect/Numpy/NumpyDialect.h"
|
#include "npcomp/Dialect/Numpy/NumpyDialect.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/PrettyStackTrace.h"
|
#include "llvm/Support/PrettyStackTrace.h"
|
||||||
|
@ -36,6 +37,7 @@ bool npcompMlirInitialize() {
|
||||||
::mlir::registerAllDialects();
|
::mlir::registerAllDialects();
|
||||||
|
|
||||||
// Local registration.
|
// Local registration.
|
||||||
|
registerDialect<NPCOMP::Basicpy::BasicpyDialect>();
|
||||||
registerDialect<NPCOMP::Numpy::NumpyDialect>();
|
registerDialect<NPCOMP::Numpy::NumpyDialect>();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -5,6 +5,7 @@ set(LIBS
|
||||||
${conversion_libs}
|
${conversion_libs}
|
||||||
MLIROptLib
|
MLIROptLib
|
||||||
NPCOMPNumpyDialect
|
NPCOMPNumpyDialect
|
||||||
|
NPCOMPBasicpyDialect
|
||||||
)
|
)
|
||||||
add_llvm_executable(npcomp-opt npcomp-opt.cpp)
|
add_llvm_executable(npcomp-opt npcomp-opt.cpp)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/ToolOutputFile.h"
|
#include "llvm/Support/ToolOutputFile.h"
|
||||||
|
|
||||||
|
#include "npcomp/Dialect/Basicpy/BasicpyDialect.h"
|
||||||
#include "npcomp/Dialect/Numpy/NumpyDialect.h"
|
#include "npcomp/Dialect/Numpy/NumpyDialect.h"
|
||||||
|
|
||||||
static llvm::cl::opt<std::string> inputFilename(llvm::cl::Positional,
|
static llvm::cl::opt<std::string> inputFilename(llvm::cl::Positional,
|
||||||
|
@ -60,6 +61,7 @@ int main(int argc, char **argv) {
|
||||||
mlir::registerAllDialects();
|
mlir::registerAllDialects();
|
||||||
mlir::registerAllPasses();
|
mlir::registerAllPasses();
|
||||||
|
|
||||||
|
mlir::registerDialect<mlir::NPCOMP::Basicpy::BasicpyDialect>();
|
||||||
mlir::registerDialect<mlir::NPCOMP::Numpy::NumpyDialect>();
|
mlir::registerDialect<mlir::NPCOMP::Numpy::NumpyDialect>();
|
||||||
// TODO: Register standalone passes here.
|
// TODO: Register standalone passes here.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue