1//===-- SideEffectInterfaces.td - Side Effect Interfaces ---*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a set of interfaces that can be used to define information
10// about what effects are applied by an operation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_INTERFACES_SIDEEFFECTS
15#define MLIR_INTERFACES_SIDEEFFECTS
16
17include "mlir/Interfaces/SideEffectInterfaceBase.td"
18
19//===----------------------------------------------------------------------===//
20// MemoryEffects
21//===----------------------------------------------------------------------===//
22
23// This def represents the definition for the memory effects interface. Users
24// should generally not use this directly, and should instead use
25// `MemoryEffects`.
26def MemoryEffectsOpInterface
27    : EffectOpInterfaceBase<"MemoryEffectOpInterface",
28                            "::mlir::MemoryEffects::Effect"> {
29  let description = [{
30    An interface used to query information about the memory effects applied by
31    an operation.
32  }];
33  let cppNamespace = "::mlir";
34}
35
36// The base class for defining specific memory effects.
37class MemoryEffect<string effectName, Resource resource>
38  : SideEffect<MemoryEffectsOpInterface, effectName, resource>;
39
40// This class represents the trait for memory effects that may be placed on
41// operations.
42class MemoryEffects<list<MemoryEffect> effects = []>
43  : SideEffectsTraitBase<MemoryEffectsOpInterface, effects>;
44
45//===----------------------------------------------------------------------===//
46// Effects
47
48// The following effect indicates that the operation allocates from some
49// resource. An 'allocate' effect implies only allocation of the resource, and
50// not any visible mutation or dereference.
51class MemAlloc<Resource resource>
52  : MemoryEffect<"MemoryEffects::Allocate", resource>;
53def MemAlloc : MemAlloc<DefaultResource>;
54
55// The following effect indicates that the operation frees some resource that
56// has been allocated. A 'free' effect implies only de-allocation of the
57// resource, and not any visible allocation, mutation or dereference.
58class MemFree<Resource resource>
59  : MemoryEffect<"MemoryEffects::Free", resource>;
60def MemFree : MemFree<DefaultResource>;
61
62// The following effect indicates that the operation reads from some
63// resource. A 'read' effect implies only dereferencing of the resource, and
64// not any visible mutation.
65class MemRead<Resource resource>
66  : MemoryEffect<"MemoryEffects::Read", resource>;
67def MemRead : MemRead<DefaultResource>;
68
69// The following effect indicates that the operation writes to some
70// resource. A 'write' effect implies only mutating a resource, and not any
71// visible dereference or read.
72class MemWrite<Resource resource>
73  : MemoryEffect<"MemoryEffects::Write", resource>;
74def MemWrite : MemWrite<DefaultResource>;
75
76//===----------------------------------------------------------------------===//
77// Effect Traits
78//===----------------------------------------------------------------------===//
79
80// Op has no side effect.
81def NoSideEffect : MemoryEffects<[]>;
82// Op has recursively computed side effects.
83def RecursiveSideEffects : NativeOpTrait<"HasRecursiveSideEffects">;
84
85#endif // MLIR_INTERFACES_SIDEEFFECTS
86