[MLIR] Disallow `sym_visibility`, `sym_name` and `type` attributes in the parsed attribute dictionary.

Differential Revision: https://reviews.llvm.org/D94200
This commit is contained in:
Rahul Joshi 2021-01-06 16:32:59 -08:00
parent 93b54b7c67
commit 67a339e968
4 changed files with 37 additions and 9 deletions

View File

@ -180,7 +180,7 @@ mlir::impl::parseFunctionLikeOp(OpAsmParser &parser, OperationState &result,
return failure();
// Parse the function signature.
auto signatureLocation = parser.getCurrentLocation();
llvm::SMLoc signatureLocation = parser.getCurrentLocation();
bool isVariadic = false;
if (parseFunctionSignature(parser, allowVariadic, entryArgs, argTypes,
argAttrs, isVariadic, resultTypes, resultAttrs))
@ -196,9 +196,24 @@ mlir::impl::parseFunctionLikeOp(OpAsmParser &parser, OperationState &result,
<< (errorMessage.empty() ? "" : ": ") << errorMessage;
// If function attributes are present, parse them.
if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
NamedAttrList parsedAttributes;
llvm::SMLoc attributeDictLocation = parser.getCurrentLocation();
if (parser.parseOptionalAttrDictWithKeyword(parsedAttributes))
return failure();
// Disallow attributes that are inferred from elsewhere in the attribute
// dictionary.
for (StringRef disallowed :
{SymbolTable::getVisibilityAttrName(), SymbolTable::getSymbolAttrName(),
getTypeAttrName()}) {
if (parsedAttributes.get(disallowed))
return parser.emitError(attributeDictLocation, "'")
<< disallowed
<< "' is an inferred attribute and should not be specified in the "
"explicit attribute dictionary";
}
result.attributes.append(parsedAttributes);
// Add the attributes to the function arguments.
assert(argAttrs.size() == argTypes.size());
assert(resultAttrs.size() == resultTypes.size());

View File

@ -19,11 +19,11 @@ func @inlined_if_fn(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -
}) : (tensor<i1>, tensor<f32>, tensor<f32>) -> tensor<f32>
return %0 : tensor<f32>
}
func @add(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> attributes {sym_visibility = "private"} {
func private @add(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> {
%0 = "tosa.add"(%arg0, %arg1) : (tensor<f32>, tensor<f32>) -> tensor<f32>
return %0 : tensor<f32>
}
func @sub(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> attributes {sym_visibility = "private"} {
func private @sub(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> {
%0 = "tosa.sub"(%arg0, %arg1) : (tensor<f32>, tensor<f32>) -> tensor<f32>
return %0 : tensor<f32>
}
@ -45,12 +45,12 @@ func @inlined_while_fn(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32
}) : (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>)
return %1#3 : tensor<10xi32>
}
func @while_body_50(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) attributes {sym_visibility = "private"} {
func private @while_body_50(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) {
%1 = "tosa.add"(%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i32>
%2 = "tosa.add"(%arg3, %1) : (tensor<10xi32>, tensor<i32>) -> tensor<10xi32>
return %1, %arg1, %arg2, %2: tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>
}
func @while_cond_40(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> tensor<i1> attributes {sym_visibility = "private"} {
func private @while_cond_40(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> tensor<i1> {
%0 = "tosa.greater_equal"(%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i1>
%1 = "tosa.logical_not"(%0) : (tensor<i1>) -> tensor<i1>
return %1 : tensor<i1>

View File

@ -942,6 +942,3 @@ func @subtensor_insert(%t: tensor<8x16x4xf32>, %t2: tensor<16x32x8xf32>, %idx :
return
}
// CHECK-LABEL: func private @legacy_visibility_syntax
func @legacy_visibility_syntax() attributes { sym_visibility = "private" }

View File

@ -78,3 +78,19 @@ func @f(%arg0: i64) -> (i64 {test.invalid_attr}) {
// expected-error@+1 {{symbol declaration cannot have public visibility}}
func @invalid_public_declaration()
// -----
// expected-error@+1 {{'sym_visibility' is an inferred attribute and should not be specified in the explicit attribute dictionary}}
func @legacy_visibility_syntax() attributes { sym_visibility = "private" }
// -----
// expected-error@+1 {{'sym_name' is an inferred attribute and should not be specified in the explicit attribute dictionary}}
func private @invalid_symbol_name_attr() attributes { sym_name = "x" }
// -----
// expected-error@+1 {{'type' is an inferred attribute and should not be specified in the explicit attribute dictionary}}
func private @invalid_symbol_type_attr() attributes { type = "x" }