[mlir] Add a parameter for passing default values to StringRefParameter

**For an explanation of these patches see D154153.**

Commit message:
Currently the `StringRefParameter` parameter doesn't support default values,
this patch allows the usage of them, eg:
`StringRefParameter<"description", [{"default_value"}]>`

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D154097
This commit is contained in:
Fabian Mora
2023-07-10 19:55:12 +00:00
parent 939f818a66
commit a042a6502c
3 changed files with 15 additions and 2 deletions

View File

@@ -342,11 +342,12 @@ class DefaultValuedParameter<string type, string value, string desc = ""> :
}
// For StringRefs, which require allocation.
class StringRefParameter<string desc = ""> :
class StringRefParameter<string desc = "", string value = ""> :
AttrOrTypeParameter<"::llvm::StringRef", desc> {
let allocator = [{$_dst = $_allocator.copyInto($_self);}];
let printer = [{$_printer << '"' << $_self << '"';}];
let cppStorageType = "std::string";
let defaultValue = value;
}
// For APFloats, which require comparison.

View File

@@ -350,6 +350,12 @@ def TestTypeCustomString : Test_Type<"TestTypeCustomString"> {
custom<BarString>(ref($foo)) `>` }];
}
def TestTypeOptionalString : Test_Type<"TestTypeOptionalString"> {
let parameters = (ins StringRefParameter<"description", [{"default"}]>:$str);
let mnemonic = "optional_type_string";
let assemblyFormat = [{ (`<` $str^ `>`)? }];
}
def TestTypeElseAnchor : Test_Type<"TestTypeElseAnchor"> {
let parameters = (ins OptionalParameter<"std::optional<int>">:$a);
let mnemonic = "else_anchor";

View File

@@ -67,6 +67,9 @@ attributes {
// CHECK: !test.custom_type_spacing<1 2>
// CHECK: !test.custom_type_string<"foo" foo>
// CHECK: !test.custom_type_string<"bar" bar>
// CHECK: !test.optional_type_string
// CHECK: !test.optional_type_string
// CHECK: !test.optional_type_string<"non default">
func.func private @test_roundtrip_default_parsers_struct(
!test.no_parser<255, [1, 2, 3, 4, 5], "foobar", 4>
@@ -105,5 +108,8 @@ func.func private @test_roundtrip_default_parsers_struct(
!test.custom_type<2 9 9 5>,
!test.custom_type_spacing<1 2>,
!test.custom_type_string<"foo" foo>,
!test.custom_type_string<"bar" bar>
!test.custom_type_string<"bar" bar>,
!test.optional_type_string,
!test.optional_type_string<"default">,
!test.optional_type_string<"non default">
)