Benjamin Maxwell 03d1c99d99
[mlir][ODS] Add OptionalTypesMatchWith and remove a custom assemblyFormat (#68876)
This is just a slight specialization of `TypesMatchWith` that returns
success if an optional parameter is missing.

There may be other places this could help e.g.:

eb21049b4b/mlir/include/mlir/Dialect/X86Vector/X86Vector.td (L58-L59)
...but I'm leaving those to avoid some churn.

This constraint will be handy for us in some later patches, it's a
formalization of a short circuiting trick with the `comparator` of the
`TypesMatchWith` constraint (devised for #69195).

```
TypesMatchWith<
  "padding type matches element type of result (if present)",
  "result", "padding",
  "::llvm::cast<VectorType>($_self).getElementType()",
  // This returns true if no padding is present, or it's present with a type that matches the element type of `result`.
  "!getPadding() || std::equal_to<>()">
```

This is a little non-obvious, so after this patch you can instead do:
```
OptionalTypesMatchWith<
  "padding type matches element type of result (if present)",
  "result", "padding",
  "::llvm::cast<VectorType>($_self).getElementType()">
```
2023-10-19 17:00:02 +01:00

24 lines
605 B
TableGen

// RUN: mlir-tblgen -I %S/../../include %s | FileCheck %s
include "mlir/IR/Utils.td"
// CHECK-DAG: string value = "CamelCaseTest"
class already_camel_case {
string value = snakeCaseToCamelCase<"CamelCaseTest">.ret;
}
// CHECK-DAG: string value = "Foo"
class single_word {
string value = snakeCaseToCamelCase<"foo">.ret;
}
// CHECK-DAG: string value = "ThisIsATest"
class snake_case {
string value = snakeCaseToCamelCase<"this_is_a_test">.ret;
}
// CHECK-DAG: string value = "ThisIsATestAgain"
class extra_underscores {
string value = snakeCaseToCamelCase<"__this__is_a_test__again__">.ret;
}