From 37dfc64687a01db1d6e7b362231b0c698d26e257 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 17 Jan 2020 07:39:45 -0500 Subject: [PATCH] Revert "[mlir][ods] Support dialect specific content emission via hooks" This reverts commit 397215cc309df1171a198b11cab3b241db9441db because this feature needs more discussion. --- mlir/include/mlir/TableGen/ODSDialectHook.h | 42 --------------------- mlir/include/mlir/TableGen/Operator.h | 9 +++-- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 37 +----------------- 3 files changed, 7 insertions(+), 81 deletions(-) delete mode 100644 mlir/include/mlir/TableGen/ODSDialectHook.h diff --git a/mlir/include/mlir/TableGen/ODSDialectHook.h b/mlir/include/mlir/TableGen/ODSDialectHook.h deleted file mode 100644 index 9d1ea3b68579..000000000000 --- a/mlir/include/mlir/TableGen/ODSDialectHook.h +++ /dev/null @@ -1,42 +0,0 @@ -//===- ODSDialectHook.h - Dialect customization hooks into ODS --*- C++ -*-===// -// -// Part of the LLVM Project, 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 -// -//===----------------------------------------------------------------------===// -// -// This file defines ODS customization hooks for dialects to programmatically -// emit dialect specific contents in ODS C++ code emission. -// -//===----------------------------------------------------------------------===// - -#ifndef MLIR_TABLEGEN_ODSDIALECTHOOK_H_ -#define MLIR_TABLEGEN_ODSDIALECTHOOK_H_ - -#include - -namespace llvm { -class StringRef; -} - -namespace mlir { -namespace tblgen { -class Operator; -class OpClass; - -// The emission function for dialect specific content. It takes in an Operator -// and updates the OpClass accordingly. -using DialectEmitFunction = - std::function; - -// ODSDialectHookRegistration provides a global initializer that registers a -// dialect specific content emission function. -struct ODSDialectHookRegistration { - ODSDialectHookRegistration(llvm::StringRef dialectName, - DialectEmitFunction emitFn); -}; -} // namespace tblgen -} // namespace mlir - -#endif // MLIR_TABLEGEN_ODSDIALECTHOOK_H_ diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h index fc558011fe9f..dd5ff353bf92 100644 --- a/mlir/include/mlir/TableGen/Operator.h +++ b/mlir/include/mlir/TableGen/Operator.h @@ -46,9 +46,6 @@ public: // Returns this op's dialect name. StringRef getDialectName() const; - // Returns the dialect of the op. - const Dialect &getDialect() const { return dialect; } - // Returns the operation name. The name will follow the "." // format if its dialect name is not empty. std::string getOperationName() const; @@ -159,8 +156,14 @@ public: StringRef getExtraClassDeclaration() const; // Returns the Tablegen definition this operator was constructed from. + // TODO(antiagainst,zinenko): do not expose the TableGen record, this is a + // temporary solution to OpEmitter requiring a Record because Operator does + // not provide enough methods. const llvm::Record &getDef() const; + // Returns the dialect of the op. + const Dialect &getDialect() const { return dialect; } + // Prints the contents in this operator to the given `os`. This is used for // debugging purposes. void print(llvm::raw_ostream &os) const; diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 14402e977180..ad0b9ef737f7 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -14,13 +14,11 @@ #include "mlir/Support/STLExtras.h" #include "mlir/TableGen/Format.h" #include "mlir/TableGen/GenInfo.h" -#include "mlir/TableGen/ODSDialectHook.h" #include "mlir/TableGen/OpClass.h" #include "mlir/TableGen/OpInterfaces.h" #include "mlir/TableGen/OpTrait.h" #include "mlir/TableGen/Operator.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Signals.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" @@ -28,35 +26,10 @@ #define DEBUG_TYPE "mlir-tblgen-opdefgen" +using namespace llvm; using namespace mlir; using namespace mlir::tblgen; -using llvm::CodeInit; -using llvm::DefInit; -using llvm::formatv; -using llvm::Init; -using llvm::ListInit; -using llvm::Record; -using llvm::RecordKeeper; -using llvm::StringInit; - -//===----------------------------------------------------------------------===// -// Dialect hook registration -//===----------------------------------------------------------------------===// - -static llvm::ManagedStatic> dialectHooks; - -ODSDialectHookRegistration::ODSDialectHookRegistration( - StringRef dialectName, DialectEmitFunction emitFn) { - bool inserted = dialectHooks->try_emplace(dialectName, emitFn).second; - assert(inserted && "Multiple ODS hooks for the same dialect!"); - (void)inserted; -} - -//===----------------------------------------------------------------------===// -// Static string definitions -//===----------------------------------------------------------------------===// - static const char *const tblgenNamePrefix = "tblgen_"; static const char *const generatedArgName = "odsArg"; static const char *const builderOpState = "odsState"; @@ -306,7 +279,6 @@ OpEmitter::OpEmitter(const Operator &op) verifyCtx.withOp("(*this->getOperation())"); genTraits(); - // Generate C++ code for various op methods. The order here determines the // methods in the generated file. genOpAsmInterface(); @@ -322,13 +294,6 @@ OpEmitter::OpEmitter(const Operator &op) genCanonicalizerDecls(); genFolderDecls(); genOpInterfaceMethods(); - - // If a dialect hook is registered for this op's dialect, emit dialect - // specific content. - auto dialectHookIt = dialectHooks->find(op.getDialectName()); - if (dialectHookIt != dialectHooks->end()) { - dialectHookIt->second(op, opClass); - } } void OpEmitter::emitDecl(const Operator &op, raw_ostream &os) {