Skip to content

Commit a1ee18f

Browse files
committed
address review comments
1 parent de69c84 commit a1ee18f

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ def LLVM_AnyPointer : Type<CPred<"::llvm::isa<::mlir::LLVM::LLVMPointerType>($_s
5656
"LLVM pointer type", "::mlir::LLVM::LLVMPointerType">;
5757

5858
// Opaque pointer in a given address space.
59-
class LLVM_OpaquePointerInAddressSpace<int addressSpace> : Type<
60-
CPred<
61-
"::llvm::cast<::mlir::LLVM::LLVMPointerType>($_self).getAddressSpace() == "
62-
# addressSpace>,
59+
class LLVM_PointerInAddressSpace<int addressSpace> : Type<
60+
And<[LLVM_AnyPointer.predicate,
61+
CPred<
62+
"::llvm::cast<::mlir::LLVM::LLVMPointerType>($_self).getAddressSpace() == "
63+
# addressSpace>]>,
6364
"Opaque LLVM pointer in address space " # addressSpace,
6465
"::mlir::LLVM::LLVMPointerType"> {
6566
let builderCall = "$_builder.getType<::mlir::LLVM::LLVMPointerType>("

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
1919
include "mlir/Interfaces/SideEffectInterfaces.td"
2020
include "mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.td"
2121

22-
def LLVM_ptr_global : LLVM_OpaquePointerInAddressSpace<1>;
23-
def LLVM_ptr_shared : LLVM_OpaquePointerInAddressSpace<3>;
22+
def LLVM_ptr_global : LLVM_PointerInAddressSpace<1>;
23+
def LLVM_ptr_shared : LLVM_PointerInAddressSpace<3>;
2424

2525
//===----------------------------------------------------------------------===//
2626
// NVVM dialect definitions

mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def ROCDL_wmma_i32_16x16x16_iu4 : ROCDL_Wmma_IntrOp<"wmma.i32.16x16x16.iu4">;
275275
// raw buffer mode).
276276
//===---------------------------------------------------------------------===//
277277

278-
def ROCDLBufferRsrc : LLVM_OpaquePointerInAddressSpace<8>;
278+
def ROCDLBufferRsrc : LLVM_PointerInAddressSpace<8>;
279279

280280
def ROCDL_MakeBufferRsrcOp :
281281
ROCDL_IntrOp<"make.buffer.rsrc", [], [0], [Pure], 1>,

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,13 @@ static bool isZeroAttribute(Attribute value) {
19541954
}
19551955

19561956
LogicalResult GlobalOp::verify() {
1957+
bool validType = isCompatibleOuterType(getType())
1958+
? !llvm::isa<LLVMVoidType, LLVMTokenType,
1959+
LLVMMetadataType, LLVMLabelType>(getType())
1960+
: llvm::isa<PointerElementTypeInterface>(getType());
1961+
if (!validType)
1962+
return emitOpError(
1963+
"expects type to be a valid element type for an LLVM global");
19571964
if ((*this)->getParentOp() && !satisfiesLLVMModule((*this)->getParentOp()))
19581965
return emitOpError("must appear at the module level");
19591966

mlir/test/Dialect/LLVMIR/global.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ llvm.mlir.global internal protected unnamed_addr @protected(42 : i32) : i32
117117

118118
// -----
119119

120+
// expected-error @+1 {{expects type to be a valid element type for an LLVM global}}
121+
llvm.mlir.global internal constant @constant(37.0) : !llvm.label
122+
123+
// -----
120124
// expected-error @+1 {{'addr_space' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
121125
"llvm.mlir.global"() ({}) {sym_name = "foo", global_type = i64, value = 42 : i64, addr_space = -1 : i32, linkage = #llvm.linkage<private>} : () -> ()
122126

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ func.func @gep_too_few_dynamic(%base : !llvm.ptr) {
125125

126126
// -----
127127

128+
func.func @load_non_llvm_type(%foo : memref<f32>) {
129+
// expected-error@+1 {{op operand #0 must be LLVM pointer type}}
130+
llvm.load %foo : memref<f32> -> f32
131+
}
132+
133+
// -----
134+
128135
func.func @load_syncscope(%ptr : !llvm.ptr) {
129136
// expected-error@below {{expected syncscope to be null for non-atomic access}}
130137
%1 = "llvm.load"(%ptr) {syncscope = "singlethread"} : (!llvm.ptr) -> (f32)

0 commit comments

Comments
 (0)