Skip to content

Commit

Permalink
Remove global dialect registration
Browse files Browse the repository at this point in the history
This has been deprecated for >1month now and removal was announced in:

https://llvm.discourse.group/t/rfc-revamp-dialect-registration/1559/11

Differential Revision: https://reviews.llvm.org/D86356
  • Loading branch information
joker-eph committed Oct 23, 2020
1 parent 2b7dfdd commit b22e2e4
Show file tree
Hide file tree
Showing 36 changed files with 54 additions and 153 deletions.
1 change: 0 additions & 1 deletion mlir/examples/standalone/standalone-opt/standalone-opt.cpp
Expand Up @@ -22,7 +22,6 @@
#include "Standalone/StandaloneDialect.h"

int main(int argc, char **argv) {
mlir::registerAllDialects();
mlir::registerAllPasses();
// TODO: Register standalone passes here.

Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch2/toyc.cpp
Expand Up @@ -68,7 +68,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
}

int dumpMLIR() {
mlir::MLIRContext context(/*loadAllDialects=*/false);
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();

Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch3/toyc.cpp
Expand Up @@ -102,7 +102,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
}

int dumpMLIR() {
mlir::MLIRContext context(/*loadAllDialects=*/false);
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();

Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch4/toyc.cpp
Expand Up @@ -103,7 +103,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
}

int dumpMLIR() {
mlir::MLIRContext context(/*loadAllDialects=*/false);
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();

Expand Down
4 changes: 1 addition & 3 deletions mlir/examples/toy/Ch5/toyc.cpp
Expand Up @@ -106,7 +106,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
}

int dumpMLIR() {
mlir::MLIRContext context(/*loadAllDialects=*/false);
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();

Expand Down Expand Up @@ -172,8 +172,6 @@ int dumpAST() {
}

int main(int argc, char **argv) {
mlir::registerAllDialects();

// Register any command line options.
mlir::registerAsmPrinterCLOptions();
mlir::registerMLIRContextCLOptions();
Expand Down
4 changes: 1 addition & 3 deletions mlir/examples/toy/Ch6/toyc.cpp
Expand Up @@ -241,8 +241,6 @@ int runJit(mlir::ModuleOp module) {
}

int main(int argc, char **argv) {
mlir::registerAllDialects();

// Register any command line options.
mlir::registerAsmPrinterCLOptions();
mlir::registerMLIRContextCLOptions();
Expand All @@ -255,7 +253,7 @@ int main(int argc, char **argv) {

// If we aren't dumping the AST, then we are compiling with/to MLIR.

mlir::MLIRContext context(/*loadAllDialects=*/false);
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();

Expand Down
4 changes: 1 addition & 3 deletions mlir/examples/toy/Ch7/toyc.cpp
Expand Up @@ -242,8 +242,6 @@ int runJit(mlir::ModuleOp module) {
}

int main(int argc, char **argv) {
mlir::registerAllDialects();

// Register any command line options.
mlir::registerAsmPrinterCLOptions();
mlir::registerMLIRContextCLOptions();
Expand All @@ -256,7 +254,7 @@ int main(int argc, char **argv) {

// If we aren't dumping the AST, then we are compiling with/to MLIR.

mlir::MLIRContext context(/*loadAllDialects=*/false);
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();

Expand Down
42 changes: 0 additions & 42 deletions mlir/include/mlir/IR/Dialect.h
Expand Up @@ -284,48 +284,6 @@ class DialectRegistry {
MapTy registry;
};

/// Deprecated: this provides a global registry for convenience, while we're
/// transitioning the registration mechanism to a stateless approach.
DialectRegistry &getGlobalDialectRegistry();

/// This controls globally whether the dialect registry is / isn't enabled.
/// This is deprecated and only intended to help the transition. It'll be
/// removed soon.
void enableGlobalDialectRegistry(bool);
bool isGlobalDialectRegistryEnabled();

/// Registers all dialects from the global registries with the
/// specified MLIRContext. This won't load the dialects in the context,
/// but only make them available for lazy loading by name.
/// Note: This method is not thread-safe.
/// Deprecated: this method will be deleted soon.
void registerAllDialects(MLIRContext *context);

/// Register and return the dialect with the given namespace in the provided
/// context. Returns nullptr is there is no constructor registered for this
/// dialect.
inline Dialect *registerDialect(StringRef name, MLIRContext *context) {
return getGlobalDialectRegistry().loadByName(name, context);
}

/// Utility to register a dialect. Client can register their dialect with the
/// global registry by calling registerDialect<MyDialect>();
/// Note: This method is not thread-safe.
template <typename ConcreteDialect> void registerDialect() {
getGlobalDialectRegistry().insert<ConcreteDialect>();
}

/// DialectRegistration provides a global initializer that registers a Dialect
/// allocation routine.
///
/// Usage:
///
/// // At namespace scope.
/// static DialectRegistration<MyDialect> Unused;
template <typename ConcreteDialect> struct DialectRegistration {
DialectRegistration() { registerDialect<ConcreteDialect>(); }
};

} // namespace mlir

namespace llvm {
Expand Down
8 changes: 1 addition & 7 deletions mlir/include/mlir/IR/MLIRContext.h
Expand Up @@ -24,7 +24,6 @@ class InFlightDiagnostic;
class Location;
class MLIRContextImpl;
class StorageUniquer;
DialectRegistry &getGlobalDialectRegistry();

/// MLIRContext is the top-level object for a collection of MLIR modules. It
/// holds immortal uniqued objects like types, and the tables used to unique
Expand All @@ -40,7 +39,7 @@ class MLIRContext {
/// The loadAllDialects parameters allows to load all dialects from the global
/// registry on Context construction. It is deprecated and will be removed
/// soon.
explicit MLIRContext(bool loadAllDialects = true);
explicit MLIRContext();
~MLIRContext();

/// Return information about all IR dialects loaded in the context.
Expand Down Expand Up @@ -88,11 +87,6 @@ class MLIRContext {
loadDialect<OtherDialect, MoreDialects...>();
}

/// Deprecated: load all globally registered dialects into this context.
/// This method will be removed soon, it can be used temporarily as we're
/// phasing out the global registry.
void loadAllGloballyRegisteredDialects();

/// Get (or create) a dialect for the given derived dialect name.
/// The dialect will be loaded from the registry if no dialect is found.
/// If no dialect is loaded for this name and none is available in the
Expand Down
7 changes: 0 additions & 7 deletions mlir/include/mlir/InitAllDialects.h
Expand Up @@ -64,13 +64,6 @@ inline void registerAllDialects(DialectRegistry &registry) {
// clang-format on
}

// This function should be called before creating any MLIRContext if one expect
// all the possible dialects to be made available to the context automatically.
inline void registerAllDialects() {
static bool initOnce =
([]() { registerAllDialects(getGlobalDialectRegistry()); }(), true);
(void)initOnce;
}
} // namespace mlir

#endif // MLIR_INITALLDIALECTS_H_
2 changes: 1 addition & 1 deletion mlir/lib/CAPI/IR/IR.cpp
Expand Up @@ -26,7 +26,7 @@ using namespace mlir;
/* ========================================================================== */

MlirContext mlirContextCreate() {
auto *context = new MLIRContext(/*loadAllDialects=*/false);
auto *context = new MLIRContext;
return wrap(context);
}

Expand Down
Expand Up @@ -136,7 +136,7 @@ static LogicalResult roundTripModule(ModuleOp srcModule, bool emitDebugInfo,
if (failed(spirv::serialize(*spirvModules.begin(), binary, emitDebugInfo)))
return failure();

MLIRContext deserializationContext(false);
MLIRContext deserializationContext;
context->getDialectRegistry().loadAll(&deserializationContext);
// Then deserialize to get back a SPIR-V module.
spirv::OwningSPIRVModuleRef spirvModule =
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/ExecutionEngine/JitRunner.cpp
Expand Up @@ -22,6 +22,7 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/InitAllDialects.h"
#include "mlir/Parser.h"
#include "mlir/Support/FileUtilities.h"

Expand Down Expand Up @@ -259,8 +260,8 @@ int mlir::JitRunnerMain(
}
}

MLIRContext context(/*loadAllDialects=*/false);
registerAllDialects(&context);
MLIRContext context;
registerAllDialects(context.getDialectRegistry());

auto m = parseMLIRInput(options.inputFilename, &context);
if (!m) {
Expand Down
21 changes: 0 additions & 21 deletions mlir/lib/IR/Dialect.cpp
Expand Up @@ -22,27 +22,6 @@ using namespace detail;

DialectAsmParser::~DialectAsmParser() {}

//===----------------------------------------------------------------------===//
// Dialect Registration (DEPRECATED)
//===----------------------------------------------------------------------===//

/// Registry for all dialect allocation functions.
static llvm::ManagedStatic<DialectRegistry> dialectRegistry;
DialectRegistry &mlir::getGlobalDialectRegistry() { return *dialectRegistry; }

// Note: deprecated, will be removed soon.
static bool isGlobalDialectRegistryEnabledFlag = false;
void mlir::enableGlobalDialectRegistry(bool enable) {
isGlobalDialectRegistryEnabledFlag = enable;
}
bool mlir::isGlobalDialectRegistryEnabled() {
return isGlobalDialectRegistryEnabledFlag;
}

void mlir::registerAllDialects(MLIRContext *context) {
dialectRegistry->appendTo(context->getDialectRegistry());
}

Dialect *DialectRegistry::loadByName(StringRef name, MLIRContext *context) {
auto it = registry.find(name.str());
if (it == registry.end())
Expand Down
12 changes: 2 additions & 10 deletions mlir/lib/IR/MLIRContext.cpp
Expand Up @@ -361,18 +361,16 @@ class MLIRContextImpl {
};
} // end namespace mlir

MLIRContext::MLIRContext(bool loadAllDialects) : impl(new MLIRContextImpl()) {
MLIRContext::MLIRContext() : impl(new MLIRContextImpl()) {
// Initialize values based on the command line flags if they were provided.
if (clOptions.isConstructed()) {
disableMultithreading(clOptions->disableThreading);
printOpOnDiagnostic(clOptions->printOpOnDiagnostic);
printStackTraceOnDiagnostic(clOptions->printStackTraceOnDiagnostic);
}

// Register dialects with this context.
// Ensure the builtin dialect is always pre-loaded.
getOrLoadDialect<BuiltinDialect>();
if (loadAllDialects)
loadAllGloballyRegisteredDialects();

// Initialize several common attributes and types to avoid the need to lock
// the context when accessing them.
Expand Down Expand Up @@ -520,12 +518,6 @@ MLIRContext::getOrLoadDialect(StringRef dialectNamespace, TypeID dialectID,
return dialect.get();
}

void MLIRContext::loadAllGloballyRegisteredDialects() {
if (!isGlobalDialectRegistryEnabled())
return;
getGlobalDialectRegistry().loadAll(this);
}

bool MLIRContext::allowsUnregisteredDialects() {
return impl->allowUnregisteredDialects;
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Support/MlirOptMain.cpp
Expand Up @@ -89,7 +89,7 @@ static LogicalResult processBuffer(raw_ostream &os,
sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());

// Parse the input file.
MLIRContext context(/*loadAllDialects=*/preloadDialectsInContext);
MLIRContext context;
registry.appendTo(context.getDialectRegistry());
if (preloadDialectsInContext)
registry.loadAll(&context);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Translation/Translation.cpp
Expand Up @@ -175,7 +175,7 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
// Processes the memory buffer with a new MLIRContext.
auto processBuffer = [&](std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
raw_ostream &os) {
MLIRContext context(false);
MLIRContext context;
context.printOpOnDiagnostic(!verifyDiagnostics);
llvm::SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), llvm::SMLoc());
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/EDSC/builder-api-test.cpp
Expand Up @@ -36,7 +36,7 @@ using namespace mlir::edsc;
using namespace mlir::edsc::intrinsics;

static MLIRContext &globalContext() {
static thread_local MLIRContext context(/*loadAllDialects=*/false);
static thread_local MLIRContext context;
static thread_local bool initOnce = [&]() {
// clang-format off
context.loadDialect<AffineDialect,
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/SDBM/sdbm-api-test.cpp
Expand Up @@ -21,7 +21,7 @@ using namespace mlir;


static MLIRContext *ctx() {
static thread_local MLIRContext context(/*loadAllDialects=*/false);
static thread_local MLIRContext context;
static thread_local bool once =
(context.getOrLoadDialect<SDBMDialect>(), true);
(void)once;
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp
Expand Up @@ -19,7 +19,6 @@
#include "llvm/Support/TargetSelect.h"

int main(int argc, char **argv) {
mlir::registerAllDialects();
llvm::InitLLVM y(argc, argv);
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
Expand Up @@ -125,7 +125,6 @@ static LogicalResult runMLIRPasses(ModuleOp m) {

int main(int argc, char **argv) {
registerPassManagerCLOptions();
mlir::registerAllDialects();
llvm::InitLLVM y(argc, argv);
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
Expand Up @@ -1757,7 +1757,7 @@ int main(int argc, char **argv) {
if (testEmitIncludeTdHeader)
output->os() << "include \"mlir/Dialect/Linalg/IR/LinalgStructuredOps.td\"";

MLIRContext context(/*loadAllDialects=*/false);
MLIRContext context;
llvm::SourceMgr mgr;
mgr.AddNewSourceBuffer(std::move(file), llvm::SMLoc());
Parser parser(mgr, &context);
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-opt/mlir-opt.cpp
Expand Up @@ -144,7 +144,6 @@ void registerTestPasses() {
#endif

int main(int argc, char **argv) {
registerAllDialects();
registerAllPasses();
#ifdef MLIR_INCLUDE_TESTS
registerTestPasses();
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-reduce/mlir-reduce.cpp
Expand Up @@ -71,7 +71,6 @@ int main(int argc, char **argv) {

llvm::InitLLVM y(argc, argv);

registerAllDialects();
registerMLIRContextCLOptions();
registerPassManagerCLOptions();

Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp
Expand Up @@ -322,7 +322,6 @@ static LogicalResult runMLIRPasses(ModuleOp m) {

int main(int argc, char **argv) {
registerPassManagerCLOptions();
mlir::registerAllDialects();
llvm::InitLLVM y(argc, argv);
llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargetMCs();
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
Expand Up @@ -53,7 +53,6 @@ int main(int argc, char **argv) {
llvm::llvm_shutdown_obj x;
registerPassManagerCLOptions();

mlir::registerAllDialects();
llvm::InitLLVM y(argc, argv);
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
Expand Down

0 comments on commit b22e2e4

Please sign in to comment.