MLIR  18.0.0git
Go to the documentation of this file.
1 //===- FoldInterfaces.h - Folding Interfaces --------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/SmallVector.h"
16 namespace mlir {
17 class Attribute;
18 class OpFoldResult;
19 class Region;
21 /// Define a fold interface to allow for dialects to control specific aspects
22 /// of the folding behavior for operations they define.
24  : public DialectInterface::Base<DialectFoldInterface> {
25 public:
26  DialectFoldInterface(Dialect *dialect) : Base(dialect) {}
28  /// Registered fallback fold for the dialect. Like the fold hook of each
29  /// operation, it attempts to fold the operation with the specified constant
30  /// operand values - the elements in "operands" will correspond directly to
31  /// the operands of the operation, but may be null if non-constant. If
32  /// folding is successful, this fills in the `results` vector. If not, this
33  /// returns failure and `results` is unspecified.
35  SmallVectorImpl<OpFoldResult> &results) const {
36  return failure();
37  }
39  /// Registered hook to check if the given region, which is attached to an
40  /// operation that is *not* isolated from above, should be used when
41  /// materializing constants. The folder will generally materialize constants
42  /// into the top-level isolated region, this allows for materializing into a
43  /// lower level ancestor region if it is more profitable/correct.
44  virtual bool shouldMaterializeInto(Region *region) const { return false; }
45 };
47 } // namespace mlir
Define a fold interface to allow for dialects to control specific aspects of the folding behavior for...
virtual LogicalResult fold(Operation *op, ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results) const
Registered fallback fold for the dialect.
DialectFoldInterface(Dialect *dialect)
virtual bool shouldMaterializeInto(Region *region) const
Registered hook to check if the given region, which is attached to an operation that is not isolated ...
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition: Dialect.h:41
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
The base class used for all derived interface types.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26