NFC: Use a DenseSet instead of a DenseMap for DialectInterfaceCollection.
The interfaces are looked up by dialect, which can always be retrieved from an interface instance. PiperOrigin-RevId: 264516023
This commit is contained in:
parent
c382d71b68
commit
e9bda5601f
@ -18,9 +18,8 @@
|
|||||||
#ifndef MLIR_IR_DIALECTINTERFACE_H
|
#ifndef MLIR_IR_DIALECTINTERFACE_H
|
||||||
#define MLIR_IR_DIALECTINTERFACE_H
|
#define MLIR_IR_DIALECTINTERFACE_H
|
||||||
|
|
||||||
#include "mlir/IR/Dialect.h"
|
|
||||||
#include "mlir/Support/STLExtras.h"
|
#include "mlir/Support/STLExtras.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseSet.h"
|
||||||
|
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
class Dialect;
|
class Dialect;
|
||||||
@ -82,6 +81,25 @@ namespace detail {
|
|||||||
/// This class is the base class for a collection of instances for a specific
|
/// This class is the base class for a collection of instances for a specific
|
||||||
/// interface kind.
|
/// interface kind.
|
||||||
class DialectInterfaceCollectionBase {
|
class DialectInterfaceCollectionBase {
|
||||||
|
/// DenseMap info for dialect interfaces that allows lookup by the dialect.
|
||||||
|
struct InterfaceKeyInfo : public DenseMapInfo<const DialectInterface *> {
|
||||||
|
using DenseMapInfo<const DialectInterface *>::isEqual;
|
||||||
|
|
||||||
|
static unsigned getHashValue(Dialect *key) { return llvm::hash_value(key); }
|
||||||
|
static unsigned getHashValue(const DialectInterface *key) {
|
||||||
|
return getHashValue(key->getDialect());
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isEqual(Dialect *lhs, const DialectInterface *rhs) {
|
||||||
|
if (rhs == getEmptyKey() || rhs == getTombstoneKey())
|
||||||
|
return false;
|
||||||
|
return lhs == rhs->getDialect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A set of registered dialect interface instances.
|
||||||
|
using InterfaceSetT = DenseSet<const DialectInterface *, InterfaceKeyInfo>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DialectInterfaceCollectionBase(MLIRContext *ctx, ClassID *interfaceKind);
|
DialectInterfaceCollectionBase(MLIRContext *ctx, ClassID *interfaceKind);
|
||||||
virtual ~DialectInterfaceCollectionBase();
|
virtual ~DialectInterfaceCollectionBase();
|
||||||
@ -93,12 +111,13 @@ protected:
|
|||||||
|
|
||||||
/// Get the interface for the given dialect.
|
/// Get the interface for the given dialect.
|
||||||
const DialectInterface *getInterfaceFor(Dialect *dialect) const {
|
const DialectInterface *getInterfaceFor(Dialect *dialect) const {
|
||||||
return interfaces.lookup(dialect);
|
auto it = interfaces.find_as(dialect);
|
||||||
|
return it == interfaces.end() ? nullptr : *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// A map of registered dialect interface instances.
|
/// A set of registered dialect interface instances.
|
||||||
DenseMap<Dialect *, const DialectInterface *> interfaces;
|
InterfaceSetT interfaces;
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
4
third_party/mlir/lib/IR/Dialect.cpp
vendored
4
third_party/mlir/lib/IR/Dialect.cpp
vendored
@ -137,7 +137,7 @@ DialectInterfaceCollectionBase::DialectInterfaceCollectionBase(
|
|||||||
MLIRContext *ctx, ClassID *interfaceKind) {
|
MLIRContext *ctx, ClassID *interfaceKind) {
|
||||||
for (auto *dialect : ctx->getRegisteredDialects())
|
for (auto *dialect : ctx->getRegisteredDialects())
|
||||||
if (auto *interface = dialect->getRegisteredInterface(interfaceKind))
|
if (auto *interface = dialect->getRegisteredInterface(interfaceKind))
|
||||||
interfaces.try_emplace(dialect, interface);
|
interfaces.insert(interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
DialectInterfaceCollectionBase::~DialectInterfaceCollectionBase() {}
|
DialectInterfaceCollectionBase::~DialectInterfaceCollectionBase() {}
|
||||||
@ -146,5 +146,5 @@ DialectInterfaceCollectionBase::~DialectInterfaceCollectionBase() {}
|
|||||||
/// is not registered.
|
/// is not registered.
|
||||||
const DialectInterface *
|
const DialectInterface *
|
||||||
DialectInterfaceCollectionBase::getInterfaceFor(Operation *op) const {
|
DialectInterfaceCollectionBase::getInterfaceFor(Operation *op) const {
|
||||||
return interfaces.lookup(op->getDialect());
|
return getInterfaceFor(op->getDialect());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user