MLIR  20.0.0git
Public Types | Static Public Member Functions | List of all members
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 }
 

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. More...
 
static llvm::hash_code ignoreHashValue (Value)
 Helper that can be used with computeHash above to ignore operation operands/result mapping. More...
 
static llvm::hash_code directHashValue (Value v)
 Helper that can be used with computeHash above to ignore operation operands/result mapping. More...
 
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. More...
 
static bool isEquivalentTo (Operation *lhs, Operation *rhs, Flags flags)
 Compare two operations and return if they are equivalent. More...
 
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. More...
 
static bool isRegionEquivalentTo (Region *lhs, Region *rhs, OperationEquivalence::Flags flags)
 Compare two regions and return if they are equivalent. More...
 
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. More...
 
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. More...
 

Detailed Description

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

Definition at line 1272 of file OperationSupport.h.

Member Enumeration Documentation

◆ Flags

Enumerator
None 
IgnoreLocations 

Definition at line 1273 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()

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

Helper that can be used with computeHash above to ignore operation operands/result mapping.

Definition at line 1298 of file OperationSupport.h.

References mlir::hash_value().

◆ exactValueMatch()

static 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 1350 of file OperationSupport.h.

◆ ignoreHashValue()

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

Helper that can be used with computeHash above to ignore operation operands/result mapping.

Definition at line 1295 of file OperationSupport.h.

◆ ignoreValueEquivalence()

static 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 1345 of file OperationSupport.h.

◆ 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 to inform the caller that the analysis determined that two values are equivalent.
  • 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 that were determined to be equivalent as per markEquivalent to be reflected in checkEquivalent, unless exactValueMatch or a different equivalence relationship is desired.

Definition at line 828 of file OperationSupport.cpp.

References mlir::OperationName::compareOpProperties(), mlir::Operation::getLoc(), mlir::Operation::getName(), mlir::Operation::getNumOperands(), mlir::Operation::getNumRegions(), mlir::Operation::getNumResults(), mlir::Operation::getNumSuccessors(), mlir::Operation::getOperands(), mlir::Operation::getPropertiesStorage(), mlir::Operation::getRawDictionaryAttrs(), mlir::Operation::getRegions(), mlir::Operation::getResults(), mlir::Value::getType(), mlir::Operation::hasTrait(), IgnoreLocations, and isRegionEquivalentTo().

Referenced by isEquivalentTo(), and isRegionEquivalentTo().

◆ 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.

See also isEquivalentTo for details.

Definition at line 708 of file OperationSupport.cpp.

References mlir::Block::getArguments(), mlir::Value::getLoc(), mlir::Block::getNumArguments(), mlir::Operation::getSuccessors(), mlir::Value::getType(), IgnoreLocations, and isEquivalentTo().

Referenced by isEquivalentTo(), 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: