MLIR 22.0.0git
InliningUtils.cpp File Reference
#include "mlir/Transforms/InliningUtils.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/CallInterfaces.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "inlining"

Functions

static LocationAttr stackLocations (Location callee, Location caller)
 Combine callee location with caller location to create a stack that represents the call chain.
static void remapInlinedLocations (iterator_range< Region::iterator > inlinedBlocks, Location callerLoc)
 Remap all locations reachable from the inlined blocks with CallSiteLoc locations with the provided caller location.
static void remapInlinedOperands (iterator_range< Region::iterator > inlinedBlocks, IRMapping &mapper)
static bool isLegalToInline (InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, IRMapping &valueMapping)
 Utility to check that all of the operations within 'src' can be inlined.
static void handleArgumentImpl (InlinerInterface &interface, OpBuilder &builder, CallOpInterface call, CallableOpInterface callable, IRMapping &mapper)
static void handleResultImpl (InlinerInterface &interface, OpBuilder &builder, CallOpInterface call, CallableOpInterface callable, ValueRange results)
static LogicalResult inlineRegionImpl (InlinerInterface &interface, function_ref< InlinerInterface::CloneCallbackSigTy > cloneCallback, Region *src, Block *inlineBlock, Block::iterator inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, std::optional< Location > inlineLoc, bool shouldCloneInlinedRegion, CallOpInterface call={})
static LogicalResult inlineRegionImpl (InlinerInterface &interface, function_ref< InlinerInterface::CloneCallbackSigTy > cloneCallback, Region *src, Block *inlineBlock, Block::iterator inlinePoint, ValueRange inlinedOperands, ValueRange resultsToReplace, std::optional< Location > inlineLoc, bool shouldCloneInlinedRegion, CallOpInterface call={})
static Value materializeConversion (const DialectInlinerInterface *interface, SmallVectorImpl< Operation * > &castOps, OpBuilder &castBuilder, Value arg, Type type, Location conversionLoc)
 Utility function used to generate a cast operation from the given interface, or return nullptr if a cast could not be generated.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "inlining"

Definition at line 25 of file InliningUtils.cpp.

Function Documentation

◆ handleArgumentImpl()

void handleArgumentImpl ( InlinerInterface & interface,
OpBuilder & builder,
CallOpInterface call,
CallableOpInterface callable,
IRMapping & mapper )
static

◆ handleResultImpl()

void handleResultImpl ( InlinerInterface & interface,
OpBuilder & builder,
CallOpInterface call,
CallableOpInterface callable,
ValueRange results )
static

◆ inlineRegionImpl() [1/2]

LogicalResult inlineRegionImpl ( InlinerInterface & interface,
function_ref< InlinerInterface::CloneCallbackSigTy > cloneCallback,
Region * src,
Block * inlineBlock,
Block::iterator inlinePoint,
IRMapping & mapper,
ValueRange resultsToReplace,
TypeRange regionResultTypes,
std::optional< Location > inlineLoc,
bool shouldCloneInlinedRegion,
CallOpInterface call = {} )
static

Handle the terminators for each of the new blocks.

Definition at line 271 of file InliningUtils.cpp.

Referenced by mlir::inlineCall(), mlir::inlineRegion(), and mlir::inlineRegion().

◆ inlineRegionImpl() [2/2]

LogicalResult inlineRegionImpl ( InlinerInterface & interface,
function_ref< InlinerInterface::CloneCallbackSigTy > cloneCallback,
Region * src,
Block * inlineBlock,
Block::iterator inlinePoint,
ValueRange inlinedOperands,
ValueRange resultsToReplace,
std::optional< Location > inlineLoc,
bool shouldCloneInlinedRegion,
CallOpInterface call = {} )
static

Definition at line 374 of file InliningUtils.cpp.

◆ isLegalToInline()

bool isLegalToInline ( InlinerInterface & interface,
Region * src,
Region * insertRegion,
bool shouldCloneInlinedRegion,
IRMapping & valueMapping )
static

Utility to check that all of the operations within 'src' can be inlined.

Definition at line 182 of file InliningUtils.cpp.

References mlir::InlinerInterface::isLegalToInline(), and mlir::InlinerInterface::shouldAnalyzeRecursively().

◆ materializeConversion()

Value materializeConversion ( const DialectInlinerInterface * interface,
SmallVectorImpl< Operation * > & castOps,
OpBuilder & castBuilder,
Value arg,
Type type,
Location conversionLoc )
static

Utility function used to generate a cast operation from the given interface, or return nullptr if a cast could not be generated.

Definition at line 453 of file InliningUtils.cpp.

References mlir::Operation::getNumOperands(), mlir::Operation::getNumResults(), mlir::Operation::getOperand(), mlir::Operation::getResult(), mlir::DialectInlinerInterface::materializeCallConversion(), and mlir::Operation::result_type_begin().

Referenced by mlir::inlineCall().

◆ remapInlinedLocations()

void remapInlinedLocations ( iterator_range< Region::iterator > inlinedBlocks,
Location callerLoc )
static

Remap all locations reachable from the inlined blocks with CallSiteLoc locations with the provided caller location.

Definition at line 55 of file InliningUtils.cpp.

References mlir::detail::AttrTypeReplacerBase< Concrete >::addReplacement(), inserted(), mlir::detail::AttrTypeReplacerBase< Concrete >::recursivelyReplaceElementsIn(), mlir::WalkResult::skip(), and stackLocations().

◆ remapInlinedOperands()

void remapInlinedOperands ( iterator_range< Region::iterator > inlinedBlocks,
IRMapping & mapper )
static

Definition at line 85 of file InliningUtils.cpp.

References mlir::IRMapping::lookupOrNull().

◆ stackLocations()

LocationAttr stackLocations ( Location callee,
Location caller )
static

Combine callee location with caller location to create a stack that represents the call chain.

If callee location is a CallSiteLoc, indicating an existing stack of locations, the caller location is appended to the end of it, extending the chain. Otherwise, a single CallSiteLoc is created, representing a direct call from caller to callee.

Definition at line 36 of file InliningUtils.cpp.

Referenced by remapInlinedLocations().