forked from OSchip/llvm-project
Revert "[mlir][ods] Support dialect specific content emission via hooks"
This reverts commit 397215cc30
because
this feature needs more discussion.
This commit is contained in:
parent
cc7cb05e9d
commit
37dfc64687
|
@ -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 <functional>
|
||||
|
||||
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<void(const Operator &srcOp, OpClass &emitClass)>;
|
||||
|
||||
// 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_
|
|
@ -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 "<dialect>.<op-name>"
|
||||
// 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;
|
||||
|
|
|
@ -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<llvm::StringMap<DialectEmitFunction>> 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) {
|
||||
|
|
Loading…
Reference in New Issue