Skip to content

Commit

Permalink
[Pybind] register everything once
Browse files Browse the repository at this point in the history
  • Loading branch information
qzylalala committed Jan 4, 2024
1 parent 0c693e1 commit 2825720
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 382 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===----------- Registration.h - Register all dialects and passes --------===//
//===------- RegisterEverything.h - Register all dialects and passes ------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,8 +14,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef BUDDYMLIR_C_REGISTRATION_H
#define BUDDYMLIR_C_REGISTRATION_H
#ifndef BUDDYMLIR_C_REGISTEREVERYTHING_H
#define BUDDYMLIR_C_REGISTEREVERYTHING_H

#include "mlir-c/IR.h"
#include "mlir-c/Support.h"
Expand All @@ -24,16 +24,17 @@
extern "C" {
#endif

/** Registers all dialects with a context.
* This is needed before creating IR for these Dialects.
*/
MLIR_CAPI_EXPORTED void buddyMlirRegisterAllDialects(MlirContext context);
// Registers all dialects with a context.
MLIR_CAPI_EXPORTED void buddyRegisterAllDialects(MlirDialectRegistry registry);

/** Registers all passes for symbolic access with the global registry. */
MLIR_CAPI_EXPORTED void buddyMlirRegisterAllPasses();
// Register all translations to LLVM IR for dialects that can support it.
MLIR_CAPI_EXPORTED void buddyRegisterAllTranslations(MlirContext context);

// Registers all passes for symbolic access with the global registry.
MLIR_CAPI_EXPORTED void buddyRegisterAllPasses();

#ifdef __cplusplus
}
#endif

#endif // BUDDYMLIR_C_REGISTRATION_H
#endif // BUDDYMLIR_C_REGISTEREVERYTHING_H
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===------ Registration.cpp - C Interface for MLIR Registration ----------===//
//===- RegisterEverything.cpp - API to register all dialects/passes -------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,20 +14,18 @@
//
//===----------------------------------------------------------------------===//

#include "buddy-mlir-c/Registration.h"
#include "buddy-mlir-c/RegisterEverything.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"

#include "mlir/CAPI/IR.h"
#include "mlir/Conversion/Passes.h"
#include "mlir/Dialect/Linalg/Passes.h"
#include "mlir/Transforms/Passes.h"
#include "buddy-mlir-c/InitAll.h"
PYBIND11_MODULE(_mlirRegisterEverything, m) {
m.doc() = "Buddy MLIR All Dialects, Translations and Passes Registration";

void buddyMlirRegisterAllDialects(MlirContext context) {
mlir::DialectRegistry registry;
mlir::buddy::registerAllDialects(registry);
m.def("register_dialects", [](MlirDialectRegistry registry) {
buddyRegisterAllDialects(registry);
});
m.def("register_llvm_translations",
[](MlirContext context) { buddyRegisterAllTranslations(context); });

unwrap(context)->appendDialectRegistry(registry);
unwrap(context)->loadAllAvailableDialects();
}

void buddyMlirRegisterAllPasses() { mlir::buddy::registerAllPasses(); }
// Register all passes on load.
buddyRegisterAllPasses();
}
18 changes: 15 additions & 3 deletions midend/lib/CAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)

add_mlir_public_c_api_library(BuddyMLIRCAPI
Dialects.cpp
Registration.cpp
RegisterEverything.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/midend/include/buddy-mlir-c

LINK_LIBS PUBLIC
MLIRIR
MLIRSupport
${dialect_libs}
${translation_libs}
${conversion_libs}
${extension_libs}
MLIRBuiltinToLLVMIRTranslation
MLIRCAPIIR
MLIRLLVMToLLVMIRTranslation
MLIRCAPITransforms
BuddyBud
BuddyDAP
BuddyDIP
Expand All @@ -18,4 +29,5 @@ add_mlir_public_c_api_library(BuddyMLIRCAPI
BuddySche
VectorExp
BuddyMLIRInitAll
BuddyToLLVMIRTranslationRegistration
)
69 changes: 69 additions & 0 deletions midend/lib/CAPI/RegisterEverything.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//===------- RegisterEverything.cpp - Register all MLIR entities ----------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//

#include "buddy-mlir-c/InitAll.h"
#include "buddy-mlir-c/RegisterEverything.h"
#include "mlir-c/RegisterEverything.h"

#include "mlir/CAPI/IR.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/InitAllDialects.h"
#include "mlir/InitAllExtensions.h"
#include "mlir/InitAllPasses.h"
#include "mlir/Target/LLVMIR/Dialect/All.h"
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
#include "Target/LLVMIR/Dialect/Gemmini/GemminiToLLVMIRTranslation.h"
#include "Target/LLVMIR/Dialect/RVV/RVVToLLVMIRTranslation.h"

using namespace buddy;
using namespace mlir;

namespace buddy {
void registerBuddyToLLVMIRTranslation();
}

void buddyRegisterAllDialects(MlirDialectRegistry registry) {
// Register all Dialects from UPSTREAM MLIR
mlir::registerAllDialects(*unwrap(registry));

// Register all Dialects from BUDDY MLIR
mlir::buddy::registerAllDialects(*unwrap(registry));
}

void buddyRegisterAllTranslations(MlirContext context) {
auto &ctx = *unwrap(context);
mlir::DialectRegistry registry;
// Register all Translations from UPSTREAM MLIR
registry.insert<DLTIDialect, func::FuncDialect>();
mlir::registerAllToLLVMIRTranslations(registry);

// Register all Translations from BUDDY MLIR
registerRVVDialectTranslation(registry);
registerGemminiDialectTranslation(registry);

ctx.appendDialectRegistry(registry);
}

void buddyRegisterAllPasses() {
// Register all Passes from UPSTREAM MLIR
mlir::registerAllPasses();

// Register all Passes from BUDDY MLIR
mlir::buddy::registerAllPasses();
}
40 changes: 0 additions & 40 deletions midend/python/Bindings/DialectBud.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions midend/python/Bindings/DialectDAP.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions midend/python/Bindings/DialectDIP.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions midend/python/Bindings/DialectGemmini.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions midend/python/Bindings/DialectRVV.cpp

This file was deleted.

Loading

0 comments on commit 2825720

Please sign in to comment.