MLIR 24.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/IR/RegionGraphTraits.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Interfaces/SubsetOpInterface.h"
#include "llvm/ADT/DepthFirstIterator.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 size_t hoistFromNestedRegions (Region &region, LoopLikeOpInterface loopLike, bool isNested)
 Hoists pure loop-invariant ops out of the control-flow regions nested in region, which is part of the body of loopLike.
static OpOperand * getSingleTerminatorUse (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 28 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 36 of file LoopInvariantCodeMotionUtils.cpp.

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

Referenced by canBeHoisted(), hoistFromNestedRegions(), 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 280 of file LoopInvariantCodeMotionUtils.cpp.

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

◆ hoistFromNestedRegions()

size_t hoistFromNestedRegions ( Region & region,
LoopLikeOpInterface loopLike,
bool isNested )
static

Hoists pure loop-invariant ops out of the control-flow regions nested in region, which is part of the body of loopLike.

Ops directly in region are hoisted only if isNested is set, i.e., if region is not a region of the loop itself. Returns the number of ops moved.

Definition at line 129 of file LoopInvariantCodeMotionUtils.cpp.

References canBeHoisted(), mlir::Region::empty(), mlir::Region::front(), mlir::Operation::getRegions(), hoistFromNestedRegions(), and mlir::isPure().

Referenced by hoistFromNestedRegions(), and mlir::moveLoopInvariantCodeFromNestedRegions().

◆ 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 375 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().