Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/IR/Attributes.h
//===- Attributes.h - MLIR Attribute Classes --------------------*- C++ -*-===// | //===- Attributes.h - MLIR Attribute Classes --------------------*- C++ -*-===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef MLIR_IR_ATTRIBUTES_H | #ifndef MLIR_IR_ATTRIBUTES_H | ||||
#define MLIR_IR_ATTRIBUTES_H | #define MLIR_IR_ATTRIBUTES_H | ||||
#include "mlir/IR/AttributeSupport.h" | #include "mlir/IR/AttributeSupport.h" | ||||
#include "llvm/Support/PointerLikeTypeTraits.h" | #include "llvm/Support/PointerLikeTypeTraits.h" | ||||
namespace mlir { | namespace mlir { | ||||
class Identifier; | class StringAttr; | ||||
// TODO: Remove this when all usages have been replaced with StringAttr. | |||||
using Identifier = StringAttr; | |||||
/// Attributes are known-constant values of operations. | /// Attributes are known-constant values of operations. | ||||
/// | /// | ||||
/// Instances of the Attribute class are references to immortal key-value pairs | /// Instances of the Attribute class are references to immortal key-value pairs | ||||
/// with immutable, uniqued keys owned by MLIRContext. As such, an Attribute is | /// with immutable, uniqued keys owned by MLIRContext. As such, an Attribute is | ||||
/// a thin wrapper around an underlying storage pointer. Attributes are usually | /// a thin wrapper around an underlying storage pointer. Attributes are usually | ||||
/// passed by value. | /// passed by value. | ||||
class Attribute { | class Attribute { | ||||
Show All 31 Lines | public: | ||||
// Support dyn_cast'ing Attribute to itself. | // Support dyn_cast'ing Attribute to itself. | ||||
static bool classof(Attribute) { return true; } | static bool classof(Attribute) { return true; } | ||||
/// Return a unique identifier for the concrete attribute type. This is used | /// Return a unique identifier for the concrete attribute type. This is used | ||||
/// to support dynamic type casting. | /// to support dynamic type casting. | ||||
TypeID getTypeID() { return impl->getAbstractAttribute().getTypeID(); } | TypeID getTypeID() { return impl->getAbstractAttribute().getTypeID(); } | ||||
/// Return the type of this attribute. | /// Return the type of this attribute. | ||||
Type getType() const; | Type getType() const { return impl->getType(); } | ||||
/// Return the context this attribute belongs to. | /// Return the context this attribute belongs to. | ||||
MLIRContext *getContext() const; | MLIRContext *getContext() const; | ||||
/// Get the dialect this attribute is registered to. | /// Get the dialect this attribute is registered to. | ||||
Dialect &getDialect() const { | Dialect &getDialect() const { | ||||
return impl->getAbstractAttribute().getDialect(); | return impl->getAbstractAttribute().getDialect(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | template <typename U> U Attribute::dyn_cast_or_null() const { | ||||
return (impl && isa<U>()) ? U(impl) : U(nullptr); | return (impl && isa<U>()) ? U(impl) : U(nullptr); | ||||
} | } | ||||
template <typename U> U Attribute::cast() const { | template <typename U> U Attribute::cast() const { | ||||
assert(isa<U>()); | assert(isa<U>()); | ||||
return U(impl); | return U(impl); | ||||
} | } | ||||
inline ::llvm::hash_code hash_value(Attribute arg) { | inline ::llvm::hash_code hash_value(Attribute arg) { | ||||
return ::llvm::hash_value(arg.impl); | return DenseMapInfo<const Attribute::ImplType *>::getHashValue(arg.impl); | ||||
} | } | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// NamedAttribute | // NamedAttribute | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
/// NamedAttribute is combination of a name, represented by an Identifier, and a | /// NamedAttribute is combination of a name, represented by an Identifier, and a | ||||
/// value, represented by an Attribute. The attribute pointer should always be | /// value, represented by an Attribute. The attribute pointer should always be | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |