Skip to content

Commit 6ab5829

Browse files
authored
[MLIR][LLVM][NFC] Remove dead interface and add namespace qualifiers (#107573)
The `GetResultPtrElementType` interface is dead now that MLIR has fully moved to opaque pointers, and can be removed. Add namespace qualifiers to all argument types and return types of interface methods for when they're used outside of LLVM dialect.
1 parent e4bb68b commit 6ab5829

File tree

3 files changed

+19
-75
lines changed

3 files changed

+19
-75
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def FastmathFlagsInterface : OpInterface<"FastmathFlagsInterface"> {
2525
let methods = [
2626
InterfaceMethod<
2727
/*desc=*/ "Returns a FastmathFlagsAttr attribute for the operation",
28-
/*returnType=*/ "FastmathFlagsAttr",
28+
/*returnType=*/ "::mlir::LLVM::FastmathFlagsAttr",
2929
/*methodName=*/ "getFastmathAttr",
3030
/*args=*/ (ins),
3131
/*methodBody=*/ [{}],
@@ -37,7 +37,7 @@ def FastmathFlagsInterface : OpInterface<"FastmathFlagsInterface"> {
3737
StaticInterfaceMethod<
3838
/*desc=*/ [{Returns the name of the FastmathFlagsAttr attribute
3939
for the operation}],
40-
/*returnType=*/ "StringRef",
40+
/*returnType=*/ "::llvm::StringRef",
4141
/*methodName=*/ "getFastmathAttrName",
4242
/*args=*/ (ins),
4343
/*methodBody=*/ [{}],
@@ -100,7 +100,7 @@ def BranchWeightOpInterface : OpInterface<"BranchWeightOpInterface"> {
100100
let methods = [
101101
InterfaceMethod<
102102
/*desc=*/ "Returns the branch weights attribute or nullptr",
103-
/*returnType=*/ "DenseI32ArrayAttr",
103+
/*returnType=*/ "::mlir::DenseI32ArrayAttr",
104104
/*methodName=*/ "getBranchWeightsOrNull",
105105
/*args=*/ (ins),
106106
/*methodBody=*/ [{}],
@@ -113,7 +113,7 @@ def BranchWeightOpInterface : OpInterface<"BranchWeightOpInterface"> {
113113
/*desc=*/ "Sets the branch weights attribute",
114114
/*returnType=*/ "void",
115115
/*methodName=*/ "setBranchWeights",
116-
/*args=*/ (ins "DenseI32ArrayAttr":$attr),
116+
/*args=*/ (ins "::mlir::DenseI32ArrayAttr":$attr),
117117
/*methodBody=*/ [{}],
118118
/*defaultImpl=*/ [{
119119
auto op = cast<ConcreteOp>(this->getOperation());
@@ -137,7 +137,7 @@ def AccessGroupOpInterface : OpInterface<"AccessGroupOpInterface"> {
137137
let methods = [
138138
InterfaceMethod<
139139
/*desc=*/ "Returns the access groups attribute or nullptr",
140-
/*returnType=*/ "ArrayAttr",
140+
/*returnType=*/ "::mlir::ArrayAttr",
141141
/*methodName=*/ "getAccessGroupsOrNull",
142142
/*args=*/ (ins),
143143
/*methodBody=*/ [{}],
@@ -150,7 +150,7 @@ def AccessGroupOpInterface : OpInterface<"AccessGroupOpInterface"> {
150150
/*desc=*/ "Sets the access groups attribute",
151151
/*returnType=*/ "void",
152152
/*methodName=*/ "setAccessGroups",
153-
/*args=*/ (ins "const ArrayAttr":$attr),
153+
/*args=*/ (ins "const ::mlir::ArrayAttr":$attr),
154154
/*methodBody=*/ [{}],
155155
/*defaultImpl=*/ [{
156156
auto op = cast<ConcreteOp>(this->getOperation());
@@ -175,7 +175,7 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
175175
let methods = [
176176
InterfaceMethod<
177177
/*desc=*/ "Returns the alias scopes attribute or nullptr",
178-
/*returnType=*/ "ArrayAttr",
178+
/*returnType=*/ "::mlir::ArrayAttr",
179179
/*methodName=*/ "getAliasScopesOrNull",
180180
/*args=*/ (ins),
181181
/*methodBody=*/ [{}],
@@ -188,7 +188,7 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
188188
/*desc=*/ "Sets the alias scopes attribute",
189189
/*returnType=*/ "void",
190190
/*methodName=*/ "setAliasScopes",
191-
/*args=*/ (ins "const ArrayAttr":$attr),
191+
/*args=*/ (ins "const ::mlir::ArrayAttr":$attr),
192192
/*methodBody=*/ [{}],
193193
/*defaultImpl=*/ [{
194194
auto op = cast<ConcreteOp>(this->getOperation());
@@ -197,7 +197,7 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
197197
>,
198198
InterfaceMethod<
199199
/*desc=*/ "Returns the noalias scopes attribute or nullptr",
200-
/*returnType=*/ "ArrayAttr",
200+
/*returnType=*/ "::mlir::ArrayAttr",
201201
/*methodName=*/ "getNoAliasScopesOrNull",
202202
/*args=*/ (ins),
203203
/*methodBody=*/ [{}],
@@ -210,7 +210,7 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
210210
/*desc=*/ "Sets the noalias scopes attribute",
211211
/*returnType=*/ "void",
212212
/*methodName=*/ "setNoAliasScopes",
213-
/*args=*/ (ins "const ArrayAttr":$attr),
213+
/*args=*/ (ins "const ::mlir::ArrayAttr":$attr),
214214
/*methodBody=*/ [{}],
215215
/*defaultImpl=*/ [{
216216
auto op = cast<ConcreteOp>(this->getOperation());
@@ -219,7 +219,7 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
219219
>,
220220
InterfaceMethod<
221221
/*desc=*/ "Returns the tbaa attribute or nullptr",
222-
/*returnType=*/ "ArrayAttr",
222+
/*returnType=*/ "::mlir::ArrayAttr",
223223
/*methodName=*/ "getTBAATagsOrNull",
224224
/*args=*/ (ins),
225225
/*methodBody=*/ [{}],
@@ -232,7 +232,7 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
232232
/*desc=*/ "Sets the tbaa attribute",
233233
/*returnType=*/ "void",
234234
/*methodName=*/ "setTBAATags",
235-
/*args=*/ (ins "const ArrayAttr":$attr),
235+
/*args=*/ (ins "const ::mlir::ArrayAttr":$attr),
236236
/*methodBody=*/ [{}],
237237
/*defaultImpl=*/ [{
238238
auto op = cast<ConcreteOp>(this->getOperation());
@@ -249,29 +249,6 @@ def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> {
249249
];
250250
}
251251

252-
def GetResultPtrElementType : OpInterface<"GetResultPtrElementType"> {
253-
let description = [{
254-
An interface for operations that yield an LLVMPointer. Allows the
255-
operation to provide the type of the element an LLVMPointer points to,
256-
if known. This is only a hint as to how to interpret a given pointer,
257-
translating how the current operation understands it.
258-
}];
259-
260-
let cppNamespace = "::mlir::LLVM";
261-
262-
let methods = [
263-
InterfaceMethod<
264-
/*desc=*/ [{Returns the the element type hint of the result
265-
LLVMPointer, if known. Returns nullptr if the
266-
requested result is not an LLVMPointer or if the
267-
element type is unknown.}],
268-
/*returnType=*/ "Type",
269-
/*methodName=*/ "getResultPtrElementType",
270-
/*args=*/ (ins)
271-
>
272-
];
273-
}
274-
275252
def FPExceptionBehaviorOpInterface : OpInterface<"FPExceptionBehaviorOpInterface"> {
276253
let description = [{
277254
An interface for operations receiving an exception behavior attribute
@@ -283,7 +260,7 @@ def FPExceptionBehaviorOpInterface : OpInterface<"FPExceptionBehaviorOpInterface
283260
let methods = [
284261
InterfaceMethod<
285262
/*desc=*/ "Returns a FPExceptionBehavior attribute for the operation",
286-
/*returnType=*/ "FPExceptionBehaviorAttr",
263+
/*returnType=*/ "::mlir::LLVM::FPExceptionBehaviorAttr",
287264
/*methodName=*/ "getFPExceptionBehaviorAttr",
288265
/*args=*/ (ins),
289266
/*methodBody=*/ [{}],
@@ -295,7 +272,7 @@ def FPExceptionBehaviorOpInterface : OpInterface<"FPExceptionBehaviorOpInterface
295272
StaticInterfaceMethod<
296273
/*desc=*/ [{Returns the name of the FPExceptionBehaviorAttr
297274
attribute for the operation}],
298-
/*returnType=*/ "StringRef",
275+
/*returnType=*/ "::llvm::StringRef",
299276
/*methodName=*/ "getFPExceptionBehaviorAttrName",
300277
/*args=*/ (ins),
301278
/*methodBody=*/ [{}],
@@ -317,7 +294,7 @@ def RoundingModeOpInterface : OpInterface<"RoundingModeOpInterface"> {
317294
let methods = [
318295
InterfaceMethod<
319296
/*desc=*/ "Returns a RoundingMode attribute for the operation",
320-
/*returnType=*/ "RoundingModeAttr",
297+
/*returnType=*/ "::mlir::LLVM::RoundingModeAttr",
321298
/*methodName=*/ "getRoundingModeAttr",
322299
/*args=*/ (ins),
323300
/*methodBody=*/ [{}],
@@ -329,7 +306,7 @@ def RoundingModeOpInterface : OpInterface<"RoundingModeOpInterface"> {
329306
StaticInterfaceMethod<
330307
/*desc=*/ [{Returns the name of the RoundingModeAttr attribute
331308
for the operation}],
332-
/*returnType=*/ "StringRef",
309+
/*returnType=*/ "::llvm::StringRef",
333310
/*methodName=*/ "getRoundingModeAttrName",
334311
/*args=*/ (ins),
335312
/*methodBody=*/ [{}],
@@ -359,7 +336,7 @@ def LLVM_PointerElementTypeInterface
359336
/*description=*/"Returns the size of the type in bytes.",
360337
/*retTy=*/"unsigned",
361338
/*methodName=*/"getSizeInBytes",
362-
/*args=*/(ins "const DataLayout &":$dataLayout),
339+
/*args=*/(ins "const ::mlir::DataLayout &":$dataLayout),
363340
/*methodBody=*/"",
364341
/*defaultImplementation=*/[{
365342
return dataLayout.getTypeSize($_type);

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ def LLVM_FNegOp : LLVM_UnaryFloatArithmeticOp<
201201
// Memory-related operations.
202202
def LLVM_AllocaOp : LLVM_Op<"alloca",
203203
[DeclareOpInterfaceMethods<PromotableAllocationOpInterface>,
204-
DeclareOpInterfaceMethods<DestructurableAllocationOpInterface>,
205-
DeclareOpInterfaceMethods<GetResultPtrElementType>]>,
204+
DeclareOpInterfaceMethods<DestructurableAllocationOpInterface>]>,
206205
LLVM_MemOpPatterns {
207206
let arguments = (ins AnySignlessInteger:$arraySize,
208207
OptionalAttr<I64Attr>:$alignment,
@@ -247,8 +246,7 @@ def LLVM_AllocaOp : LLVM_Op<"alloca",
247246
def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
248247
DeclareOpInterfaceMethods<PromotableOpInterface>,
249248
DeclareOpInterfaceMethods<SafeMemorySlotAccessOpInterface>,
250-
DeclareOpInterfaceMethods<DestructurableAccessorOpInterface>,
251-
DeclareOpInterfaceMethods<GetResultPtrElementType>]> {
249+
DeclareOpInterfaceMethods<DestructurableAccessorOpInterface>]> {
252250
let arguments = (ins LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$base,
253251
Variadic<LLVM_ScalarOrVectorOf<AnySignlessInteger>>:$dynamicIndices,
254252
DenseI32ArrayAttr:$rawConstantIndices,

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,6 @@ LogicalResult AllocaOp::verify() {
413413
return success();
414414
}
415415

416-
Type AllocaOp::getResultPtrElementType() { return getElemType(); }
417-
418416
//===----------------------------------------------------------------------===//
419417
// LLVM::BrOp
420418
//===----------------------------------------------------------------------===//
@@ -792,35 +790,6 @@ LogicalResult LLVM::GEPOp::verify() {
792790
[&] { return emitOpError(); });
793791
}
794792

795-
Type GEPOp::getResultPtrElementType() {
796-
// Set the initial type currently being used for indexing. This will be
797-
// updated as the indices get walked over.
798-
Type selectedType = getElemType();
799-
800-
// Follow the indexed elements in the gep.
801-
auto indices = getIndices();
802-
for (GEPIndicesAdaptor<ValueRange>::value_type index :
803-
llvm::drop_begin(indices)) {
804-
// GEPs can only index into aggregates which can be structs or arrays.
805-
806-
// The resulting type if indexing into an array type is always the element
807-
// type, regardless of index.
808-
if (auto arrayType = dyn_cast<LLVMArrayType>(selectedType)) {
809-
selectedType = arrayType.getElementType();
810-
continue;
811-
}
812-
813-
// The GEP verifier ensures that any index into structs are static and
814-
// that they refer to a field within the struct.
815-
selectedType = cast<DestructurableTypeInterface>(selectedType)
816-
.getTypeAtIndex(cast<IntegerAttr>(index));
817-
}
818-
819-
// When there are no more indices, the type currently being used for indexing
820-
// is the type of the value pointed at by the returned indexed pointer.
821-
return selectedType;
822-
}
823-
824793
//===----------------------------------------------------------------------===//
825794
// LoadOp
826795
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)