MLIR 22.0.0git
LoopInvariantCodeMotionUtils.cpp File Reference
#include "mlir/Transforms/LoopInvariantCodeMotionUtils.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Interfaces/SubsetOpInterface.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include <queue>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "licm"

Functions

static bool canBeHoisted (Operation *op, function_ref< bool(OpOperand &)> condition)
 Checks whether the given op can be hoisted by checking that.
static bool canBeHoisted (Operation *op, function_ref< bool(Value)> definedOutside)
static OpOperandgetSingleTerminatorUse (Value value)
 If the given value has a single use by an op that is a terminator, return that use.
static LoopLikeOpInterface hoistSubsetAtIterArg (RewriterBase &rewriter, LoopLikeOpInterface loopLike, BlockArgument iterArg)
 Hoist all subset ops that operate on the idx-th region iter_arg of the given loop-like op and index into loop-invariant subset locations.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "licm"

Definition at line 25 of file LoopInvariantCodeMotionUtils.cpp.

Function Documentation

◆ canBeHoisted() [1/2]

bool canBeHoisted ( Operation * op,
function_ref< bool(OpOperand &)> condition )
static

Checks whether the given op can be hoisted by checking that.

  • the op and none of its contained operations depend on values inside of the loop (by means of calling definedOutside).
  • the op has no side-effects.

Definition at line 33 of file LoopInvariantCodeMotionUtils.cpp.

References mlir::WalkResult::advance(), mlir::Operation::hasTrait(), mlir::WalkResult::interrupt(), mlir::Operation::isAncestor(), and mlir::Operation::walk().

Referenced by canBeHoisted(), and mlir::moveLoopInvariantCode().

◆ canBeHoisted() [2/2]

bool canBeHoisted ( Operation * op,
function_ref< bool(Value)> definedOutside )
static

◆ getSingleTerminatorUse()

OpOperand * getSingleTerminatorUse ( Value value)
static

If the given value has a single use by an op that is a terminator, return that use.

Otherwise, return nullptr.

Definition at line 233 of file LoopInvariantCodeMotionUtils.cpp.

References mlir::detail::IROperandBase::getOwner(), mlir::Value::getUses(), mlir::Value::hasOneUse(), and mlir::Operation::hasTrait().

◆ hoistSubsetAtIterArg()

LoopLikeOpInterface hoistSubsetAtIterArg ( RewriterBase & rewriter,
LoopLikeOpInterface loopLike,
BlockArgument iterArg )
static

Hoist all subset ops that operate on the idx-th region iter_arg of the given loop-like op and index into loop-invariant subset locations.

Return the newly created loop op (that has extra iter_args) or the original loop op if nothing was hoisted.

Definition at line 324 of file LoopInvariantCodeMotionUtils.cpp.

References b, canBeHoisted(), mlir::IROperand< DerivedT, IRValueT >::get(), mlir::BlockArgument::getOwner(), mlir::Block::getParentOp(), mlir::RewriterBase::moveOpAfter(), mlir::RewriterBase::moveOpBefore(), and mlir::RewriterBase::replaceAllUsesWith().

Referenced by mlir::hoistLoopInvariantSubsets().