MLIR  14.0.0git
Attributes.cpp
Go to the documentation of this file.
1 //===- Attributes.cpp - MLIR Affine Expr Classes --------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir/IR/Attributes.h"
10 #include "mlir/IR/Dialect.h"
11 
12 using namespace mlir;
13 using namespace mlir::detail;
14 
15 //===----------------------------------------------------------------------===//
16 // Attribute
17 //===----------------------------------------------------------------------===//
18 
19 /// Return the context this attribute belongs to.
20 MLIRContext *Attribute::getContext() const { return getDialect().getContext(); }
21 
22 //===----------------------------------------------------------------------===//
23 // NamedAttribute
24 //===----------------------------------------------------------------------===//
25 
27  : name(name), value(value) {
28  assert(name && value && "expected valid attribute name and value");
29  assert(name.size() != 0 && "expected valid attribute name");
30 }
31 
32 StringAttr NamedAttribute::getName() const { return name.cast<StringAttr>(); }
33 
35  return getName().getReferencedDialect();
36 }
37 
38 void NamedAttribute::setName(StringAttr newName) {
39  assert(name && "expected valid attribute name");
40  name = newName;
41 }
42 
43 bool NamedAttribute::operator<(const NamedAttribute &rhs) const {
44  return getName().compare(rhs.getName()) < 0;
45 }
46 
47 bool NamedAttribute::operator<(StringRef rhs) const {
48  return getName().getValue().compare(rhs) < 0;
49 }
Include the generated interface declarations.
U cast() const
Definition: Attributes.h:123
static constexpr const bool value
NamedAttribute represents a combination of a name and an Attribute value.
Definition: Attributes.h:137
NamedAttribute(StringAttr name, Attribute value)
Definition: Attributes.cpp:26
MLIRContext * getContext() const
Return the context this attribute belongs to.
Definition: Attributes.cpp:20
Attributes are known-constant values of operations.
Definition: Attributes.h:24
StringAttr getName() const
Return the name of the attribute.
Definition: Attributes.cpp:32
void setName(StringAttr newName)
Set the name of this attribute.
Definition: Attributes.cpp:38
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition: Dialect.h:42
Dialect * getNameDialect() const
Return the dialect of the name of this attribute, if the name is prefixed by a dialect namespace...
Definition: Attributes.cpp:34
bool operator<(const NamedAttribute &rhs) const
Compare this attribute to the provided attribute, ordering by name.
Definition: Attributes.cpp:43
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55