MLIR 24.0.0git
mlir::OperationEquivalence Struct Reference

This class provides utilities for computing if two operations are equivalent. More...

#include "mlir/IR/OperationSupport.h"

Public Types

enum  Flags {
  None = 0 , IgnoreLocations = 1 , IgnoreDiscardableAttrs = 2 , IgnoreProperties = 4 ,
  IgnoreCommutativity = 8
}

Static Public Member Functions

static llvm::hash_code computeHash (Operation *op, function_ref< llvm::hash_code(Value)> hashOperands=[](Value v) { return hash_value(v);}, function_ref< llvm::hash_code(Value)> hashResults=[](Value v) { return hash_value(v);}, Flags flags=Flags::None)
 Compute a hash for the given operation.
static llvm::hash_code ignoreHashValue (Value)
 Helper that can be used with computeHash above to ignore operation operands/result mapping.
static llvm::hash_code directHashValue (Value v)
 Helper that can be used with computeHash to compute the hash value of operands/results directly.
static bool isEquivalentTo (Operation *lhs, Operation *rhs, function_ref< LogicalResult(Value, Value)> checkEquivalent, function_ref< void(Value, Value)> markEquivalent=nullptr, Flags flags=Flags::None, function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent=nullptr)
 Compare two operations (including their regions) and return if they are equivalent.
static bool isEquivalentTo (Operation *lhs, Operation *rhs, Flags flags)
 Compare two operations and return if they are equivalent.
static bool isRegionEquivalentTo (Region *lhs, Region *rhs, function_ref< LogicalResult(Value, Value)> checkEquivalent, function_ref< void(Value, Value)> markEquivalent, OperationEquivalence::Flags flags, function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent=nullptr)
 Compare two regions (including their subregions) and return if they are equivalent.
static bool isRegionEquivalentTo (Region *lhs, Region *rhs, OperationEquivalence::Flags flags)
 Compare two regions and return if they are equivalent.
static LogicalResult ignoreValueEquivalence (Value lhs, Value rhs)
 Helper that can be used with isEquivalentTo above to consider ops equivalent even if their operands are not equivalent.
static LogicalResult exactValueMatch (Value lhs, Value rhs)
 Helper that can be used with isEquivalentTo above to consider ops equivalent only if their operands are the exact same SSA values.

Detailed Description

This class provides utilities for computing if two operations are equivalent.

Definition at line 1400 of file OperationSupport.h.

Member Enumeration Documentation

◆ Flags

Enumerator
None 
IgnoreLocations 
IgnoreDiscardableAttrs 
IgnoreProperties 
IgnoreCommutativity 

Definition at line 1401 of file OperationSupport.h.

Member Function Documentation

◆ computeHash()

llvm::hash_code OperationEquivalence::computeHash ( Operation * op,
function_ref< llvm::hash_code(Value)> hashOperands = [](Value v) { return hash_value(v); },
function_ref< llvm::hash_code(Value)> hashResults = [](Value v) { return hash_value(v); },
Flags flags = Flags::None )
static

◆ directHashValue()

llvm::hash_code mlir::OperationEquivalence::directHashValue ( Value v)
inlinestatic

Helper that can be used with computeHash to compute the hash value of operands/results directly.

Definition at line 1437 of file OperationSupport.h.

References mlir::hash_value().

Referenced by mlirOperationStructuralHashValue().

◆ exactValueMatch()

LogicalResult mlir::OperationEquivalence::exactValueMatch ( Value lhs,
Value rhs )
inlinestatic

Helper that can be used with isEquivalentTo above to consider ops equivalent only if their operands are the exact same SSA values.

Definition at line 1493 of file OperationSupport.h.

References success().

◆ ignoreHashValue()

llvm::hash_code mlir::OperationEquivalence::ignoreHashValue ( Value )
inlinestatic

◆ ignoreValueEquivalence()

LogicalResult mlir::OperationEquivalence::ignoreValueEquivalence ( Value lhs,
Value rhs )
inlinestatic

Helper that can be used with isEquivalentTo above to consider ops equivalent even if their operands are not equivalent.

Definition at line 1488 of file OperationSupport.h.

References success().

Referenced by SelectCommonElementwiseOp::matchAndRewrite().

◆ isEquivalentTo() [1/2]

bool OperationEquivalence::isEquivalentTo ( Operation * lhs,
Operation * rhs,
Flags flags )
static

◆ isEquivalentTo() [2/2]

bool OperationEquivalence::isEquivalentTo ( Operation * lhs,
Operation * rhs,
function_ref< LogicalResult(Value, Value)> checkEquivalent,
function_ref< void(Value, Value)> markEquivalent = nullptr,
Flags flags = Flags::None,
function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent = nullptr )
static

Compare two operations (including their regions) and return if they are equivalent.

  • checkEquivalent is a callback to check if two values are equivalent. For two operations to be equivalent, their operands must be the same SSA value or this callback must return success.
  • markEquivalent is a callback invoked tentatively for corresponding values before full equivalence is established; it may be called even when the comparison returns false.
  • checkCommutativeEquivalent is an optional callback to check for equivalence across two ranges for a commutative operation. If not passed in, then equivalence is checked pairwise. This callback is needed to be able to query the optional equivalence classes.

Note: Additional information regarding value equivalence can be injected into the analysis via checkEquivalent. Typically, callers may want values marked via markEquivalent to be reflected in checkEquivalent, unless exactValueMatch or a different equivalence relationship is desired.

Definition at line 985 of file OperationSupport.cpp.

References compareLocalOperationFeatures(), compareOperationOperands(), isRegionEquivalentTo(), and markResultsEquivalent().

Referenced by isEquivalentTo(), SelectCommonElementwiseOp::matchAndRewrite(), mlirOperationIsStructurallyEquivalent(), and valsAreEquivalent().

◆ isRegionEquivalentTo() [1/2]

bool OperationEquivalence::isRegionEquivalentTo ( Region * lhs,
Region * rhs,
function_ref< LogicalResult(Value, Value)> checkEquivalent,
function_ref< void(Value, Value)> markEquivalent,
OperationEquivalence::Flags flags,
function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent = nullptr )
static

Compare two regions (including their subregions) and return if they are equivalent.

Block arguments and direct operation results across the region are passed to markEquivalent before checking operands, successors, or nested regions, supporting non-lexical dominance order and forward or cyclic value references. See also isEquivalentTo for callback details.

Definition at line 841 of file OperationSupport.cpp.

References compareLocalOperationFeatures(), compareOperationOperands(), mlir::Block::getArguments(), mlir::Block::getNumArguments(), mlir::Operation::getRegions(), mlir::Operation::getSuccessors(), IgnoreLocations, isRegionEquivalentTo(), and markResultsEquivalent().

Referenced by isEquivalentTo(), isRegionEquivalentTo(), and isRegionEquivalentTo().

◆ isRegionEquivalentTo() [2/2]

bool OperationEquivalence::isRegionEquivalentTo ( Region * lhs,
Region * rhs,
OperationEquivalence::Flags flags )
static

The documentation for this struct was generated from the following files: