Skip to content

Commit 03d136c

Browse files
committed
[mlir] Promote the SubElementInterfaces to a core Attribute/Type construct
This commit restructures the sub element infrastructure to be a core part of attributes and types, instead of being relegated to an interface. This establishes sub element walking/replacement as something "always there", which makes it easier to rely on for correctness/etc (which various bits of infrastructure want, such as Symbols). Attribute/Type now have `walk` and `replace` methods directly accessible, which provide power API for interacting with sub elements. As part of this, a new AttrTypeWalker class is introduced that supports caching walked attributes/types, and a friendlier API (see the simplification of symbol walking in SymbolTable.cpp). Differential Revision: https://reviews.llvm.org/D142272
1 parent f58de21 commit 03d136c

36 files changed

+599
-610
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
include "mlir/IR/AttrTypeBase.td"
1313
include "mlir/Dialect/LLVMIR/LLVMEnums.td"
1414
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
15-
include "mlir/IR/SubElementInterfaces.td"
1615

1716
// All of the attributes will extend this class.
1817
class LLVM_Attr<string name, string attrMnemonic,
@@ -160,9 +159,8 @@ def LLVM_DIBasicTypeAttr : LLVM_Attr<"DIBasicType", "di_basic_type",
160159
// DICompileUnitAttr
161160
//===----------------------------------------------------------------------===//
162161

163-
def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", "di_compile_unit", [
164-
SubElementAttrInterface
165-
], "DIScopeAttr"> {
162+
def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", "di_compile_unit",
163+
/*traits=*/[], "DIScopeAttr"> {
166164
let parameters = (ins
167165
LLVM_DILanguageParameter:$sourceLanguage,
168166
"DIFileAttr":$file,
@@ -177,9 +175,8 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", "di_compile_unit", [
177175
// DICompositeTypeAttr
178176
//===----------------------------------------------------------------------===//
179177

180-
def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type", [
181-
SubElementAttrInterface
182-
], "DITypeAttr"> {
178+
def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
179+
/*traits=*/[], "DITypeAttr"> {
183180
let parameters = (ins
184181
LLVM_DITagParameter:$tag,
185182
"StringAttr":$name,
@@ -199,9 +196,8 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
199196
// DIDerivedTypeAttr
200197
//===----------------------------------------------------------------------===//
201198

202-
def LLVM_DIDerivedTypeAttr : LLVM_Attr<"DIDerivedType", "di_derived_type", [
203-
SubElementAttrInterface
204-
], "DITypeAttr"> {
199+
def LLVM_DIDerivedTypeAttr : LLVM_Attr<"DIDerivedType", "di_derived_type",
200+
/*traits=*/[], "DITypeAttr"> {
205201
let parameters = (ins
206202
LLVM_DITagParameter:$tag,
207203
OptionalParameter<"StringAttr">:$name,
@@ -231,9 +227,8 @@ def LLVM_DIFileAttr : LLVM_Attr<"DIFile", "di_file", /*traits=*/[], "DIScopeAttr
231227
// DILexicalBlockAttr
232228
//===----------------------------------------------------------------------===//
233229

234-
def LLVM_DILexicalBlockAttr : LLVM_Attr<"DILexicalBlock", "di_lexical_block", [
235-
SubElementAttrInterface
236-
], "DIScopeAttr"> {
230+
def LLVM_DILexicalBlockAttr : LLVM_Attr<"DILexicalBlock", "di_lexical_block",
231+
/*traits=*/[], "DIScopeAttr"> {
237232
let parameters = (ins
238233
"DIScopeAttr":$scope,
239234
OptionalParameter<"DIFileAttr">:$file,
@@ -255,9 +250,8 @@ def LLVM_DILexicalBlockAttr : LLVM_Attr<"DILexicalBlock", "di_lexical_block", [
255250
// DILexicalBlockFileAttr
256251
//===----------------------------------------------------------------------===//
257252

258-
def LLVM_DILexicalBlockFile : LLVM_Attr<"DILexicalBlockFile", "di_lexical_block_file", [
259-
SubElementAttrInterface
260-
], "DIScopeAttr"> {
253+
def LLVM_DILexicalBlockFile : LLVM_Attr<"DILexicalBlockFile", "di_lexical_block_file",
254+
/*traits=*/[], "DIScopeAttr"> {
261255
let parameters = (ins
262256
"DIScopeAttr":$scope,
263257
OptionalParameter<"DIFileAttr">:$file,
@@ -277,9 +271,8 @@ def LLVM_DILexicalBlockFile : LLVM_Attr<"DILexicalBlockFile", "di_lexical_block_
277271
// DILocalVariableAttr
278272
//===----------------------------------------------------------------------===//
279273

280-
def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable", [
281-
SubElementAttrInterface
282-
], "DINodeAttr"> {
274+
def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
275+
/*traits=*/[], "DINodeAttr"> {
283276
let parameters = (ins
284277
"DIScopeAttr":$scope,
285278
"StringAttr":$name,
@@ -307,9 +300,8 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
307300
// DISubprogramAttr
308301
//===----------------------------------------------------------------------===//
309302

310-
def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram", [
311-
SubElementAttrInterface
312-
], "DIScopeAttr"> {
303+
def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
304+
/*traits=*/[], "DIScopeAttr"> {
313305
let parameters = (ins
314306
"DICompileUnitAttr":$compileUnit,
315307
"DIScopeAttr":$scope,
@@ -357,9 +349,8 @@ def LLVM_DISubrangeAttr : LLVM_Attr<"DISubrange", "di_subrange", /*traits=*/[],
357349
// DISubroutineTypeAttr
358350
//===----------------------------------------------------------------------===//
359351

360-
def LLVM_DISubroutineTypeAttr : LLVM_Attr<"DISubroutineType", "di_subroutine_type", [
361-
SubElementAttrInterface
362-
], "DITypeAttr"> {
352+
def LLVM_DISubroutineTypeAttr : LLVM_Attr<"DISubroutineType", "di_subroutine_type",
353+
/*traits=*/[], "DITypeAttr"> {
363354
let parameters = (ins
364355
LLVM_DICallingConventionParameter:$callingConvention,
365356
OptionalArrayRefParameter<"DITypeAttr">:$types
@@ -377,9 +368,7 @@ def LLVM_DISubroutineTypeAttr : LLVM_Attr<"DISubroutineType", "di_subroutine_typ
377368
// MemoryEffectsAttr
378369
//===----------------------------------------------------------------------===//
379370

380-
def LLVM_MemoryEffectsAttr : LLVM_Attr<"MemoryEffects", "memory_effects", [
381-
SubElementAttrInterface
382-
]> {
371+
def LLVM_MemoryEffectsAttr : LLVM_Attr<"MemoryEffects", "memory_effects"> {
383372
let parameters = (ins
384373
"ModRefInfo":$other,
385374
"ModRefInfo":$argMem,

mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef MLIR_DIALECT_LLVMIR_LLVMTYPES_H_
1515
#define MLIR_DIALECT_LLVMIR_LLVMTYPES_H_
1616

17-
#include "mlir/IR/SubElementInterfaces.h"
1817
#include "mlir/IR/Types.h"
1918
#include "mlir/Interfaces/DataLayoutInterfaces.h"
2019
#include <optional>
@@ -104,7 +103,6 @@ DEFINE_TRIVIAL_LLVM_TYPE(LLVMMetadataType);
104103
class LLVMStructType
105104
: public Type::TypeBase<LLVMStructType, Type, detail::LLVMStructTypeStorage,
106105
DataLayoutTypeInterface::Trait,
107-
SubElementTypeInterface::Trait,
108106
TypeTrait::IsMutable> {
109107
public:
110108
/// Inherit base constructors.

mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
1313
include "mlir/IR/AttrTypeBase.td"
14-
include "mlir/IR/SubElementInterfaces.td"
1514
include "mlir/Interfaces/DataLayoutInterfaces.td"
1615

1716
/// Base class for all LLVM dialect types.
@@ -25,8 +24,7 @@ class LLVMType<string typeName, string typeMnemonic, list<Trait> traits = []>
2524
//===----------------------------------------------------------------------===//
2625

2726
def LLVMArrayType : LLVMType<"LLVMArray", "array", [
28-
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, ["getTypeSize"]>,
29-
DeclareTypeInterfaceMethods<SubElementTypeInterface>]> {
27+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, ["getTypeSize"]>]> {
3028
let summary = "LLVM array type";
3129
let description = [{
3230
The `!llvm.array` type represents a fixed-size array of element types.
@@ -62,8 +60,7 @@ def LLVMArrayType : LLVMType<"LLVMArray", "array", [
6260
// LLVMFunctionType
6361
//===----------------------------------------------------------------------===//
6462

65-
def LLVMFunctionType : LLVMType<"LLVMFunction", "func", [
66-
DeclareTypeInterfaceMethods<SubElementTypeInterface>]> {
63+
def LLVMFunctionType : LLVMType<"LLVMFunction", "func"> {
6764
let summary = "LLVM function type";
6865
let description = [{
6966
The `!llvm.func` is a function type. It consists of a single return type
@@ -124,8 +121,7 @@ def LLVMFunctionType : LLVMType<"LLVMFunction", "func", [
124121

125122
def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [
126123
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, [
127-
"areCompatible", "verifyEntries"]>,
128-
DeclareTypeInterfaceMethods<SubElementTypeInterface>]> {
124+
"areCompatible", "verifyEntries"]>]> {
129125
let summary = "LLVM pointer type";
130126
let description = [{
131127
The `!llvm.ptr` type is an LLVM pointer type. This type typically represents
@@ -171,8 +167,7 @@ def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [
171167
// LLVMFixedVectorType
172168
//===----------------------------------------------------------------------===//
173169

174-
def LLVMFixedVectorType : LLVMType<"LLVMFixedVector", "vec", [
175-
DeclareTypeInterfaceMethods<SubElementTypeInterface>]> {
170+
def LLVMFixedVectorType : LLVMType<"LLVMFixedVector", "vec"> {
176171
let summary = "LLVM fixed vector type";
177172
let description = [{
178173
LLVM dialect scalable vector type, represents a sequence of elements of
@@ -202,8 +197,7 @@ def LLVMFixedVectorType : LLVMType<"LLVMFixedVector", "vec", [
202197
// LLVMScalableVectorType
203198
//===----------------------------------------------------------------------===//
204199

205-
def LLVMScalableVectorType : LLVMType<"LLVMScalableVector", "vec", [
206-
DeclareTypeInterfaceMethods<SubElementTypeInterface>]> {
200+
def LLVMScalableVectorType : LLVMType<"LLVMScalableVector", "vec"> {
207201
let summary = "LLVM scalable vector type";
208202
let description = [{
209203
LLVM dialect scalable vector type, represents a sequence of elements of

0 commit comments

Comments
 (0)