This patch moves the registration to a method in the MLIRContext: getOrCreateDialect<ConcreteDialect>() This method requires dialect to provide a static getDialectNamespace() and store a TypeID on the Dialect itself, which allows to lazyily create a dialect when not yet loaded in the context. As a side effect, it means that duplicated registration of the same dialect is not an issue anymore. To limit the boilerplate, TableGen dialect generation is modified to emit the constructor entirely and invoke separately a "init()" method that the user implements. Differential Revision: https://reviews.llvm.org/D85495
25 lines
823 B
C++
25 lines
823 B
C++
//===- StandaloneDialect.cpp - Standalone 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 "Standalone/StandaloneDialect.h"
|
|
#include "Standalone/StandaloneOps.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::standalone;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Standalone dialect.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void StandaloneDialect::initialize() {
|
|
addOperations<
|
|
#define GET_OP_LIST
|
|
#include "Standalone/StandaloneOps.cpp.inc"
|
|
>();
|
|
}
|