Skip to content

Commit de69c84

Browse files
committed
[MLIR][LLVM] Remove typed pointers from the LLVM dialect
This commit removes the support for typed pointers from the LLVM dialect. Typed pointers have been deprecated for a while and thus this removal was announced in a PSA: https://discourse.llvm.org/t/psa-removal-of-typed-pointers-from-the-llvm-dialect/74502 This change includes: - Changing the ` LLVMPointerType` - Removing remaining usages of the builders and the now removed element type - Fixing assembly formats that require fully qualified pointer types - Updating ODS pointer constraints
1 parent 422ffc5 commit de69c84

File tree

16 files changed

+118
-594
lines changed

16 files changed

+118
-594
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ class GEPIndicesAdaptor {
209209
/// global and use it to compute the address of the first character in the
210210
/// string (operations inserted at the builder insertion point).
211211
Value createGlobalString(Location loc, OpBuilder &builder, StringRef name,
212-
StringRef value, Linkage linkage,
213-
bool useOpaquePointers = true);
212+
StringRef value, Linkage linkage);
214213

215214
/// LLVM requires some operations to be inside of a Module operation. This
216215
/// function confirms that the Operation has the desired properties.

mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,16 @@ def LLVM_ThreadlocalAddressOp : LLVM_OneResultIntrOp<"threadlocal.address", [],
469469

470470
def LLVM_CoroIdOp : LLVM_IntrOp<"coro.id", [], [], [], 1> {
471471
let arguments = (ins I32:$align,
472-
LLVM_i8Ptr:$promise,
473-
LLVM_i8Ptr:$coroaddr,
474-
LLVM_i8Ptr:$fnaddrs);
472+
LLVM_AnyPointer:$promise,
473+
LLVM_AnyPointer:$coroaddr,
474+
LLVM_AnyPointer:$fnaddrs);
475475
let assemblyFormat = "$align `,` $promise `,` $coroaddr `,` $fnaddrs"
476476
" attr-dict `:` functional-type(operands, results)";
477477
}
478478

479479
def LLVM_CoroBeginOp : LLVM_IntrOp<"coro.begin", [], [], [], 1> {
480480
let arguments = (ins LLVM_TokenType:$token,
481-
LLVM_i8Ptr:$mem);
481+
LLVM_AnyPointer:$mem);
482482
let assemblyFormat = "$token `,` $mem attr-dict `:` functional-type(operands, results)";
483483
}
484484

@@ -491,7 +491,7 @@ def LLVM_CoroAlignOp : LLVM_IntrOp<"coro.align", [0], [], [], 1> {
491491
}
492492

493493
def LLVM_CoroSaveOp : LLVM_IntrOp<"coro.save", [], [], [], 1> {
494-
let arguments = (ins LLVM_i8Ptr:$handle);
494+
let arguments = (ins LLVM_AnyPointer:$handle);
495495
let assemblyFormat = "$handle attr-dict `:` functional-type(operands, results)";
496496
}
497497

@@ -502,20 +502,20 @@ def LLVM_CoroSuspendOp : LLVM_IntrOp<"coro.suspend", [], [], [], 1> {
502502
}
503503

504504
def LLVM_CoroEndOp : LLVM_IntrOp<"coro.end", [], [], [], 1> {
505-
let arguments = (ins LLVM_i8Ptr:$handle,
505+
let arguments = (ins LLVM_AnyPointer:$handle,
506506
I1:$unwind,
507507
LLVM_TokenType:$retvals);
508508
let assemblyFormat = "$handle `,` $unwind `,` $retvals attr-dict `:` functional-type(operands, results)";
509509
}
510510

511511
def LLVM_CoroFreeOp : LLVM_IntrOp<"coro.free", [], [], [], 1> {
512512
let arguments = (ins LLVM_TokenType:$id,
513-
LLVM_i8Ptr:$handle);
513+
LLVM_AnyPointer:$handle);
514514
let assemblyFormat = "$id `,` $handle attr-dict `:` functional-type(operands, results)";
515515
}
516516

517517
def LLVM_CoroResumeOp : LLVM_IntrOp<"coro.resume", [], [], [], 0> {
518-
let arguments = (ins LLVM_i8Ptr:$handle);
518+
let arguments = (ins LLVM_AnyPointer:$handle);
519519
let assemblyFormat = "$handle attr-dict `:` qualified(type($handle))";
520520
}
521521

@@ -591,19 +591,19 @@ def LLVM_DbgLabelOp : LLVM_IntrOp<"dbg.label", [], [], [], 0> {
591591
//
592592

593593
def LLVM_VaStartOp : LLVM_ZeroResultIntrOp<"vastart">,
594-
Arguments<(ins LLVM_i8Ptr:$arg_list)> {
594+
Arguments<(ins LLVM_AnyPointer:$arg_list)> {
595595
let assemblyFormat = "$arg_list attr-dict `:` qualified(type($arg_list))";
596596
let summary = "Initializes `arg_list` for subsequent variadic argument extractions.";
597597
}
598598

599599
def LLVM_VaCopyOp : LLVM_ZeroResultIntrOp<"vacopy">,
600-
Arguments<(ins LLVM_i8Ptr:$dest_list, LLVM_i8Ptr:$src_list)> {
600+
Arguments<(ins LLVM_AnyPointer:$dest_list, LLVM_AnyPointer:$src_list)> {
601601
let assemblyFormat = "$src_list `to` $dest_list attr-dict `:` type(operands)";
602602
let summary = "Copies the current argument position from `src_list` to `dest_list`.";
603603
}
604604

605605
def LLVM_VaEndOp : LLVM_ZeroResultIntrOp<"vaend">,
606-
Arguments<(ins LLVM_i8Ptr:$arg_list)> {
606+
Arguments<(ins LLVM_AnyPointer:$arg_list)> {
607607
let assemblyFormat = "$arg_list attr-dict `:` qualified(type($arg_list))";
608608
let summary = "Destroys `arg_list`, which has been initialized by `intr.vastart` or `intr.vacopy`.";
609609
}
@@ -613,7 +613,7 @@ def LLVM_VaEndOp : LLVM_ZeroResultIntrOp<"vaend">,
613613
//
614614

615615
def LLVM_EhTypeidForOp : LLVM_OneResultIntrOp<"eh.typeid.for"> {
616-
let arguments = (ins LLVM_i8Ptr:$type_info);
616+
let arguments = (ins LLVM_AnyPointer:$type_info);
617617
let assemblyFormat = "$type_info attr-dict `:` functional-type(operands, results)";
618618
}
619619

@@ -927,12 +927,12 @@ def LLVM_PtrAnnotation
927927
: LLVM_OneResultIntrOp<"ptr.annotation", [0], [2],
928928
[AllTypesMatch<["res", "ptr"]>,
929929
AllTypesMatch<["annotation", "fileName", "attr"]>]> {
930-
let arguments = (ins LLVM_PointerTo<AnySignlessInteger>:$ptr,
930+
let arguments = (ins LLVM_AnyPointer:$ptr,
931931
LLVM_AnyPointer:$annotation,
932932
LLVM_AnyPointer:$fileName,
933933
I32:$line,
934934
LLVM_AnyPointer:$attr);
935-
let results = (outs LLVM_PointerTo<AnySignlessInteger>:$res);
935+
let results = (outs LLVM_AnyPointer:$res);
936936
}
937937

938938
def LLVM_Annotation

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,17 @@ def LLVM_AnyFloat : Type<
5555
def LLVM_AnyPointer : Type<CPred<"::llvm::isa<::mlir::LLVM::LLVMPointerType>($_self)">,
5656
"LLVM pointer type", "::mlir::LLVM::LLVMPointerType">;
5757

58-
def LLVM_OpaquePointer : Type<
59-
And<[LLVM_AnyPointer.predicate,
60-
CPred<"::llvm::cast<::mlir::LLVM::LLVMPointerType>($_self).isOpaque()">]>,
61-
"LLVM opaque pointer", "::mlir::LLVM::LLVMPointerType">;
62-
63-
// Type constraint accepting LLVM pointer type with an additional constraint
64-
// on the element type.
65-
class LLVM_PointerTo<Type pointee> : Type<
66-
And<[LLVM_AnyPointer.predicate,
67-
Or<[LLVM_OpaquePointer.predicate,
68-
SubstLeaves<
69-
"$_self",
70-
"::llvm::cast<::mlir::LLVM::LLVMPointerType>($_self).getElementType()",
71-
pointee.predicate>]>]>,
72-
"LLVM pointer to " # pointee.summary, "::mlir::LLVM::LLVMPointerType">;
73-
7458
// Opaque pointer in a given address space.
7559
class LLVM_OpaquePointerInAddressSpace<int addressSpace> : Type<
76-
And<[LLVM_OpaquePointer.predicate,
7760
CPred<
7861
"::llvm::cast<::mlir::LLVM::LLVMPointerType>($_self).getAddressSpace() == "
79-
# addressSpace>]>,
62+
# addressSpace>,
8063
"Opaque LLVM pointer in address space " # addressSpace,
8164
"::mlir::LLVM::LLVMPointerType"> {
8265
let builderCall = "$_builder.getType<::mlir::LLVM::LLVMPointerType>("
8366
# addressSpace # ")";
8467
}
8568

86-
// Type constraints accepting LLVM pointer type to integer of a specific width.
87-
class LLVM_IntPtrBase<int width, int addressSpace = 0> : Type<
88-
And<[LLVM_PointerTo<I<width>>.predicate,
89-
CPred<"::llvm::cast<::mlir::LLVM::LLVMPointerType>($_self).getAddressSpace()"
90-
" == " # addressSpace>]>,
91-
"LLVM pointer to " # I<width>.summary>;
92-
93-
def LLVM_i8Ptr : LLVM_IntPtrBase<8>;
94-
9569
// Type constraint accepting any LLVM structure type.
9670
def LLVM_AnyStruct : Type<CPred<"::llvm::isa<::mlir::LLVM::LLVMStructType>($_self)">,
9771
"LLVM structure type">;

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

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,14 @@ def LLVM_AllocaOp : LLVM_Op<"alloca",
184184
LLVM_MemOpPatterns {
185185
let arguments = (ins AnyInteger:$arraySize,
186186
OptionalAttr<I64Attr>:$alignment,
187-
OptionalAttr<TypeAttr>:$elem_type,
187+
TypeAttr:$elem_type,
188188
UnitAttr:$inalloca);
189189
let results = (outs Res<LLVM_AnyPointer, "",
190190
[MemAlloc<AutomaticAllocationScopeResource>]>:$res);
191191
string llvmInstName = "Alloca";
192192
string llvmBuilder = [{
193193
auto addrSpace = $_resultType->getPointerAddressSpace();
194-
llvm::Type *elementType = moduleTranslation.convertType(
195-
$elem_type ? *$elem_type
196-
: ::llvm::cast<LLVMPointerType>(op.getType()).getElementType());
194+
llvm::Type *elementType = moduleTranslation.convertType($elem_type);
197195
auto *inst = builder.CreateAlloca(elementType, addrSpace, $arraySize);
198196
}] # setAlignmentCode # [{
199197
inst->setUsedWithInAlloca($inalloca);
@@ -207,31 +205,16 @@ def LLVM_AllocaOp : LLVM_Op<"alloca",
207205
$res = $_builder.create<LLVM::AllocaOp>(
208206
$_location, $_resultType, $arraySize,
209207
alignment == 0 ? IntegerAttr() : $_builder.getI64IntegerAttr(alignment),
210-
TypeAttr::get(allocatedType), allocaInst->isUsedWithInAlloca());
208+
allocatedType, allocaInst->isUsedWithInAlloca());
211209
}];
212210
let builders = [
213-
DeprecatedOpBuilder<"the usage of typed pointers is deprecated",
214-
(ins "Type":$resultType, "Value":$arraySize,
215-
"unsigned":$alignment),
216-
[{
217-
assert(!::llvm::cast<LLVMPointerType>(resultType).isOpaque() &&
218-
"pass the allocated type explicitly if opaque pointers are used");
219-
if (alignment == 0)
220-
return build($_builder, $_state, resultType, arraySize, IntegerAttr(),
221-
TypeAttr(), false);
222-
build($_builder, $_state, resultType, arraySize,
223-
$_builder.getI64IntegerAttr(alignment), TypeAttr(), false);
224-
}]>,
225211
OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$arraySize,
226212
CArg<"unsigned", "0">:$alignment),
227213
[{
228-
TypeAttr elemTypeAttr =
229-
::llvm::cast<LLVMPointerType>(resultType).isOpaque() ?
230-
TypeAttr::get(elementType) : TypeAttr();
231214
build($_builder, $_state, resultType, arraySize,
232215
alignment == 0 ? IntegerAttr()
233216
: $_builder.getI64IntegerAttr(alignment),
234-
elemTypeAttr, false);
217+
elementType, false);
235218

236219
}]>
237220
];
@@ -247,7 +230,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
247230
let arguments = (ins LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$base,
248231
Variadic<LLVM_ScalarOrVectorOf<AnyInteger>>:$dynamicIndices,
249232
DenseI32ArrayAttr:$rawConstantIndices,
250-
OptionalAttr<TypeAttr>:$elem_type,
233+
TypeAttr:$elem_type,
251234
UnitAttr:$inbounds);
252235
let results = (outs LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$res);
253236
let skipDefaultBuilders = 1;
@@ -282,14 +265,6 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
282265
OpBuilder<(ins "Type":$resultType, "Type":$basePtrType, "Value":$basePtr,
283266
"ValueRange":$indices, CArg<"bool", "false">:$inbounds,
284267
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
285-
DeprecatedOpBuilder<"the usage of typed pointers is deprecated",
286-
(ins "Type":$resultType, "Value":$basePtr,
287-
"ValueRange":$indices, CArg<"bool", "false">:$inbounds,
288-
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
289-
DeprecatedOpBuilder<"the usage of typed pointers is deprecated",
290-
(ins "Type":$resultType, "Value":$basePtr,
291-
"ArrayRef<GEPArg>":$indices, CArg<"bool", "false">:$inbounds,
292-
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
293268
OpBuilder<(ins "Type":$resultType, "Type":$basePtrType, "Value":$basePtr,
294269
"ArrayRef<GEPArg>":$indices, CArg<"bool", "false">:$inbounds,
295270
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
@@ -313,7 +288,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
313288
let assemblyFormat = [{
314289
(`inbounds` $inbounds^)?
315290
$base `[` custom<GEPIndices>($dynamicIndices, $rawConstantIndices) `]` attr-dict
316-
`:` functional-type(operands, results) (`,` $elem_type^)?
291+
`:` functional-type(operands, results) `,` $elem_type
317292
}];
318293

319294
let extraClassDeclaration = [{
@@ -332,7 +307,7 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
332307
[DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
333308
DeclareOpInterfaceMethods<PromotableMemOpInterface>,
334309
DeclareOpInterfaceMethods<SafeMemorySlotAccessOpInterface>]> {
335-
dag args = (ins LLVM_PointerTo<LLVM_LoadableType>:$addr,
310+
dag args = (ins LLVM_AnyPointer:$addr,
336311
OptionalAttr<I64Attr>:$alignment,
337312
UnitAttr:$volatile_,
338313
UnitAttr:$nontemporal,
@@ -370,7 +345,8 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
370345
let assemblyFormat = [{
371346
(`volatile` $volatile_^)? $addr
372347
(`atomic` (`syncscope` `(` $syncscope^ `)`)? $ordering^)?
373-
attr-dict `:` custom<LoadType>(type($addr), type($res))
348+
attr-dict `:` qualified(type($addr)) `->` type($res)
349+
374350
}];
375351
string llvmBuilder = [{
376352
auto *inst = builder.CreateLoad($_resultType, $addr, $volatile_);
@@ -391,9 +367,6 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
391367
getLLVMSyncScope(loadInst));
392368
}];
393369
let builders = [
394-
DeprecatedOpBuilder<"the usage of typed pointers is deprecated",
395-
(ins "Value":$addr, CArg<"unsigned", "0">:$alignment,
396-
CArg<"bool", "false">:$isVolatile, CArg<"bool", "false">:$isNonTemporal)>,
397370
OpBuilder<(ins "Type":$type, "Value":$addr,
398371
CArg<"unsigned", "0">:$alignment, CArg<"bool", "false">:$isVolatile,
399372
CArg<"bool", "false">:$isNonTemporal,
@@ -408,7 +381,7 @@ def LLVM_StoreOp : LLVM_MemAccessOpBase<"store",
408381
DeclareOpInterfaceMethods<PromotableMemOpInterface>,
409382
DeclareOpInterfaceMethods<SafeMemorySlotAccessOpInterface>]> {
410383
dag args = (ins LLVM_LoadableType:$value,
411-
LLVM_PointerTo<LLVM_LoadableType>:$addr,
384+
LLVM_AnyPointer:$addr,
412385
OptionalAttr<I64Attr>:$alignment,
413386
UnitAttr:$volatile_,
414387
UnitAttr:$nontemporal,
@@ -445,7 +418,7 @@ def LLVM_StoreOp : LLVM_MemAccessOpBase<"store",
445418
let assemblyFormat = [{
446419
(`volatile` $volatile_^)? $value `,` $addr
447420
(`atomic` (`syncscope` `(` $syncscope^ `)`)? $ordering^)?
448-
attr-dict `:` custom<StoreType>(type($value), type($addr))
421+
attr-dict `:` type($value) `,` qualified(type($addr))
449422
}];
450423
string llvmBuilder = [{
451424
auto *inst = builder.CreateStore($value, $addr, $volatile_);
@@ -651,8 +624,7 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
651624
OpBuilder<(ins "LLVMFunctionType":$calleeType, "FlatSymbolRefAttr":$callee,
652625
CArg<"ValueRange", "{}">:$args)>,
653626
OpBuilder<(ins "LLVMFunctionType":$calleeType, "StringRef":$callee,
654-
CArg<"ValueRange", "{}">:$args)>,
655-
OpBuilder<(ins "Value":$callee, "ValueRange":$args)>
627+
CArg<"ValueRange", "{}">:$args)>
656628
];
657629
let hasCustomAssemblyFormat = 1;
658630
let extraClassDeclaration = [{
@@ -1636,7 +1608,7 @@ def LLVM_AtomicRMWOp : LLVM_MemAccessOpBase<"atomicrmw", [
16361608
TypesMatchWith<"result #0 and operand #1 have the same type",
16371609
"val", "res", "$_self">]> {
16381610
dag args = (ins AtomicBinOp:$bin_op,
1639-
LLVM_PointerTo<LLVM_AtomicRMWType>:$ptr,
1611+
LLVM_AnyPointer:$ptr,
16401612
LLVM_AtomicRMWType:$val, AtomicOrdering:$ordering,
16411613
OptionalAttr<StrAttr>:$syncscope,
16421614
OptionalAttr<I64Attr>:$alignment,
@@ -1687,7 +1659,7 @@ def LLVM_AtomicCmpXchgOp : LLVM_MemAccessOpBase<"cmpxchg", [
16871659
TypesMatchWith<"result #0 has an LLVM struct type consisting of "
16881660
"the type of operand #2 and a bool", "val", "res",
16891661
"getValAndBoolStructType($_self)">]> {
1690-
dag args = (ins LLVM_PointerTo<LLVM_AtomicCmpXchgType>:$ptr,
1662+
dag args = (ins LLVM_AnyPointer:$ptr,
16911663
LLVM_AtomicCmpXchgType:$cmp, LLVM_AtomicCmpXchgType:$val,
16921664
AtomicOrdering:$success_ordering,
16931665
AtomicOrdering:$failure_ordering,

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,17 @@ def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [
137137
```
138138
}];
139139

140-
let parameters = (ins DefaultValuedParameter<"Type", "Type()">:$elementType,
141-
DefaultValuedParameter<"unsigned", "0">:$addressSpace);
140+
let parameters = (ins DefaultValuedParameter<"unsigned", "0">:$addressSpace);
142141
let assemblyFormat = [{
143-
(`<` custom<Pointer>($elementType, $addressSpace)^ `>`)?
142+
(`<` $addressSpace^ `>`)?
144143
}];
145144

146-
let genVerifyDecl = 1;
147-
145+
let skipDefaultBuilders = 1;
148146
let builders = [
149-
TypeBuilderWithInferredContext<(ins "Type":$elementType,
150-
CArg<"unsigned", "0">:$addressSpace)>,
151147
TypeBuilder<(ins CArg<"unsigned", "0">:$addressSpace), [{
152-
return $_get($_ctxt, Type(), addressSpace);
148+
return $_get($_ctxt, addressSpace);
153149
}]>
154150
];
155-
156-
let extraClassDeclaration = [{
157-
/// Returns `true` if this type is the opaque pointer type, i.e., it has no
158-
/// pointed-to type.
159-
bool isOpaque() const { return !getElementType(); }
160-
161-
/// Checks if the given type can have a pointer type pointing to it.
162-
static bool isValidElementType(Type type);
163-
}];
164151
}
165152

166153
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)