diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..ae79b502 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.13.4) +project(mlir-goes-relational LANGUAGES CXX C) + +set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") + +find_package(MLIR REQUIRED CONFIG) + +message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") + +set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin) +set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib) +set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) + +list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") +list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") +include(TableGen) +include(AddLLVM) +include(AddMLIR) +include(HandleLLVMOptions) + +include_directories(${LLVM_INCLUDE_DIRS}) +include_directories(${MLIR_INCLUDE_DIRS}) +include_directories(${PROJECT_SOURCE_DIR}/include) +include_directories(${PROJECT_BINARY_DIR}/include) +link_directories(${LLVM_BUILD_LIBRARY_DIR}) +add_definitions(${LLVM_DEFINITIONS}) +set(LLVM_LINK_COMPONENTS + Support + Core + ) + +add_subdirectory(include) +add_subdirectory(lib) + + + +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) + +set(LIBS + ${dialect_libs} + ${conversion_libs} + ${translation_libs} + MLIROptLib + MLIRRelAlg + MLIRDB + MLIRIR + MLIRParser + MLIRPass + + MLIRTranslation + MLIRSupport + MLIRAnalysis + MLIRCallInterfaces + MLIRSideEffectInterfaces + MLIRTransforms + ) + + +add_llvm_executable(mlir-db-opt mlir-opt.cpp) +target_link_libraries(mlir-db-opt PUBLIC ${LIBS}) \ No newline at end of file diff --git a/examples/example.mlir b/examples/example.mlir new file mode 100644 index 00000000..2134f64a --- /dev/null +++ b/examples/example.mlir @@ -0,0 +1,12 @@ +module @testmodule { + func @main() -> !db.int { + %0 = db.constant( 2 ) : !db.int + %1 = relalg.basetable @abctable {table_identifier = "abc"} columns: {col1 => @col1({name = "abc", type = !db.int}), col2 => @col2({name = "dupp", type = !db.bool})} + %2 = relalg.selection %1 (%arg0: !relalg.tuple){ + %3 = relalg.getattr %arg0, @abctable::@col1 : !db.int + %4 = db.compare "eq", %0 :!db.int,%3:!db.int + relalg.return %4 : !db.bool + } + return %0 : !db.int + } +} \ No newline at end of file diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 00000000..967b5b0f --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(mlir) \ No newline at end of file diff --git a/include/mlir/CMakeLists.txt b/include/mlir/CMakeLists.txt new file mode 100644 index 00000000..e6f347c8 --- /dev/null +++ b/include/mlir/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Dialect) \ No newline at end of file diff --git a/include/mlir/Dialect/CMakeLists.txt b/include/mlir/Dialect/CMakeLists.txt new file mode 100644 index 00000000..0fe35cdc --- /dev/null +++ b/include/mlir/Dialect/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(RelAlg) +add_subdirectory(DB) \ No newline at end of file diff --git a/include/mlir/Dialect/DB/CMakeLists.txt b/include/mlir/Dialect/DB/CMakeLists.txt new file mode 100644 index 00000000..7d59dce8 --- /dev/null +++ b/include/mlir/Dialect/DB/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) \ No newline at end of file diff --git a/include/mlir/Dialect/DB/IR/CMakeLists.txt b/include/mlir/Dialect/DB/IR/CMakeLists.txt new file mode 100644 index 00000000..7957da90 --- /dev/null +++ b/include/mlir/Dialect/DB/IR/CMakeLists.txt @@ -0,0 +1,17 @@ + +set(LLVM_TARGET_DEFINITIONS DBOps.td) +mlir_tablegen(DBOpsDialect.h.inc -gen-dialect-decls) +mlir_tablegen(DBOps.h.inc -gen-op-decls) +mlir_tablegen(DBOps.cpp.inc -gen-op-defs) +mlir_tablegen(DBOpsEnums.h.inc -gen-enum-decls) +mlir_tablegen(DBOpsEnums.cpp.inc -gen-enum-defs) +mlir_tablegen(DBOpsTypes.h.inc --gen-typedef-decls) +mlir_tablegen(DBOpsTypes.cpp.inc --gen-typedef-defs) + +set(LLVM_TARGET_DEFINITIONS DBInterfaces.td) +mlir_tablegen(DBOpsInterfaces.h.inc -gen-op-interface-decls) +mlir_tablegen(DBOpsInterfaces.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(MLIRDBOpsIncGen) +add_mlir_doc(DBDialect -gen-dialect-doc DBDialect DB/) +add_mlir_doc(DBOps -gen-op-doc DBOps DB/) + diff --git a/include/mlir/Dialect/DB/IR/DBDialect.h b/include/mlir/Dialect/DB/IR/DBDialect.h new file mode 100644 index 00000000..29da721f --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBDialect.h @@ -0,0 +1,8 @@ +#ifndef DB_DBDIALECT_H +#define DB_DBDIALECT_H + +#include "mlir/IR/Dialect.h" + +#include "mlir/Dialect/DB/IR/DBOpsDialect.h.inc" + +#endif// DB_DBDIALECT_H diff --git a/include/mlir/Dialect/DB/IR/DBInterfaces.td b/include/mlir/Dialect/DB/IR/DBInterfaces.td new file mode 100644 index 00000000..49d03dd9 --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBInterfaces.td @@ -0,0 +1,6 @@ +#ifndef Interfaces +#define Interfaces +include "mlir/IR/OpBase.td" + + +#endif// Interfaces diff --git a/include/mlir/Dialect/DB/IR/DBOps.h b/include/mlir/Dialect/DB/IR/DBOps.h new file mode 100644 index 00000000..d096bb56 --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBOps.h @@ -0,0 +1,21 @@ +#ifndef DB_DBOPS_H +#define DB_DBOPS_H + + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" + +#include "mlir/Dialect/DB/IR/DBOpsEnums.h" +#include "mlir/Dialect/DB/IR/DBTypes.h" + +#include "mlir/Dialect/DB/IR/DBOpsInterfaces.h" + + +#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/IR/Builders.h" + +#define GET_OP_CLASSES +#include "mlir/Dialect/DB/IR/DBOps.h.inc" + +#endif// DB_DBOPS_H diff --git a/include/mlir/Dialect/DB/IR/DBOps.td b/include/mlir/Dialect/DB/IR/DBOps.td new file mode 100644 index 00000000..fe7d2712 --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBOps.td @@ -0,0 +1,136 @@ +#ifndef OPS +#define OPS + +include "mlir/IR/OpBase.td" +include "mlir/Interfaces/SideEffectInterfaces.td" +include "mlir/Interfaces/LoopLikeInterface.td" +include "DBInterfaces.td" + +//===----------------------------------------------------------------------===// +// DB dialect definition. +//===----------------------------------------------------------------------===// + +def DB_Dialect : Dialect { +let name = "db"; +let summary = "A db out-of-tree MLIR dialect."; +let description = [{ +This dialect is an example of an out-of-tree MLIR dialect designed to + illustrate the basic setup required to develop MLIR-based tools without + working inside of the LLVM source tree. +}]; +let cppNamespace = "::mlir::db"; +} + +class DB_Op traits = []> : +Op{ +let printer = [{ return ::print(p, *this); }]; +let parser = [{ return ::parse$cppClass(parser, result); }]; +} + +class DB_Type : TypeDef { + let mnemonic = typeMnemonic; +} +def DBType : Type()">,"DB dialect type">; + + +def DB_BoolType : DB_Type<"Bool","bool"> { + let summary = "database boolean type"; +} +def DB_IntType : DB_Type<"Int","int"> { +let summary = "database integer type"; +} + +def DB_ConstantOp : DB_Op<"constant", + [ConstantLike, NoSideEffect]> { +let summary = "constant"; + + +let arguments = (ins AnyAttr:$value); +let results = (outs DBType); + +let extraClassDeclaration = [{ +Attribute getValue() { return (*this)->getAttr("value"); } +}]; + +} + +class DB_BinaryOp traits = []> : +Op,Arguments<(ins DBType:$lhs, DBType:$rhs)> { +let results = (outs AnyType:$result); +let parser = [{ +return impl::parseOneResultSameOperandTypeOp(parser, result); +}]; + +let printer = [{ +return printStandardBinaryOp(this->getOperation(), p); +}]; +} +class DB_UnaryOp traits = []> : +Op,Arguments<(ins DBType:$val)> { +let results = (outs AnyType:$result); +let parser = [{ +return impl::parseOneResultSameOperandTypeOp(parser, result); +}]; + +let printer = [{ +return printStandardBinaryOp(this->getOperation(), p); +}]; +} +def DB_AddOp : DB_BinaryOp<"add"> {} +def DB_SubOp : DB_BinaryOp<"sub"> {} +def DB_MulOp : DB_BinaryOp<"mul"> {} +def DB_DivOp : DB_BinaryOp<"div"> {} +def DB_ModOp : DB_BinaryOp<"mod"> {} +def DB_NegOp : DB_BinaryOp<"neg"> {} + +def DB_CMP_P_EQ : I64EnumAttrCase<"eq", 0>; +def DB_CMP_P_NE : I64EnumAttrCase<"ne", 1>; +def DB_CMP_P_SLT : I64EnumAttrCase<"slt", 2>; +def DB_CMP_P_SLE : I64EnumAttrCase<"sle", 3>; +def DB_CMP_P_SGT : I64EnumAttrCase<"sgt", 4>; +def DB_CMP_P_SGE : I64EnumAttrCase<"sge", 5>; +def DB_CMP_P_ULT : I64EnumAttrCase<"ult", 6>; +def DB_CMP_P_ULE : I64EnumAttrCase<"ule", 7>; +def DB_CMP_P_UGT : I64EnumAttrCase<"ugt", 8>; +def DB_CMP_P_UGE : I64EnumAttrCase<"uge", 9>; + +def DB_CmpPredicateAttr : I64EnumAttr< + "DBCmpPredicate", "", + [DB_CMP_P_EQ, DB_CMP_P_NE, DB_CMP_P_SLT, DB_CMP_P_SLE, DB_CMP_P_SGT, + DB_CMP_P_SGE, DB_CMP_P_ULT, DB_CMP_P_ULE, DB_CMP_P_UGT, DB_CMP_P_UGE]> { +let cppNamespace = "::mlir::db"; +} + +def DB_CmpOp : DB_Op<"compare", + [NoSideEffect, SameTypeOperands]> { +let summary = "integer comparison operation"; + +let arguments = (ins +DB_CmpPredicateAttr:$predicate, +DBType:$lhs, +DBType:$rhs +); +let results = (outs DB_BoolType:$result); + +let builders = [ +OpBuilderDAG<(ins "CmpIPredicate":$predicate, "Value":$lhs, +"Value":$rhs), [{ +::buildDBCmpOp($_builder, $_state, predicate, lhs, rhs); +}]>]; + +let extraClassDeclaration = [{ +static StringRef getPredicateAttrName() { return "predicate"; } +static CmpIPredicate getPredicateByName(StringRef name); + +CmpIPredicate getPredicate() { + return (CmpIPredicate)(*this)->getAttrOfType( + getPredicateAttrName()).getInt(); +} +}]; +let assemblyFormat = "$predicate `,` $lhs `:` type($lhs) `,` $rhs `:` type($rhs) attr-dict"; +} +#endif// OPS diff --git a/include/mlir/Dialect/DB/IR/DBOpsEnums.h b/include/mlir/Dialect/DB/IR/DBOpsEnums.h new file mode 100644 index 00000000..5fa7c85f --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBOpsEnums.h @@ -0,0 +1,11 @@ +#ifndef DB_DBENUMS_H +#define DB_DBENUMS_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + + +#define GET_OP_CLASSES +#include "mlir/Dialect/DB/IR/DBOpsEnums.h.inc" + +#endif// DB_DBENUMS_H diff --git a/include/mlir/Dialect/DB/IR/DBOpsInterfaces.h b/include/mlir/Dialect/DB/IR/DBOpsInterfaces.h new file mode 100644 index 00000000..1f44df50 --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBOpsInterfaces.h @@ -0,0 +1,11 @@ +#ifndef DB_DBInterfaces +#define DB_DBInterfaces + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + + +#define GET_OP_CLASSES +#include "mlir/Dialect/DB/IR/DBOpsInterfaces.h.inc" + +#endif// DB_DBInterfaces diff --git a/include/mlir/Dialect/DB/IR/DBType.h b/include/mlir/Dialect/DB/IR/DBType.h new file mode 100644 index 00000000..af27e3f2 --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBType.h @@ -0,0 +1,11 @@ +#ifndef MLIR_GOES_RELATIONAL_DBTYPE_H +#define MLIR_GOES_RELATIONAL_DBTYPE_H + +namespace mlir::db{ +class DBType : public mlir::Type { +public: + using Type::Type; +}; +} + +#endif // MLIR_GOES_RELATIONAL_DBTYPE_H diff --git a/include/mlir/Dialect/DB/IR/DBTypes.h b/include/mlir/Dialect/DB/IR/DBTypes.h new file mode 100644 index 00000000..fbf0277a --- /dev/null +++ b/include/mlir/Dialect/DB/IR/DBTypes.h @@ -0,0 +1,11 @@ +#ifndef DB_DBTYPES_H +#define DB_DBTYPES_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/Dialect/DB/IR/DBType.h" + +#define GET_TYPEDEF_CLASSES +#include "mlir/Dialect/DB/IR/DBOpsTypes.h.inc" + +#endif// DB_DBTYPES_H diff --git a/include/mlir/Dialect/DB/Passes.h b/include/mlir/Dialect/DB/Passes.h new file mode 100644 index 00000000..9cba108a --- /dev/null +++ b/include/mlir/Dialect/DB/Passes.h @@ -0,0 +1,13 @@ +#ifndef MLIR_DB_PASSES_H +#define MLIR_DB_PASSES_H + +#include "mlir/Pass/Pass.h" +#include + +namespace mlir { + namespace db { + std::unique_ptr createLowerToLLVMPass(db::Database &db); + }// end namespace db +}// end namespace mlir + +#endif// MLIR_DB_PASSES_H \ No newline at end of file diff --git a/include/mlir/Dialect/RelAlg/CMakeLists.txt b/include/mlir/Dialect/RelAlg/CMakeLists.txt new file mode 100644 index 00000000..7d59dce8 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) \ No newline at end of file diff --git a/include/mlir/Dialect/RelAlg/IR/CMakeLists.txt b/include/mlir/Dialect/RelAlg/IR/CMakeLists.txt new file mode 100644 index 00000000..e1249428 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/CMakeLists.txt @@ -0,0 +1,16 @@ + +set(LLVM_TARGET_DEFINITIONS RelAlgOps.td) +mlir_tablegen(RelAlgOpsDialect.h.inc -gen-dialect-decls) +mlir_tablegen(RelAlgOps.h.inc -gen-op-decls) +mlir_tablegen(RelAlgOps.cpp.inc -gen-op-defs) +mlir_tablegen(RelAlgOpsEnums.h.inc -gen-enum-decls) +mlir_tablegen(RelAlgOpsEnums.cpp.inc -gen-enum-defs) +mlir_tablegen(RelAlgOpsTypes.h.inc --gen-typedef-decls) +mlir_tablegen(RelAlgOpsTypes.cpp.inc --gen-typedef-defs) +set(LLVM_TARGET_DEFINITIONS RelAlgInterfaces.td) +mlir_tablegen(RelAlgOpsInterfaces.h.inc -gen-op-interface-decls) +mlir_tablegen(RelAlgOpsInterfaces.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(MLIRRelAlgOpsIncGen) +add_mlir_doc(RelAlgDialect -gen-dialect-doc RelAlgDialect RelAlg/) +add_mlir_doc(RelAlgOps -gen-op-doc RelAlgOps RelAlg/) + diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgDialect.h b/include/mlir/Dialect/RelAlg/IR/RelAlgDialect.h new file mode 100644 index 00000000..1c4c789d --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgDialect.h @@ -0,0 +1,8 @@ +#ifndef RelAlg_RelAlgDIALECT_H +#define RelAlg_RelAlgDIALECT_H + +#include "mlir/IR/Dialect.h" + +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsDialect.h.inc" + +#endif// RelAlg_RelAlgDIALECT_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgInterfaces.td b/include/mlir/Dialect/RelAlg/IR/RelAlgInterfaces.td new file mode 100644 index 00000000..49d03dd9 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgInterfaces.td @@ -0,0 +1,6 @@ +#ifndef Interfaces +#define Interfaces +include "mlir/IR/OpBase.td" + + +#endif// Interfaces diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgOps.h b/include/mlir/Dialect/RelAlg/IR/RelAlgOps.h new file mode 100644 index 00000000..edae2563 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgOps.h @@ -0,0 +1,23 @@ +#ifndef RelAlg_RelAlgOPS_H +#define RelAlg_RelAlgOPS_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" + +#include "mlir/Dialect/DB/IR/DBType.h" +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsEnums.h" +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsInterfaces.h" +#include "mlir/Dialect/RelAlg/IR/RelAlgTypes.h" +#include "mlir/Dialect/RelAlg/IR/RelationalAttribute.h" +#include "mlir/Dialect/RelAlg/IR/RelationalAttributeDefAttr.h" +#include "mlir/Dialect/RelAlg/IR/RelationalAttributeRefAttr.h" + + +#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/IR/Builders.h" + +#define GET_OP_CLASSES +#include "mlir/Dialect/RelAlg/IR/RelAlgOps.h.inc" + +#endif// RelAlg_RelAlgOPS_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgOps.td b/include/mlir/Dialect/RelAlg/IR/RelAlgOps.td new file mode 100644 index 00000000..62e6efec --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgOps.td @@ -0,0 +1,92 @@ +#ifndef OPS +#define OPS + +include "mlir/IR/OpBase.td" +include "mlir/Interfaces/SideEffectInterfaces.td" +include "mlir/Interfaces/LoopLikeInterface.td" +include "mlir/Interfaces/ControlFlowInterfaces.td" +include "mlir/IR/SymbolInterfaces.td" + +include "RelAlgInterfaces.td" + +//===----------------------------------------------------------------------===// +// realg dialect definition. +//===----------------------------------------------------------------------===// + +def RelAlg_Dialect : Dialect { +let name = "relalg"; +let summary = "A dialect for relational algebra"; +let cppNamespace = "::mlir::relalg"; +} + +//===----------------------------------------------------------------------===// +// Base relAlg operation definition. +//===----------------------------------------------------------------------===// + +class RelAlg_Op traits = []> : +Op{ +let printer = [{ return ::print(p, *this); }]; +let parser = [{ return ::parse$cppClass(parser, result); }]; +} + +def DBType : Type()">,"DB dialect type">; + +def RelAlg_Relation : TypeDef { +let summary = "relation type"; +} +def RelAlg_Tuple : TypeDef { +let summary = "tuple type"; +} +def RelationalAttributeDefAttr : +DialectAttr()">, "AttributeDefAttr">{ +let storageType = "::mlir::relalg::RelationalAttributeDefAttr"; +let returnType = "::mlir::relalg::RelationalAttributeDefAttr"; +let convertFromStorage = "$_self"; +} +def RelationalAttributeRefAttr : +DialectAttr()">, "AttributeRefAttr">{ +let storageType = "::mlir::relalg::RelationalAttributeRefAttr"; +let returnType = "::mlir::relalg::RelationalAttributeRefAttr"; +let convertFromStorage = "$_self"; +} + +def RelAlg_ReturnOp : RelAlg_Op<"return", [NoSideEffect, ReturnLike, Terminator, + // ParentOneOf<[", ForOp", "ParallelOp","WhileOp"]> + ]> { +let summary = "loop yield and termination operation"; + +let arguments = (ins Variadic:$results); +let builders = [OpBuilderDAG<(ins), [{ /* nothing to do */ }]>]; + +let assemblyFormat = +[{ attr-dict ($results^ `:` type($results))? }]; + +} + + + +def BaseTableOp : RelAlg_Op<"basetable", +[SingleBlockImplicitTerminator<"relalg::ReturnOp">,RecursiveSideEffects]> { +let summary = "base table operation"; +let arguments = (ins SymbolNameAttr:$sym_name, StrAttr: $table_identifier, DictionaryAttr: $columns); +let results = (outs RelAlg_Relation:$result); +} + +def GetAttrOp : RelAlg_Op<"getattr"> { +let summary = "get attribute operation"; +let arguments = (ins RelationalAttributeRefAttr:$attr, RelAlg_Tuple:$tuple); +let results = (outs DBType : $res); +} + + +def SelectionOp : RelAlg_Op<"selection",[RecursiveSideEffects]> { +let summary = "selection operation"; +let arguments = (ins RelAlg_Relation:$rel); +let results = (outs RelAlg_Relation:$result); +let regions = (region SizedRegion<1>:$predicate); +} + + +#endif// OPS diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgOpsEnums.h b/include/mlir/Dialect/RelAlg/IR/RelAlgOpsEnums.h new file mode 100644 index 00000000..09dd9668 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgOpsEnums.h @@ -0,0 +1,10 @@ +#ifndef RelAlg_RelAlgENUMS_H +#define RelAlg_RelAlgENUMS_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + +#define GET_OP_CLASSES +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsEnums.h.inc" + +#endif// RelAlg_RelAlgENUMS_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgOpsInterfaces.h b/include/mlir/Dialect/RelAlg/IR/RelAlgOpsInterfaces.h new file mode 100644 index 00000000..431ab216 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgOpsInterfaces.h @@ -0,0 +1,11 @@ +#ifndef RelAlg_RelAlgInterfaces +#define RelAlg_RelAlgInterfaces + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + + +#define GET_OP_CLASSES +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsInterfaces.h.inc" + +#endif// RelAlg_RelAlgInterfaces diff --git a/include/mlir/Dialect/RelAlg/IR/RelAlgTypes.h b/include/mlir/Dialect/RelAlg/IR/RelAlgTypes.h new file mode 100644 index 00000000..50aa36ef --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelAlgTypes.h @@ -0,0 +1,10 @@ +#ifndef RelAlg_RelAlgTYPES_H +#define RelAlg_RelAlgTYPES_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + +#define GET_TYPEDEF_CLASSES +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsTypes.h.inc" + +#endif// RelAlg_RelAlgTYPES_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelationalAttribute.h b/include/mlir/Dialect/RelAlg/IR/RelationalAttribute.h new file mode 100644 index 00000000..8dfaf429 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelationalAttribute.h @@ -0,0 +1,16 @@ +#ifndef MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTE_H +#define MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTE_H +#include "mlir/Dialect/DB/IR/DBType.h" + +namespace mlir::relalg { +class RelationalAttribute { + +public: + RelationalAttribute(StringRef name, mlir::db::DBType type) + : name(name), type(type) {} + std::string name; + mlir::db::DBType type; +}; +} // namespace mlir::relalg + +#endif // MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTE_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelationalAttributeAttrDefStorage.h b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeAttrDefStorage.h new file mode 100644 index 00000000..a6ce020e --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeAttrDefStorage.h @@ -0,0 +1,30 @@ +// +// Created by michael on 13.03.21. +// + +#ifndef MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEATTRDEFSTORAGE_H +#define MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEATTRDEFSTORAGE_H +namespace mlir::relalg { +struct RelationalAttributeAttrDefStorage : public AttributeStorage { + RelationalAttributeAttrDefStorage( + StringRef name, std::shared_ptr relationalAttribute) + : name(name), relationalAttribute(relationalAttribute) {} + + using KeyTy = std::pair>; + + bool operator==(const KeyTy &key) const { + return key.first == name && key.second == relationalAttribute; + } + static llvm::hash_code hashKey(const KeyTy &key) { + return llvm::hash_combine(key.first, key.second.get()); + } + static RelationalAttributeAttrDefStorage * + construct(AttributeStorageAllocator &allocator, const KeyTy &key) { + return new (allocator.allocate()) + RelationalAttributeAttrDefStorage(key.first, key.second); + } + std::string name; + std::shared_ptr relationalAttribute; +}; +} // namespace mlir::relalg +#endif // MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEATTRDEFSTORAGE_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelationalAttributeAttrRefStorage.h b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeAttrRefStorage.h new file mode 100644 index 00000000..a889c058 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeAttrRefStorage.h @@ -0,0 +1,30 @@ +// +// Created by michael on 13.03.21. +// + +#ifndef MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEATTRREFSTORAGE_H +#define MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEATTRREFSTORAGE_H +namespace mlir::relalg { +struct RelationalAttributeAttrRefStorage : public AttributeStorage { + RelationalAttributeAttrRefStorage( + SymbolRefAttr name, std::shared_ptr relationalAttribute) + : name(name), relationalAttribute(relationalAttribute) {} + + using KeyTy = std::pair>; + + bool operator==(const KeyTy &key) const { + return key.first == name && key.second == relationalAttribute; + } + static llvm::hash_code hashKey(const KeyTy &key) { + return llvm::hash_combine(key.first, key.second.get()); + } + static RelationalAttributeAttrRefStorage * + construct(AttributeStorageAllocator &allocator, const KeyTy &key) { + return new (allocator.allocate()) + RelationalAttributeAttrRefStorage(key.first, key.second); + } + SymbolRefAttr name; + std::shared_ptr relationalAttribute; +}; +} // namespace mlir::relalg +#endif // MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEATTRREFSTORAGE_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelationalAttributeDefAttr.h b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeDefAttr.h new file mode 100644 index 00000000..4cf4f4e6 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeDefAttr.h @@ -0,0 +1,35 @@ +// +// Created by michael on 13.03.21. +// + +#ifndef MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEDEFATTR_H +#define MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEDEFATTR_H +#include "mlir/Dialect/RelAlg/IR/RelationalAttribute.h" +#include "mlir/Dialect/RelAlg/IR/RelationalAttributeAttrDefStorage.h" + +#include "mlir/IR/OpDefinition.h" + +namespace mlir { +namespace relalg { + +class RelationalAttributeDefAttr + : public Attribute::AttrBase { +public: + using Base::Base; + static RelationalAttributeDefAttr + get(MLIRContext *context,StringRef attributeName, + std::shared_ptr relationalAttribute) { + return Base::get(context, attributeName,relationalAttribute); + } + const StringRef getName() { + return getImpl()->name; + } + const RelationalAttribute &getRelationalAttribute() { + return *getImpl()->relationalAttribute; + } +}; +} // namespace relalg +} // namespace mlir + +#endif // MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEDEFATTR_H diff --git a/include/mlir/Dialect/RelAlg/IR/RelationalAttributeRefAttr.h b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeRefAttr.h new file mode 100644 index 00000000..735b3df7 --- /dev/null +++ b/include/mlir/Dialect/RelAlg/IR/RelationalAttributeRefAttr.h @@ -0,0 +1,35 @@ +// +// Created by michael on 13.03.21. +// + +#ifndef MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEREFATTR_H +#define MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEREFATTR_H +#include "mlir/Dialect/RelAlg/IR/RelationalAttribute.h" +#include "mlir/Dialect/RelAlg/IR/RelationalAttributeAttrRefStorage.h" + +#include "mlir/IR/OpDefinition.h" + +namespace mlir { +namespace relalg { + +class RelationalAttributeRefAttr + : public Attribute::AttrBase { +public: + using Base::Base; + static RelationalAttributeRefAttr + get(MLIRContext *context,SymbolRefAttr attributeName, + std::shared_ptr relationalAttribute) { + return Base::get(context, attributeName,relationalAttribute); + } + const SymbolRefAttr getName() { + return getImpl()->name; + } + const RelationalAttribute &getRelationalAttribute() { + return *getImpl()->relationalAttribute; + } +}; +} // namespace relalg +} // namespace mlir + +#endif // MLIR_GOES_RELATIONAL_RELATIONALATTRIBUTEREFATTR_H diff --git a/include/mlir/Dialect/RelAlg/Passes.h b/include/mlir/Dialect/RelAlg/Passes.h new file mode 100644 index 00000000..3936188b --- /dev/null +++ b/include/mlir/Dialect/RelAlg/Passes.h @@ -0,0 +1,13 @@ +#ifndef MLIR_DB_PASSES_H +#define MLIR_DB_PASSES_H + +#include "mlir/Pass/Pass.h" +#include + +namespace mlir { + namespace relalg { + std::unique_ptr createTestPass(); + }// end namespace db +}// end namespace mlir + +#endif// MLIR_DB_PASSES_H \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 00000000..564e59f6 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(RelAlg) +add_subdirectory(DB) diff --git a/lib/DB/CMakeLists.txt b/lib/DB/CMakeLists.txt new file mode 100644 index 00000000..ca9464f4 --- /dev/null +++ b/lib/DB/CMakeLists.txt @@ -0,0 +1,13 @@ +add_mlir_dialect_library(MLIRDB + DBDialect.cpp + DBOps.cpp + DBOpsEnums.cpp + ADDITIONAL_HEADER_DIRS + ../../include/mlir/Dialect/DB + + DEPENDS + MLIRDBOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR + ) diff --git a/lib/DB/DBDialect.cpp b/lib/DB/DBDialect.cpp new file mode 100644 index 00000000..d0813ce1 --- /dev/null +++ b/lib/DB/DBDialect.cpp @@ -0,0 +1,38 @@ +#include "mlir/Dialect/DB/IR/DBDialect.h" +#include "mlir/Dialect/DB/IR/DBOps.h" +#include "mlir/IR/DialectImplementation.h" +using namespace mlir; +using namespace mlir::db; + +void DBDialect::initialize() { + addOperations< +#define GET_OP_LIST +#include "mlir/Dialect/DB/IR/DBOps.cpp.inc" + >(); + addTypes< +#define GET_TYPEDEF_LIST +#include "mlir/Dialect/DB/IR/DBOpsTypes.cpp.inc" + >(); +} + +/// Parse a type registered to this dialect. +::mlir::Type DBDialect::parseType(::mlir::DialectAsmParser &parser) const { + if(!parser.parseOptionalKeyword("bool")){ + return mlir::db::BoolType::get(parser.getBuilder().getContext()); + } + if(!parser.parseOptionalKeyword("int")){ + return mlir::db::IntType::get(parser.getBuilder().getContext()); + } + return mlir::Type(); +} + +/// Print a type registered to this dialect. +void DBDialect::printType(::mlir::Type type, + ::mlir::DialectAsmPrinter &os) const { + if(type.isa()){ + os<<"bool"; + }else if(type.isa()){ + os<<"int"; + } + +} \ No newline at end of file diff --git a/lib/DB/DBOps.cpp b/lib/DB/DBOps.cpp new file mode 100644 index 00000000..e4a86d23 --- /dev/null +++ b/lib/DB/DBOps.cpp @@ -0,0 +1,72 @@ +#include "mlir/Dialect/DB/IR/DBOps.h" +#include "mlir/Dialect/DB/IR/DBDialect.h" +#include "mlir/IR/OpImplementation.h" +#include + +#include +using namespace mlir; +static void print(OpAsmPrinter &p, db::ConstantOp &op) { + p << op.getOperationName(); + p.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"}); + + if (op->getAttrs().size() > 1) + p << ' '; + p << "( "; + p.printAttributeWithoutType(op.getValue()); + p << " )"; + p << " : " << op.getType(); +} + +static ParseResult parseConstantOp(OpAsmParser &parser, + OperationState &result) { + Attribute valueAttr; + if (parser.parseLParen() || + parser.parseAttribute(valueAttr, "value", result.attributes) || + parser.parseRParen()) + return failure(); + + // If the attribute is a symbol reference, then we expect a trailing type. + Type type; + if (parser.parseColon()) { + return failure(); + } + if (parser.parseType(type)) { + return failure(); + } + // Add the attribute type to the list. + return parser.addTypeToList(type, result.types); +} + +/// A custom binary operation printer that omits the "std." prefix from the +/// operation names. +static void printStandardBinaryOp(Operation *op, OpAsmPrinter &p) { + assert(op->getNumOperands() == 2 && "binary op should have two operands"); + assert(op->getNumResults() == 1 && "binary op should have one result"); + + // If not all the operand and result types are the same, just use the + // generic assembly form to avoid omitting information in printing. + auto resultType = op->getResult(0).getType(); + if (op->getOperand(0).getType() != resultType || + op->getOperand(1).getType() != resultType) { + p.printGenericOp(op); + return; + } + + p << op->getName() << ' ' + << op->getOperand(0) << ", " << op->getOperand(1); + p.printOptionalAttrDict(op->getAttrs()); + + // Now we can output only one type for all operands and the result. + p << " : " << op->getResult(0).getType(); +} + +static void buildDBCmpOp(OpBuilder &build, OperationState &result, + CmpIPredicate predicate, Value lhs, Value rhs) { + result.addOperands({lhs, rhs}); + result.types.push_back(mlir::db::BoolType::get(build.getContext())); + result.addAttribute(CmpIOp::getPredicateAttrName(), + build.getI64IntegerAttr(static_cast(predicate))); +} +#define GET_OP_CLASSES +#include "mlir/Dialect/DB/IR/DBOps.cpp.inc" +#include "mlir/Dialect/DB/IR/DBOpsInterfaces.cpp.inc" diff --git a/lib/DB/DBOpsEnums.cpp b/lib/DB/DBOpsEnums.cpp new file mode 100644 index 00000000..5b9e21cb --- /dev/null +++ b/lib/DB/DBOpsEnums.cpp @@ -0,0 +1,6 @@ +#include "mlir/Dialect/DB/IR/DBDialect.h" +#include "mlir/Dialect/DB/IR/DBOps.h" +#include "mlir/IR/OpImplementation.h" + +#define GET_OP_CLASSES +#include "mlir/Dialect/DB/IR/DBOpsEnums.cpp.inc" diff --git a/lib/RelAlg/CMakeLists.txt b/lib/RelAlg/CMakeLists.txt new file mode 100644 index 00000000..99f12284 --- /dev/null +++ b/lib/RelAlg/CMakeLists.txt @@ -0,0 +1,15 @@ +add_mlir_dialect_library(MLIRRelAlg + RelAlgDialect.cpp + RelAlgOps.cpp + RelAlgOpsEnums.cpp + TestPass.cpp + ADDITIONAL_HEADER_DIRS + ../../include/mlir/Dialect/RelAlg + + DEPENDS + MLIRRelAlgOpsIncGen + MLIRDBOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR + ) diff --git a/lib/RelAlg/RelAlgDialect.cpp b/lib/RelAlg/RelAlgDialect.cpp new file mode 100644 index 00000000..d4720f84 --- /dev/null +++ b/lib/RelAlg/RelAlgDialect.cpp @@ -0,0 +1,64 @@ +#include "mlir/Dialect/RelAlg/IR/RelAlgDialect.h" + +#include "mlir/Dialect/RelAlg/IR/RelAlgOps.h" +#include "mlir/IR/DialectImplementation.h" +#include "mlir/IR/OpImplementation.h" +#include "mlir/Dialect/DB/IR/DBTypes.h" + +using namespace mlir; +using namespace mlir::relalg; +void RelAlgDialect::initialize() { + addOperations< +#define GET_OP_LIST +#include "mlir/Dialect/RelAlg/IR/RelAlgOps.cpp.inc" + >(); + addTypes< +#define GET_TYPEDEF_LIST +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsTypes.cpp.inc" + >(); + addAttributes(); + addAttributes(); + +} + +/// Parse a type registered to this dialect. +::mlir::Type RelAlgDialect::parseType(::mlir::DialectAsmParser &parser) const { + if (!parser.parseOptionalKeyword("relation")) { + return mlir::relalg::RelationType::get(parser.getBuilder().getContext()); + } + if (!parser.parseOptionalKeyword("tuple")) { + return mlir::relalg::TupleType::get(parser.getBuilder().getContext()); + } + return mlir::Type(); +} + +/// Print a type registered to this dialect. +void RelAlgDialect::printType(::mlir::Type type, + ::mlir::DialectAsmPrinter &os) const { + if (type.isa()) { + os << "relation"; + } + if (type.isa()) { + os << "tuple"; + } +} +::mlir::Attribute +RelAlgDialect::parseAttribute(::mlir::DialectAsmParser &parser, + ::mlir::Type type) const { + + if (!parser.parseOptionalKeyword("attr_def") ) { + StringRef name; + if(parser.parseLBrace()||parser.parseOptionalString(&name)||parser.parseRBrace()) + return mlir::Attribute(); + return mlir::relalg::RelationalAttributeDefAttr::get( + parser.getBuilder().getContext(), name, + std::make_shared("",mlir::db::BoolType::get(parser.getBuilder().getContext()))); + } + return mlir::Attribute(); +} +void RelAlgDialect::printAttribute(::mlir::Attribute attr, + ::mlir::DialectAsmPrinter &os) const { + if(auto attr_def=attr.dyn_cast_or_null()){ + os<<"attr_def(\\\""< + +#include + +using namespace mlir; +static void print(OpAsmPrinter &p, relalg::BaseTableOp &op) { + p << op.getOperationName(); + p << " "; + p.printSymbolName(op.sym_name()); + if (op->getAttrs().size() > 1) + p << ' '; + p.printOptionalAttrDict(op->getAttrs(), + /*elidedAttrs=*/{"sym_name", "columns"}); + p << " columns: {"; + auto first = true; + for (auto mapping : op.columns()) { + auto [column_name, attr] = mapping; + auto relation_def_attr = + attr.dyn_cast_or_null(); + if (first) { + first = false; + } else { + p << ", "; + } + p << column_name << " => "; + p.printSymbolName(relation_def_attr.getName()); + std::vector rel_attr_def_props; + MLIRContext *context = op->getContext(); + const mlir::relalg::RelationalAttribute &relationalAttribute = + relation_def_attr.getRelationalAttribute(); + rel_attr_def_props.push_back( + {mlir::Identifier::get("name", context), + mlir::StringAttr::get(context, relationalAttribute.name)}); + rel_attr_def_props.push_back( + {mlir::Identifier::get("type", context), + mlir::TypeAttr::get(relationalAttribute.type)}); + + p << "(" << mlir::DictionaryAttr::get(context, rel_attr_def_props) << ")"; + } + p << "}"; +} + +static void print(OpAsmPrinter &p, relalg::GetAttrOp &op) { + p << op.getOperationName(); + p << " " << op.tuple() << ", "; + p.printAttributeWithoutType(op.attr().getName()); + p << " : "; + p << op.getType(); +} + +static ParseResult parseBaseTableOp(OpAsmParser &parser, + OperationState &result) { + Attribute valueAttr; + StringAttr nameAttr; + if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(), + result.attributes)) + return failure(); + if (parser.parseOptionalAttrDict(result.attributes)) + return failure(); + if (parser.parseKeyword("columns") || parser.parseColon() || + parser.parseLBrace()) + return failure(); + std::vector columns; + + while (true) { + if (!parser.parseOptionalRBrace()) { + break; + } + StringRef col_name; + SymbolRefAttr attr_symbolAttr; + if (parser.parseKeyword(&col_name)) { + return failure(); + } + if (parser.parseEqual() || parser.parseGreater()) { + return failure(); + } + if (parser.parseAttribute( + attr_symbolAttr, parser.getBuilder().getType<::mlir::NoneType>())) { + return failure(); + } + std::string attr_name(attr_symbolAttr.getLeafReference()); + if (parser.parseLParen()) { + return failure(); + } + DictionaryAttr dictAttr; + if (parser.parseAttribute(dictAttr)) { + return failure(); + } + auto prop_name = dictAttr.get("name").dyn_cast().getValue(); + auto prop_type = dictAttr.get("type") + .dyn_cast() + .getValue() + .dyn_cast(); + auto relationalAttribute = + std::make_shared(prop_name, + prop_type); + auto attr_def_attr = mlir::relalg::RelationalAttributeDefAttr::get( + parser.getBuilder().getContext(), attr_name, relationalAttribute); + columns.push_back( + {Identifier::get(col_name, parser.getBuilder().getContext()), + attr_def_attr}); + if (parser.parseRParen()) { + return failure(); + } + if (!parser.parseOptionalComma()) { + continue; + } + if (parser.parseRBrace()) { + return failure(); + } + break; + } + result.addAttribute( + "columns", + mlir::DictionaryAttr::get(parser.getBuilder().getContext(), columns)); + + // Add the attribute type to the list. + return parser.addTypeToList( + mlir::relalg::RelationType::get(parser.getBuilder().getContext()), + result.types); +} +static ParseResult parseGetAttrOp(OpAsmParser &parser, OperationState &result) { + OpAsmParser::OperandType input_tuple; + ::mlir::SymbolRefAttr attr_symbolAttr; + ::mlir::Type resultType; + if (parser.parseOperand(input_tuple) || parser.parseComma()) { + return mlir::failure(); + } + if (parser.resolveOperand( + input_tuple, + mlir::relalg::TupleType::get(parser.getBuilder().getContext()), + result.operands)) + return failure(); + if (parser.parseAttribute(attr_symbolAttr, + parser.getBuilder().getType<::mlir::NoneType>())) + return ::mlir::failure(); + result.addAttribute( + "attr", mlir::relalg::RelationalAttributeRefAttr::get( + parser.getBuilder().getContext(), attr_symbolAttr, + std::shared_ptr())); + if (parser.parseColon()) + return ::mlir::failure(); + if (parser.parseType(resultType)) + return ::mlir::failure(); + return parser.addTypeToList(resultType, result.types); +} + +static ParseResult parseSelectionOp(OpAsmParser &parser, + OperationState &result) { + OpAsmParser::OperandType input_rel, pred_argument; + if (parser.parseOperand(input_rel)) { + return failure(); + } + Type pred_arg_type; + if (parser.parseLParen() || parser.parseRegionArgument(pred_argument) || + parser.parseColonType(pred_arg_type) || parser.parseRParen()) { + return failure(); + } + SmallVector regionArgs; + regionArgs.push_back(pred_argument); + SmallVector argTypes; + argTypes.push_back(pred_arg_type); + Region *body = result.addRegion(); + if (parser.resolveOperand( + input_rel, + mlir::relalg::RelationType::get(parser.getBuilder().getContext()), + result.operands)) + return failure(); + if (parser.parseRegion(*body, regionArgs, argTypes)) + return failure(); + + return parser.addTypeToList( + mlir::relalg::RelationType::get(parser.getBuilder().getContext()), + result.types); +} + +static void print(OpAsmPrinter &p, relalg::SelectionOp &op) { + p << op.getOperationName(); + auto ba = op.getRegion().front().getArguments().front(); + p << " " << op.rel() << "(" << ba << ":" << ba.getType() << ")"; + p.printRegion(op.getRegion(), false, true); +} +#define GET_OP_CLASSES +#include "mlir/Dialect/RelAlg/IR/RelAlgOps.cpp.inc" +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsInterfaces.cpp.inc" +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsTypes.cpp.inc" \ No newline at end of file diff --git a/lib/RelAlg/RelAlgOpsEnums.cpp b/lib/RelAlg/RelAlgOpsEnums.cpp new file mode 100644 index 00000000..fa1842c2 --- /dev/null +++ b/lib/RelAlg/RelAlgOpsEnums.cpp @@ -0,0 +1,6 @@ +#include "mlir/Dialect/RelAlg/IR/RelAlgDialect.h" +#include "mlir/Dialect/RelAlg/IR/RelAlgOps.h" +#include "mlir/IR/OpImplementation.h" + +#define GET_OP_CLASSES +#include "mlir/Dialect/RelAlg/IR/RelAlgOpsEnums.cpp.inc" diff --git a/lib/RelAlg/TestPass.cpp b/lib/RelAlg/TestPass.cpp new file mode 100644 index 00000000..3c3f5aef --- /dev/null +++ b/lib/RelAlg/TestPass.cpp @@ -0,0 +1,28 @@ + +#include "mlir/Dialect/RelAlg/IR/RelAlgOps.h" +#include "mlir/Dialect/RelAlg/Passes.h" + +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" +#include +#include +#include +#include + +namespace { +// query optimization pass +class TestPass : public mlir::PassWrapper { + +public: + void runOnFunction() override { + auto f = getFunction(); + auto *context = &getContext(); + + } +}; +} // end anonymous namespace + +namespace mlir { +namespace relalg { +std::unique_ptr createTestPass() { return std::make_unique(); } +} // end namespace relalg +} // end namespace mlir \ No newline at end of file diff --git a/mlir-opt.cpp b/mlir-opt.cpp new file mode 100644 index 00000000..0866cf3b --- /dev/null +++ b/mlir-opt.cpp @@ -0,0 +1,30 @@ +#include "mlir/IR/Dialect.h" +#include "mlir/IR/MLIRContext.h" +#include "mlir/InitAllDialects.h" +#include "mlir/InitAllPasses.h" +#include "mlir/Pass/Pass.h" +#include "mlir/Pass/PassManager.h" +#include "mlir/Support/FileUtilities.h" +#include "mlir/Support/MlirOptMain.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/ToolOutputFile.h" + +#include "mlir/Dialect/RelAlg/IR/RelAlgDialect.h" +#include "mlir/Dialect/RelAlg/Passes.h" + +#include "mlir/Dialect/DB/IR/DBDialect.h" + +int main(int argc, char **argv) { + mlir::registerAllPasses(); + ::mlir::registerPass("relalg-test-pass", "test pass for relalg dialect", []() -> std::unique_ptr<::mlir::Pass> { + return mlir::relalg::createTestPass(); + }); + mlir::DialectRegistry registry; + registry.insert(); + registry.insert(); + registry.insert(); + return failed( + mlir::MlirOptMain(argc, argv, "DB dialects optimization driver\n", registry)); +}