forked from OSchip/llvm-project
[mlir] disallow side-effecting ops in llvm.mlir.global
The llvm.mlir.global operation accepts a region as initializer. This region corresponds to an LLVM IR constant expression and therefore should not accept operations with side effects. Add a corresponding verifier. Reviewed By: wsmoses, bondhugula Differential Revision: https://reviews.llvm.org/D120632
This commit is contained in:
parent
b3f1480204
commit
5c73db24df
|
@ -1798,6 +1798,13 @@ LogicalResult GlobalOp::verify() {
|
|||
<< *ret.operand_type_begin() << " does not match global type "
|
||||
<< getType();
|
||||
|
||||
for (Operation &op : *b) {
|
||||
auto iface = dyn_cast<MemoryEffectOpInterface>(op);
|
||||
if (!iface || !iface.hasNoEffect())
|
||||
return op.emitError()
|
||||
<< "ops with side effects not allowed in global initializers";
|
||||
}
|
||||
|
||||
if (getValueOrNull())
|
||||
return emitOpError("cannot have both initializer value and region");
|
||||
}
|
||||
|
|
|
@ -1254,7 +1254,17 @@ func @gep_out_of_bounds(%ptr: !llvm.ptr<struct<(i32, struct<(i32, f32)>)>>, %idx
|
|||
// -----
|
||||
|
||||
func @non_splat_shuffle_on_scalable_vector(%arg0: vector<[4]xf32>) {
|
||||
// expected-error@+1 {{expected a splat operation for scalable vectors}}
|
||||
// expected-error@below {{expected a splat operation for scalable vectors}}
|
||||
%0 = llvm.shufflevector %arg0, %arg0 [0 : i32, 0 : i32, 0 : i32, 1 : i32] : vector<[4]xf32>, vector<[4]xf32>
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
llvm.mlir.global internal @side_effecting_global() : !llvm.struct<(i8)> {
|
||||
%0 = llvm.mlir.constant(1 : i64) : i64
|
||||
// expected-error@below {{ops with side effects not allowed in global initializers}}
|
||||
%1 = llvm.alloca %0 x !llvm.struct<(i8)> : (i64) -> !llvm.ptr<struct<(i8)>>
|
||||
%2 = llvm.load %1 : !llvm.ptr<struct<(i8)>>
|
||||
llvm.return %2 : !llvm.struct<(i8)>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue