Generic Interfaces#
Op Interfaces#
CaptureInterface (CaptureInterface
)
This interface allows operations to specify whether they capture an object reference. A capture is defined as copying the object reference itself, making it possible for it to persist longer than its SSA value. Operations that simply use an object reference as operand to read from are typical examples for operations that do not capture. A store into an aggregate which copies the object reference is a typical example for an operation that captures that specific value.
For the ease of definition the Captured
annotation can be used to annotate
that an operation captures the value input into the annotated operand.
Methods:
capturesValue
bool capturesValue(::mlir::Value value);
Returns whether the operation captures the value.
ConditionalBranchInterface (ConditionalBranchInterface
)
Interface that can be used by passes to get implied values from a branching terminator instructions. Example for this includes eg. a conditional branch instruction. It implies that the value for its condition is true, within the path of its true destination and false within the path of its false destination, until some merge point has been reached.
Methods:
getBranchImplications
::llvm::SmallVector<std::pair<mlir::Block*, mlir::Attribute>> getBranchImplications();
Method called to get the implications of the branch instruction.
It should simply return a list of pairs consisting of a successor and the
constant the value returned by getCondition
has for the given successor.
Implementations itself should not care about contradicting or duplicate
successors.
getCondition
mlir::Value getCondition();
Returns the condition value that is used to decide the branch and whose value is implied within the operations successors.
MemoryFoldInterface (MemoryFoldInterface
)
Methods:
foldUsage
::mlir::LogicalResult foldUsage(mlir::Operation*lastClobber, ::llvm::SmallVectorImpl<::mlir::OpFoldResult>&results);
SROAAllocOpInterface (SROAAllocOpInterface
)
This interface signifies that an aggregate created by this operation should
participate in SROA.
SROA works by deconstructing an aggregate type into its elements.
This only works if given read and write operations statically know which
value within the aggregate they’re referring to.
See the SROAReadWriteOpInterface
below for read and write operations.
Methods:
canParticipateInSROA
::mlir::LogicalResult canParticipateInSROA();
Called to check whether this operations allocation can participate in SROA. The default implementations imply returns success.
replaceAggregate
void replaceAggregate(::mlir::OpBuilder&builder, ::llvm::function_ref<void(mlir::Attribute, mlir::SideEffects::Resource*, mlir::Value)> write);
Called during replacement of the aggregate.
The purpose of this method is to be able to initialize the values of the
aggregate.
This is done via the callback write
, which takes three arguments.
The first is the key, which is used by all participating
‘SROAReadWriteOpInterface’ operations and this operation to identity a
value within the aggregate.
The second argument is a memory resource, which acts as an additional
scoping mechanism when later retrieving a value.
To read a value written here, using the same key and scope is required.
The last argument is the value that should be written to the value within
the aggregate.
If any operations should be created during the process builder
may be
used, which has its insertion point set to right before the operation.
SROAReadWriteOpInterface (SROAReadWriteOpInterface
)
This interface should be used on read or write operations of aggregates that should be able to participate in SROA. Only if all uses of an aggregate are in read or write operations implementing the interface can it be fully replaced.
This interface makes use of two OpVariable
s to ease definition.
SROAAggregate
must be attached to one operand which is the aggregate that
is being read from or written to. When SROA checks if all uses are read and
write ops it makes sure that these uses are the aggregate operand of read
write ops.
Additionally, one may optionally add SROAKey
to at max one operand.
The key is an operand which is used to find out the precise value that is
being read from or written to within the aggregate.
If the operation has such a key operand that is simply a constant operand,
one can use SROAKey
to autogenerate the getKey
method.
Otherwise, the method should override getKey
to return an appropriate key.
Methods:
getAggregateOperand
::mlir::OpOperand&getAggregateOperand();
Returns the aggregate operand which is read from or written to.
getSROAKey
::mlir::FailureOr<::mlir::Attribute> getSROAKey();
Returns the key identifying the operand that is used to identify the
precise location that is read from or written to within the aggregate, or
nullptr if no such key exists, as the operation always reads or writes to
a fixed value within the aggregate.
The result of this method (including nullptr) is then passed onto
replaceAggregate
.
The default implementation simply returns nullptr.
If the op cannot participate in SROA due to no suitable key being able to be gathered, failure should be returned.
replaceAggregate
void replaceAggregate(::mlir::OpBuilder&builder, ::mlir::Attribute optionalKey, ::llvm::function_ref<mlir::Value(mlir::Attribute, mlir::SideEffects::Resource*, mlir::Type)> read, ::llvm::function_ref<void(mlir::Attribute, mlir::SideEffects::Resource*, mlir::Value)> write);
Called during the replacement of the aggregate.
Using the callbacks read
and write
one can make reads and writes to
specific values within the aggregate.
These values are located via the Attribute
passed as the first argument
and the ‘Resource’ passed as the second argument to each callback
respectively.
read
s third argument is the type of the value to be read.
It then returns the given value. write
s third argument is the value that
should be written to the value within the aggregate.
builder
may be used in case any operations are to be created and has its
insertion point set before this operation.
optionalKey
is the static value of the SROAKey
operand returned by
getSROAKey
or a null attribute if no operand was annotated as such.
If this operation has any results they’re required to have no uses after this operations.
Attribute Interfaces#
AttrVerifyInterface (AttrVerifyInterface
)
This attribute interface allows verifying the structural properties of an attribute. Common use cases include attributes referencing symbols and checking that the referred to operation is of a specific shape and kind and attributes using mutable attributes and requiring the cycle, and therefore creation and parsing, to be complete prior to verification.
Methods:
verifyStructure
mlir::LogicalResult verifyStructure(::mlir::Operation*operation, ::mlir::SymbolTableCollection&collection);
Called to verify the structural properties of the attribute.
operation
is an operation that this attribute is transitively reachable
from and can be used to emit errors using the emitError
method.
SROAAttrInterface (SROAAttrInterface
)
Interface for attributes of aggregates to participate in SROA.
Methods:
destructureAggregate
void destructureAggregate(::llvm::function_ref<void(mlir::Attribute, mlir::SideEffects::Resource*, mlir::Type, mlir::Attribute)> write);
Method to initialize the scalar values of an aggregate that is initialized
by an attribute.
This works similarly to the callbacks with replaceAggregate
of
SROAAllocOpInterface
and SROAReadWriteOpInterface
respectively.
write
is used to initialize the values within the aggregate.
The first and second parameters denote the location within the attribute,
and initializes it with value
. Additionally the MLIR type
of the value
has to be passed as second argument.