From 4e7f24c7683bd7b670e95ab04f8a44882253c62c Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 17 Oct 2024 12:06:43 +0200 Subject: [PATCH] define TraitProperty and value_traits --- include/llvm-dialects/Dialect/Dialect.td | 56 +++++++++++++++--------- test/unit/dialect/TestDialect.td | 11 +++++ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/include/llvm-dialects/Dialect/Dialect.td b/include/llvm-dialects/Dialect/Dialect.td index 55557a7..3859952 100644 --- a/include/llvm-dialects/Dialect/Dialect.td +++ b/include/llvm-dialects/Dialect/Dialect.td @@ -320,29 +320,43 @@ multiclass AttrEnum { /// Traits generally map to llvm::Attributes. // ============================================================================ -class Trait; +class TraitProperty; +def FnTrait : TraitProperty; +def ParamTrait : TraitProperty; +def RetTrait : TraitProperty; -class LlvmEnumAttributeTrait : Trait { +class Trait P>{ + list Properties = P; +} + +class LlvmEnumAttributeTrait P> : Trait

{ string llvmEnum = llvmEnum_; } -def NoUnwind : LlvmEnumAttributeTrait<"NoUnwind">; -def WillReturn : LlvmEnumAttributeTrait<"WillReturn">; -def NoReturn : LlvmEnumAttributeTrait<"NoReturn">; -def NoRecurse : LlvmEnumAttributeTrait<"NoRecurse">; -def NoSync : LlvmEnumAttributeTrait<"NoSync">; -def NoFree : LlvmEnumAttributeTrait<"NoFree">; -def MustProgress : LlvmEnumAttributeTrait<"MustProgress">; -def NoCallback : LlvmEnumAttributeTrait<"NoCallback">; -def NoDuplicate : LlvmEnumAttributeTrait<"NoDuplicate">; -def NoBuiltin : LlvmEnumAttributeTrait<"NoBuiltin">; -def Builtin : LlvmEnumAttributeTrait<"Builtin">; -def InlineHint : LlvmEnumAttributeTrait<"InlineHint">; -def AlwaysInline : LlvmEnumAttributeTrait<"AlwaysInline">; -def Cold : LlvmEnumAttributeTrait<"Cold">; -def Hot : LlvmEnumAttributeTrait<"Hot">; -def Convergent : LlvmEnumAttributeTrait<"Convergent">; -def Speculatable : LlvmEnumAttributeTrait<"Speculatable">; +def NoUnwind : LlvmEnumAttributeTrait<"NoUnwind", [FnTrait]>; +def WillReturn : LlvmEnumAttributeTrait<"WillReturn", [FnTrait]>; +def NoReturn : LlvmEnumAttributeTrait<"NoReturn", [FnTrait]>; +def NoRecurse : LlvmEnumAttributeTrait<"NoRecurse", [FnTrait]>; +def NoSync : LlvmEnumAttributeTrait<"NoSync", [FnTrait]>; +def NoFree : LlvmEnumAttributeTrait<"NoFree", [FnTrait]>; +def MustProgress : LlvmEnumAttributeTrait<"MustProgress", [FnTrait]>; +def NoCallback : LlvmEnumAttributeTrait<"NoCallback", [FnTrait]>; +def NoDuplicate : LlvmEnumAttributeTrait<"NoDuplicate", [FnTrait]>; +def NoBuiltin : LlvmEnumAttributeTrait<"NoBuiltin", [FnTrait]>; +def Builtin : LlvmEnumAttributeTrait<"Builtin", [FnTrait]>; +def InlineHint : LlvmEnumAttributeTrait<"InlineHint", [FnTrait]>; +def AlwaysInline : LlvmEnumAttributeTrait<"AlwaysInline", [FnTrait]>; +def Cold : LlvmEnumAttributeTrait<"Cold", [FnTrait]>; +def Hot : LlvmEnumAttributeTrait<"Hot", [FnTrait]>; +def Convergent : LlvmEnumAttributeTrait<"Convergent", [FnTrait]>; +def Speculatable : LlvmEnumAttributeTrait<"Speculatable", [FnTrait]>; + +def NoCapture : LlvmEnumAttributeTrait<"NoCapture", [ParamTrait]>; +def ReadOnly : LlvmEnumAttributeTrait<"ReadOnly", [ParamTrait]>; + +def NoUndef : LlvmEnumAttributeTrait<"NoUndef", [ParamTrait, RetTrait]>; +def NonNull : LlvmEnumAttributeTrait<"NonNull", [ParamTrait, RetTrait]>; + /// Represent the LLVM `memory(...)` attribute as the OR (or union) of memory /// effects. An empty effects list means the operation does not access memory @@ -356,7 +370,7 @@ def Speculatable : LlvmEnumAttributeTrait<"Speculatable">; /// Example: `Memory<[(ref), (mod ArgMem, InaccessibleMem)]>` means the /// operation may read from any kind of memory and write to argument and /// inaccessible memory. -class Memory effects_> : Trait { +class Memory effects_> : Trait<[FnTrait]> { list effects = effects_; } @@ -410,6 +424,8 @@ class Op traits_> { dag arguments = ?; dag results = ?; + list value_traits = []; + list verifier = []; string summary = ?; diff --git a/test/unit/dialect/TestDialect.td b/test/unit/dialect/TestDialect.td index b22c36e..f3c8881 100644 --- a/test/unit/dialect/TestDialect.td +++ b/test/unit/dialect/TestDialect.td @@ -66,6 +66,17 @@ def DialectOp4 : TestOp<"dialect.op.4", []> { let summary = "Test operation 4"; } +def DialectOp5 : TestOp<"dialect.op.5", []> { + let results = (outs Ptr:$ptr); + let arguments = (ins Ptr:$result); + + let value_traits = [ + (ReadOnly $ptr), + (NoCapture $ptr), + (NonNull $result) + ]; +} + def InstNameConflictTestOp : Op { let results = (outs); let arguments = (ins value:$instName, value:$inst__name);