-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir] Add new SubElementAttr/SubElementType Interfaces
These interfaces allow for a composite attribute or type to opaquely provide access to any held attributes or types. There are several intended use cases for this interface. The first of which is to allow the printer to create aliases for non-builtin dialect attributes and types. In the future, this interface will also be extended to allow for SymbolRefAttr to be placed on other entities aside from just DictionaryAttr and ArrayAttr. To limit potential test breakages, this revision only adds the new interfaces to the builtin attributes/types that are currently hardcoded during AsmPrinter alias generation. In a followup the remaining builtin attributes/types, and non-builtin attributes/types can be extended to support it. Differential Revision: https://reviews.llvm.org/D102945
- Loading branch information
Showing
14 changed files
with
365 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===- SubElementInterfaces.h - Attr and Type SubElements -------*- 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 contains interfaces and utilities for querying the sub elements of | ||
// an attribute or type. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_INTERFACES_SUBELEMENTINTERFACES_H | ||
#define MLIR_INTERFACES_SUBELEMENTINTERFACES_H | ||
|
||
#include "mlir/IR/Attributes.h" | ||
#include "mlir/IR/Types.h" | ||
|
||
/// Include the definitions of the sub elemnt interfaces. | ||
#include "mlir/IR/SubElementAttrInterfaces.h.inc" | ||
#include "mlir/IR/SubElementTypeInterfaces.h.inc" | ||
|
||
#endif // MLIR_INTERFACES_SUBELEMENTINTERFACES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//===-- SubElementInterfaces.td - Sub-Element Interfaces ---*- tablegen -*-===// | ||
// | ||
// 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 contains a set of interfaces that can be used to interface with | ||
// sub-elements, e.g. held attributes and types, of a composite attribute or | ||
// type. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_IR_SUBELEMENTINTERFACES_TD_ | ||
#define MLIR_IR_SUBELEMENTINTERFACES_TD_ | ||
|
||
include "mlir/IR/OpBase.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// SubElementInterfaceBase | ||
//===----------------------------------------------------------------------===// | ||
|
||
class SubElementInterfaceBase<string interfaceName, string derivedValue> { | ||
string cppNamespace = "::mlir"; | ||
|
||
list<InterfaceMethod> methods = [ | ||
InterfaceMethod< | ||
/*desc=*/[{ | ||
Walk all of the immediately nested sub-attributes and sub-types. This | ||
method does not recurse into sub elements. | ||
}], "void", "walkImmediateSubElements", | ||
(ins "llvm::function_ref<void(mlir::Attribute)>":$walkAttrsFn, | ||
"llvm::function_ref<void(mlir::Type)>":$walkTypesFn) | ||
>, | ||
]; | ||
|
||
code extraClassDeclaration = [{ | ||
/// Walk all of the held sub-attributes. | ||
void walkSubAttrs(llvm::function_ref<void(mlir::Attribute)> walkFn) { | ||
walkSubElements(walkFn, /*walkTypesFn=*/[](mlir::Type) {}); | ||
} | ||
|
||
/// Walk all of the held sub-types. | ||
void walkSubTypes(llvm::function_ref<void(mlir::Type)> walkFn) { | ||
walkSubElements(/*walkAttrsFn=*/[](mlir::Attribute) {}, walkFn); | ||
} | ||
|
||
/// Walk all of the held sub-attributes and sub-types. | ||
void walkSubElements(llvm::function_ref<void(mlir::Attribute)> walkAttrsFn, | ||
llvm::function_ref<void(mlir::Type)> walkTypesFn); | ||
}]; | ||
|
||
code extraTraitClassDeclaration = [{ | ||
/// Walk all of the held sub-attributes. | ||
void walkSubAttrs(llvm::function_ref<void(mlir::Attribute)> walkFn) { | ||
walkSubElements(walkFn, /*walkTypesFn=*/[](mlir::Type) {}); | ||
} | ||
|
||
/// Walk all of the held sub-types. | ||
void walkSubTypes(llvm::function_ref<void(mlir::Type)> walkFn) { | ||
walkSubElements(/*walkAttrsFn=*/[](mlir::Attribute) {}, walkFn); | ||
} | ||
|
||
/// Walk all of the held sub-attributes and sub-types. | ||
void walkSubElements(llvm::function_ref<void(mlir::Attribute)> walkAttrsFn, | ||
llvm::function_ref<void(mlir::Type)> walkTypesFn) { | ||
}] # interfaceName # " interface(" # derivedValue # [{); | ||
interface.walkSubElements(walkAttrsFn, walkTypesFn); | ||
} | ||
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// SubElementAttrInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
def SubElementAttrInterface | ||
: AttrInterface<"SubElementAttrInterface">, | ||
SubElementInterfaceBase<"SubElementAttrInterface", "$_attr"> { | ||
let description = [{ | ||
An interface used to query and manipulate sub-elements, such as sub-types | ||
and sub-attributes of a composite attribute. | ||
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// SubElementTypeInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
def SubElementTypeInterface | ||
: TypeInterface<"SubElementTypeInterface">, | ||
SubElementInterfaceBase<"SubElementTypeInterface", "$_type"> { | ||
let description = [{ | ||
An interface used to query and manipulate sub-elements, such as sub-types | ||
and sub-attributes of a composite type. | ||
}]; | ||
} | ||
|
||
#endif // MLIR_IR_SUBELEMENTINTERFACES_TD_ |
Oops, something went wrong.