MLIR 22.0.0git
InlinerInterfaceImpl.cpp File Reference
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
#include "mlir/Analysis/SliceWalk.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "llvm-inliner"

Functions

static bool hasLifetimeMarkers (LLVM::AllocaOp allocaOp)
 Check whether the given alloca is an input to a lifetime intrinsic, optionally passing through one or more casts on the way.
static void handleInlinedAllocas (Operation *call, iterator_range< Region::iterator > inlinedBlocks)
 Handles alloca operations in the inlined blocks:
static void deepCloneAliasScopes (iterator_range< Region::iterator > inlinedBlocks)
 Maps all alias scopes in the inlined operations to deep clones of the scopes and domain.
static ArrayAttr concatArrayAttr (ArrayAttr lhs, ArrayAttr rhs)
 Creates a new ArrayAttr by concatenating lhs with rhs.
static FailureOr< SmallVector< Value > > getUnderlyingObjectSet (Value pointerValue)
 Attempts to return the set of all underlying pointer values that pointerValue is based on.
static void createNewAliasScopesFromNoAliasParameter (Operation *call, iterator_range< Region::iterator > inlinedBlocks)
 Creates a new AliasScopeAttr for every noalias parameter and attaches it to the appropriate inlined memory operations in an attempt to preserve the original semantics of the parameter attribute.
static void appendCallOpAliasScopes (Operation *call, iterator_range< Region::iterator > inlinedBlocks)
 Appends any alias scopes of the call operation to any inlined memory operation.
static void handleAliasScopes (Operation *call, iterator_range< Region::iterator > inlinedBlocks)
 Handles all interactions with alias scopes during inlining.
static void handleAccessGroups (Operation *call, iterator_range< Region::iterator > inlinedBlocks)
 Appends any access groups of the call operation to any inlined memory operation.
static void handleLoopAnnotations (Operation *call, iterator_range< Region::iterator > inlinedBlocks)
 Updates locations inside loop annotations to reflect that they were inlined.
static uint64_t tryToEnforceAllocaAlignment (LLVM::AllocaOp alloca, uint64_t requestedAlignment, DataLayout const &dataLayout)
 If requestedAlignment is higher than the alignment specified on alloca, realigns alloca if this does not exceed the natural stack alignment.
static uint64_t tryToEnforceAlignment (Value value, uint64_t requestedAlignment, DataLayout const &dataLayout)
 Tries to find and return the alignment of the pointer value by looking for an alignment attribute on the defining allocation op or function argument.
static Value handleByValArgumentInit (OpBuilder &builder, Location loc, Value argument, Type elementType, uint64_t elementTypeSize, uint64_t targetAlignment)
 Introduces a new alloca and copies the memory pointed to by argument to the address of the new alloca, then returns the value of the new alloca.
static Value handleByValArgument (OpBuilder &builder, Operation *callable, Value argument, Type elementType, uint64_t requestedAlignment)
 Handles a function argument marked with the byval attribute by introducing a memcpy or realigning the defining operation, if required either due to the pointee being writeable in the callee, and/or due to an alignment mismatch.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "llvm-inliner"

Definition at line 27 of file InlinerInterfaceImpl.cpp.

Function Documentation

◆ appendCallOpAliasScopes()

void appendCallOpAliasScopes ( Operation * call,
iterator_range< Region::iterator > inlinedBlocks )
static

Appends any alias scopes of the call operation to any inlined memory operation.

Definition at line 429 of file InlinerInterfaceImpl.cpp.

References ArrayAttr(), and concatArrayAttr().

Referenced by handleAliasScopes().

◆ concatArrayAttr()

ArrayAttr concatArrayAttr ( ArrayAttr lhs,
ArrayAttr rhs )
static

Creates a new ArrayAttr by concatenating lhs with rhs.

Returns null if both parameters are null. If only one attribute is null, return the other.

Definition at line 217 of file InlinerInterfaceImpl.cpp.

References ArrayAttr(), lhs, result, and rhs.

Referenced by appendCallOpAliasScopes(), createNewAliasScopesFromNoAliasParameter(), and handleAccessGroups().

◆ createNewAliasScopesFromNoAliasParameter()

void createNewAliasScopesFromNoAliasParameter ( Operation * call,
iterator_range< Region::iterator > inlinedBlocks )
static

Creates a new AliasScopeAttr for every noalias parameter and attaches it to the appropriate inlined memory operations in an attempt to preserve the original semantics of the parameter attribute.

Definition at line 271 of file InlinerInterfaceImpl.cpp.

References concatArrayAttr(), mlir::Operation::getContext(), mlir::Operation::getLoc(), getUnderlyingObjectSet(), mlir::Operation::getUsers(), mlir::m_Constant(), and mlir::matchPattern().

Referenced by handleAliasScopes().

◆ deepCloneAliasScopes()

void deepCloneAliasScopes ( iterator_range< Region::iterator > inlinedBlocks)
static

Maps all alias scopes in the inlined operations to deep clones of the scopes and domain.

This is required for code such as foo(a, b); foo(a2, b2); to not incorrectly return noalias for e.g. operations on a and a2.

Definition at line 158 of file InlinerInterfaceImpl.cpp.

References mlir::AttrTypeWalker::addWalk(), ArrayAttr(), and mlir::AttrTypeWalker::walk().

Referenced by handleAliasScopes().

◆ getUnderlyingObjectSet()

FailureOr< SmallVector< Value > > getUnderlyingObjectSet ( Value pointerValue)
static

Attempts to return the set of all underlying pointer values that pointerValue is based on.

This function traverses through select operations and block arguments.

Definition at line 233 of file InlinerInterfaceImpl.cpp.

References mlir::WalkContinuation::advanceTo(), mlir::getControlFlowPredecessors(), mlir::Value::getDefiningOp(), mlir::WalkContinuation::interrupt(), result, mlir::WalkContinuation::skip(), mlir::walkSlice(), and mlir::WalkContinuation::wasInterrupted().

Referenced by createNewAliasScopesFromNoAliasParameter().

◆ handleAccessGroups()

void handleAccessGroups ( Operation * call,
iterator_range< Region::iterator > inlinedBlocks )
static

Appends any access groups of the call operation to any inlined memory operation.

Definition at line 467 of file InlinerInterfaceImpl.cpp.

References concatArrayAttr().

◆ handleAliasScopes()

void handleAliasScopes ( Operation * call,
iterator_range< Region::iterator > inlinedBlocks )
static

Handles all interactions with alias scopes during inlining.

Definition at line 458 of file InlinerInterfaceImpl.cpp.

References appendCallOpAliasScopes(), createNewAliasScopesFromNoAliasParameter(), and deepCloneAliasScopes().

◆ handleByValArgument()

Value handleByValArgument ( OpBuilder & builder,
Operation * callable,
Value argument,
Type elementType,
uint64_t requestedAlignment )
static

Handles a function argument marked with the byval attribute by introducing a memcpy or realigning the defining operation, if required either due to the pointee being writeable in the callee, and/or due to an alignment mismatch.

requestedAlignment specifies the alignment set in the "align" argument attribute (or 1 if no align attribute was set).

Definition at line 630 of file InlinerInterfaceImpl.cpp.

References mlir::DataLayout::closest(), mlir::Value::getLoc(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypeSize(), handleByValArgumentInit(), and tryToEnforceAlignment().

◆ handleByValArgumentInit()

Value handleByValArgumentInit ( OpBuilder & builder,
Location loc,
Value argument,
Type elementType,
uint64_t elementTypeSize,
uint64_t targetAlignment )
static

Introduces a new alloca and copies the memory pointed to by argument to the address of the new alloca, then returns the value of the new alloca.

Definition at line 599 of file InlinerInterfaceImpl.cpp.

References mlir::Builder::getI64IntegerAttr(), mlir::Builder::getI64Type(), mlir::Value::getParentRegion(), mlir::Value::getType(), and mlir::OpBuilder::setInsertionPointToStart().

Referenced by handleByValArgument().

◆ handleInlinedAllocas()

void handleInlinedAllocas ( Operation * call,
iterator_range< Region::iterator > inlinedBlocks )
static

Handles alloca operations in the inlined blocks:

  • Moves all alloca operations with a constant size in the former entry block of the callee into the entry block of the caller, so they become part of the function prologue/epilogue during code generation.
  • Inserts lifetime intrinsics that limit the scope of inlined static allocas to the inlined blocks.
  • Inserts StackSave and StackRestore operations if dynamic allocas were inlined.

Definition at line 56 of file InlinerInterfaceImpl.cpp.

References mlir::Block::begin(), mlir::Region::front(), mlir::Operation::getContext(), mlir::Operation::getLoc(), mlir::Block::getOps(), mlir::Operation::getParentOp(), mlir::Operation::getParentRegion(), mlir::Builder::getType(), hasLifetimeMarkers(), mlir::m_Constant(), mlir::matchPattern(), mlir::OpBuilder::setInsertionPoint(), and mlir::OpBuilder::setInsertionPointToStart().

◆ handleLoopAnnotations()

◆ hasLifetimeMarkers()

bool hasLifetimeMarkers ( LLVM::AllocaOp allocaOp)
static

Check whether the given alloca is an input to a lifetime intrinsic, optionally passing through one or more casts on the way.

This is not transitive through block arguments.

Definition at line 34 of file InlinerInterfaceImpl.cpp.

References mlir::Operation::getUsers().

Referenced by handleInlinedAllocas().

◆ tryToEnforceAlignment()

uint64_t tryToEnforceAlignment ( Value value,
uint64_t requestedAlignment,
DataLayout const & dataLayout )
static

Tries to find and return the alignment of the pointer value by looking for an alignment attribute on the defining allocation op or function argument.

If the found alignment is lower than requestedAlignment, tries to realign the pointer, then returns the resulting post-alignment, regardless of whether it was realigned or not. If no existing alignment attribute is found, returns 1 (i.e., assume that no alignment is guaranteed).

Definition at line 569 of file InlinerInterfaceImpl.cpp.

References mlir::Value::getDefiningOp(), mlir::Value::getParentBlock(), mlir::Block::getParentOp(), mlir::SymbolTable::lookupNearestSymbolFrom(), and tryToEnforceAllocaAlignment().

Referenced by handleByValArgument().

◆ tryToEnforceAllocaAlignment()

uint64_t tryToEnforceAllocaAlignment ( LLVM::AllocaOp alloca,
uint64_t requestedAlignment,
DataLayout const & dataLayout )
static

If requestedAlignment is higher than the alignment specified on alloca, realigns alloca if this does not exceed the natural stack alignment.

Returns the post-alignment of alloca, whether it was realigned or not.

Definition at line 540 of file InlinerInterfaceImpl.cpp.

References mlir::DataLayout::getStackAlignment().

Referenced by tryToEnforceAlignment().