2020-07-01 06:42:52 +08:00
|
|
|
//===- Interfaces.cpp - Interface classes ---------------------------------===//
|
2019-10-01 03:42:31 +08:00
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-10-01 03:42:31 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-10-01 03:42:31 +08:00
|
|
|
|
2020-07-01 06:42:52 +08:00
|
|
|
#include "mlir/TableGen/Interfaces.h"
|
2019-10-01 03:42:31 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
using namespace mlir::tblgen;
|
|
|
|
|
2020-07-01 06:42:52 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InterfaceMethod
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) {
|
2019-10-01 03:42:31 +08:00
|
|
|
llvm::DagInit *args = def->getValueAsDag("arguments");
|
|
|
|
for (unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
|
|
|
|
arguments.push_back(
|
|
|
|
{llvm::cast<llvm::StringInit>(args->getArg(i))->getValue(),
|
|
|
|
args->getArgNameStr(i)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 06:42:52 +08:00
|
|
|
StringRef InterfaceMethod::getReturnType() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
return def->getValueAsString("returnType");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the name of this method.
|
2020-07-01 06:42:52 +08:00
|
|
|
StringRef InterfaceMethod::getName() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
return def->getValueAsString("name");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return if this method is static.
|
2020-07-01 06:42:52 +08:00
|
|
|
bool InterfaceMethod::isStatic() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
return def->isSubClassOf("StaticInterfaceMethod");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the body for this method if it has one.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> InterfaceMethod::getBody() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
auto value = def->getValueAsString("body");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
|
|
|
|
2019-12-19 03:02:35 +08:00
|
|
|
// Return the default implementation for this method if it has one.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> InterfaceMethod::getDefaultImplementation() const {
|
2019-12-19 03:02:35 +08:00
|
|
|
auto value = def->getValueAsString("defaultBody");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
|
|
|
|
2019-10-01 03:42:31 +08:00
|
|
|
// Return the description of this method if it has one.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> InterfaceMethod::getDescription() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
auto value = def->getValueAsString("description");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
|
|
|
|
2020-07-01 06:42:52 +08:00
|
|
|
ArrayRef<InterfaceMethod::Argument> InterfaceMethod::getArguments() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
2020-07-01 06:42:52 +08:00
|
|
|
bool InterfaceMethod::arg_empty() const { return arguments.empty(); }
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Interface
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
Interface::Interface(const llvm::Record *def) : def(def) {
|
|
|
|
assert(def->isSubClassOf("Interface") &&
|
|
|
|
"must be subclass of TableGen 'Interface' class");
|
2019-10-01 03:42:31 +08:00
|
|
|
|
|
|
|
auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("methods"));
|
|
|
|
for (llvm::Init *init : listInit->getValues())
|
|
|
|
methods.emplace_back(cast<llvm::DefInit>(init)->getDef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the name of this interface.
|
2020-07-01 06:42:52 +08:00
|
|
|
StringRef Interface::getName() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
return def->getValueAsString("cppClassName");
|
|
|
|
}
|
|
|
|
|
2020-07-13 05:11:39 +08:00
|
|
|
// Return the C++ namespace of this interface.
|
|
|
|
StringRef Interface::getCppNamespace() const {
|
|
|
|
return def->getValueAsString("cppNamespace");
|
|
|
|
}
|
|
|
|
|
2019-10-01 03:42:31 +08:00
|
|
|
// Return the methods of this interface.
|
2020-07-01 06:42:52 +08:00
|
|
|
ArrayRef<InterfaceMethod> Interface::getMethods() const { return methods; }
|
2019-10-01 03:42:31 +08:00
|
|
|
|
|
|
|
// Return the description of this method if it has one.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> Interface::getDescription() const {
|
2019-10-01 03:42:31 +08:00
|
|
|
auto value = def->getValueAsString("description");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
2020-01-22 01:40:22 +08:00
|
|
|
|
[mlir] Allow adding extra class declarations to interfaces.
Summary: This matches the similar feature on operation definitions.
Reviewers: jpienaar, antiagainst
Reviewed By: jpienaar, antiagainst
Subscribers: mehdi_amini, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74438
2020-02-16 15:54:28 +08:00
|
|
|
// Return the interfaces extra class declaration code.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> Interface::getExtraClassDeclaration() const {
|
[mlir] Allow adding extra class declarations to interfaces.
Summary: This matches the similar feature on operation definitions.
Reviewers: jpienaar, antiagainst
Reviewed By: jpienaar, antiagainst
Subscribers: mehdi_amini, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74438
2020-02-16 15:54:28 +08:00
|
|
|
auto value = def->getValueAsString("extraClassDeclaration");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
|
|
|
|
2020-04-28 03:57:32 +08:00
|
|
|
// Return the traits extra class declaration code.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> Interface::getExtraTraitClassDeclaration() const {
|
2020-04-28 03:57:32 +08:00
|
|
|
auto value = def->getValueAsString("extraTraitClassDeclaration");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
|
|
|
|
2020-01-22 01:40:22 +08:00
|
|
|
// Return the body for this method if it has one.
|
2020-07-01 06:42:52 +08:00
|
|
|
llvm::Optional<StringRef> Interface::getVerify() const {
|
|
|
|
// Only OpInterface supports the verify method.
|
|
|
|
if (!isa<OpInterface>(this))
|
|
|
|
return llvm::None;
|
2020-01-22 01:40:22 +08:00
|
|
|
auto value = def->getValueAsString("verify");
|
|
|
|
return value.empty() ? llvm::Optional<StringRef>() : value;
|
|
|
|
}
|
2020-07-01 06:42:52 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AttrInterface
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool AttrInterface::classof(const Interface *interface) {
|
|
|
|
return interface->getDef().isSubClassOf("AttrInterface");
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OpInterface
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool OpInterface::classof(const Interface *interface) {
|
|
|
|
return interface->getDef().isSubClassOf("OpInterface");
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TypeInterface
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool TypeInterface::classof(const Interface *interface) {
|
|
|
|
return interface->getDef().isSubClassOf("TypeInterface");
|
|
|
|
}
|