Skip to content

Commit

Permalink
define TraitProperty and value_traits
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Oct 17, 2024
1 parent a3f36a8 commit 4e7f24c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
56 changes: 36 additions & 20 deletions include/llvm-dialects/Dialect/Dialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -320,29 +320,43 @@ multiclass AttrEnum<string cppType_> {
/// Traits generally map to llvm::Attributes.
// ============================================================================

class Trait;
class TraitProperty;
def FnTrait : TraitProperty;
def ParamTrait : TraitProperty;
def RetTrait : TraitProperty;

class LlvmEnumAttributeTrait<string llvmEnum_> : Trait {
class Trait<list<TraitProperty> P>{
list<TraitProperty> Properties = P;
}

class LlvmEnumAttributeTrait<string llvmEnum_, list<TraitProperty> P> : Trait<P> {
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
Expand All @@ -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<list<dag> effects_> : Trait {
class Memory<list<dag> effects_> : Trait<[FnTrait]> {
list<dag> effects = effects_;
}

Expand Down Expand Up @@ -410,6 +424,8 @@ class Op<Dialect dialect_, string mnemonic_, list<Trait> traits_> {
dag arguments = ?;
dag results = ?;

list<dag> value_traits = [];

list<dag> verifier = [];

string summary = ?;
Expand Down
11 changes: 11 additions & 0 deletions test/unit/dialect/TestDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestDialect, "try.conflict", [WillReturn]> {
let results = (outs);
let arguments = (ins value:$instName, value:$inst__name);
Expand Down

0 comments on commit 4e7f24c

Please sign in to comment.