31#include "llvm/ADT/ScopeExit.h"
32#include "llvm/Support/Debug.h"
34#include "llvm/Support/DebugLog.h"
36#define DEBUG_TYPE "llvm-inliner"
45 allocaOp->getUsers().end());
46 while (!stack.empty()) {
48 if (isa<LLVM::LifetimeStartOp, LLVM::LifetimeEndOp>(op))
50 if (isa<LLVM::BitcastOp>(op))
74 Block *callerEntryBlock =
nullptr;
88 Block *calleeEntryBlock = &(*inlinedBlocks.begin());
89 if (!callerEntryBlock || callerEntryBlock == calleeEntryBlock)
93 bool shouldInsertLifetimes =
false;
94 bool hasDynamicAlloca =
false;
98 for (
auto allocaOp : calleeEntryBlock->
getOps<LLVM::AllocaOp>()) {
99 IntegerAttr arraySize;
101 hasDynamicAlloca =
true;
104 bool shouldInsertLifetime =
106 shouldInsertLifetimes |= shouldInsertLifetime;
107 allocasToMove.emplace_back(allocaOp, arraySize, shouldInsertLifetime);
110 for (
Block &block : llvm::drop_begin(inlinedBlocks)) {
111 if (hasDynamicAlloca)
114 llvm::any_of(block.getOps<LLVM::AllocaOp>(), [](
auto allocaOp) {
115 return !matchPattern(allocaOp.getArraySize(), m_Constant());
118 if (allocasToMove.empty() && !hasDynamicAlloca)
122 if (hasDynamicAlloca) {
127 stackPtr = LLVM::StackSaveOp::create(
129 LLVM::LLVMPointerType::get(call->
getContext()));
132 for (
auto &[allocaOp, arraySize, shouldInsertLifetime] : allocasToMove) {
134 LLVM::ConstantOp::create(builder, allocaOp->getLoc(),
135 allocaOp.getArraySize().
getType(), arraySize);
137 if (shouldInsertLifetime) {
140 LLVM::LifetimeStartOp::create(builder, allocaOp.getLoc(),
141 allocaOp.getResult());
143 allocaOp->moveAfter(newConstant);
144 allocaOp.getArraySizeMutable().assign(newConstant.getResult());
146 if (!shouldInsertLifetimes && !hasDynamicAlloca)
149 for (
Block &block : inlinedBlocks) {
153 if (hasDynamicAlloca)
154 LLVM::StackRestoreOp::create(builder, call->
getLoc(), stackPtr);
155 for (
auto &[allocaOp, arraySize, shouldInsertLifetime] : allocasToMove) {
156 if (shouldInsertLifetime)
157 LLVM::LifetimeEndOp::create(builder, allocaOp.getLoc(),
158 allocaOp.getResult());
178 walker.
addWalk([&](LLVM::AliasScopeDomainAttr domainAttr) {
179 mapping[domainAttr] = LLVM::AliasScopeDomainAttr::get(
180 domainAttr.getContext(), domainAttr.getDescription(),
181 domainAttr.getDisjointScopes());
184 walker.
addWalk([&](LLVM::AliasScopeAttr scopeAttr) {
185 mapping[scopeAttr] = LLVM::AliasScopeAttr::get(
186 cast<LLVM::AliasScopeDomainAttr>(mapping.lookup(scopeAttr.getDomain())),
187 scopeAttr.getDescription());
196 walker.
walk(arrayAttr);
198 return ArrayAttr::get(arrayAttr.getContext(),
199 llvm::map_to_vector(arrayAttr, [&](
Attribute attr) {
200 return mapping.lookup(attr);
204 for (
Block &block : inlinedBlocks) {
206 if (
auto aliasInterface = dyn_cast<LLVM::AliasAnalysisOpInterface>(op)) {
207 aliasInterface.setAliasScopes(
208 convertScopeList(aliasInterface.getAliasScopesOrNull()));
209 aliasInterface.setNoAliasScopes(
210 convertScopeList(aliasInterface.getNoAliasScopesOrNull()));
213 if (
auto noAliasScope = dyn_cast<LLVM::NoAliasScopeDeclOp>(op)) {
215 walker.
walk(noAliasScope.getScopeAttr());
217 noAliasScope.setScopeAttr(cast<LLVM::AliasScopeAttr>(
218 mapping.lookup(noAliasScope.getScopeAttr())));
234 llvm::append_range(
result, lhs);
235 llvm::append_range(
result, rhs);
236 return ArrayAttr::get(lhs.getContext(),
result);
242static FailureOr<SmallVector<Value>>
248 if (
auto viewOp = val.
getDefiningOp<ViewLikeOpInterface>()) {
249 if (val == viewOp.getViewDest())
254 std::optional<SmallVector<Value>> controlFlowPredecessors =
256 if (controlFlowPredecessors)
260 if (isa<OpResult>(val)) {
293 for (
Value argument : cast<LLVM::CallOp>(call).getArgOperands()) {
295 llvm::make_isa_range<LLVM::SSACopyOp>(argument.getUsers())) {
296 ssaCopies.insert(ssaCopy);
298 if (!ssaCopy->hasDiscardableAttr(LLVM::LLVMDialect::getNoAliasAttrName()))
300 noAliasParams.insert(ssaCopy);
306 llvm::scope_exit exit([&] {
307 for (LLVM::SSACopyOp ssaCopyOp : ssaCopies) {
308 ssaCopyOp.replaceAllUsesWith(ssaCopyOp.getOperand());
314 if (noAliasParams.empty())
319 auto functionDomain = LLVM::AliasScopeDomainAttr::get(
320 call->
getContext(), cast<LLVM::CallOp>(call).getCalleeAttr().getAttr());
322 for (LLVM::SSACopyOp copyOp : noAliasParams) {
323 auto scope = LLVM::AliasScopeAttr::get(functionDomain);
324 pointerScopes[copyOp] = scope;
327 LLVM::NoAliasScopeDeclOp::create(builder, call->
getLoc(), scope);
332 for (
Block &inlinedBlock : inlinedBlocks) {
333 inlinedBlock.walk([&](LLVM::AliasAnalysisOpInterface aliasInterface) {
339 for (
Value pointer : pointerArgs) {
340 FailureOr<SmallVector<Value>> underlyingObjectSet =
342 if (failed(underlyingObjectSet))
344 llvm::copy(*underlyingObjectSet,
345 std::inserter(basedOnPointers, basedOnPointers.begin()));
348 bool aliasesOtherKnownObject =
false;
358 if (llvm::any_of(basedOnPointers, [&](
Value object) {
362 if (
auto ssaCopy =
object.getDefiningOp<LLVM::SSACopyOp>()) {
365 aliasesOtherKnownObject |= !noAliasParams.contains(ssaCopy);
369 if (isa_and_nonnull<LLVM::AllocaOp, LLVM::AddressOfOp>(
370 object.getDefiningOp())) {
371 aliasesOtherKnownObject =
true;
381 for (LLVM::SSACopyOp noAlias : noAliasParams) {
382 if (basedOnPointers.contains(noAlias))
385 noAliasScopes.push_back(pointerScopes[noAlias]);
388 if (!noAliasScopes.empty())
389 aliasInterface.setNoAliasScopes(
391 ArrayAttr::get(call->
getContext(), noAliasScopes)));
417 if (aliasesOtherKnownObject ||
418 isa<LLVM::CallOp>(aliasInterface.getOperation()))
422 for (LLVM::SSACopyOp noAlias : noAliasParams)
423 if (basedOnPointers.contains(noAlias))
424 aliasScopes.push_back(pointerScopes[noAlias]);
426 if (!aliasScopes.empty())
427 aliasInterface.setAliasScopes(
429 ArrayAttr::get(call->
getContext(), aliasScopes)));
439 auto callAliasInterface = dyn_cast<LLVM::AliasAnalysisOpInterface>(call);
440 if (!callAliasInterface)
443 ArrayAttr aliasScopes = callAliasInterface.getAliasScopesOrNull();
444 ArrayAttr noAliasScopes = callAliasInterface.getNoAliasScopesOrNull();
447 if (!aliasScopes && !noAliasScopes)
452 for (
Block &block : inlinedBlocks) {
453 block.walk([&](LLVM::AliasAnalysisOpInterface aliasInterface) {
456 aliasInterface.getAliasScopesOrNull(), aliasScopes));
460 aliasInterface.getNoAliasScopesOrNull(), noAliasScopes));
477 auto callAccessGroupInterface = dyn_cast<LLVM::AccessGroupOpInterface>(call);
478 if (!callAccessGroupInterface)
481 auto accessGroups = callAccessGroupInterface.getAccessGroupsOrNull();
487 for (
Block &block : inlinedBlocks)
488 for (
auto accessGroupOpInterface :
489 block.getOps<LLVM::AccessGroupOpInterface>())
491 accessGroupOpInterface.getAccessGroupsOrNull(), accessGroups));
500 size_t len = std::min(mibStack.size(), callsiteStack.size());
501 return mibStack.take_front(len) == callsiteStack.take_front(len);
522 StringRef callsiteName = LLVM::LLVMDialect::getCallsiteAttrName();
523 StringRef memprofName = LLVM::LLVMDialect::getMemProfAttrName();
532 for (
Block &block : inlinedBlocks) {
537 if (!origCallsite && !memprof)
546 if (inlinedStack.empty()) {
554 newStack.append(inlinedStack.begin(), inlinedStack.end());
560 bool malformed =
false;
562 auto mib = dyn_cast<LLVM::MemProfMIBAttr>(mibAttr);
568 keptMIBs.push_back(mibAttr);
570 if (malformed || keptMIBs.empty()) {
573 }
else if (keptMIBs.size() != memprof.size()) {
583 if (!isa<UnknownLoc>(call->
getLoc()))
593 for (
Block &block : inlinedBlocks)
595 op->
setLoc(CallSiteLoc::get(op->
getLoc(), callSiteLoc));
608 auto fusedLoc = dyn_cast_if_present<FusedLoc>(funcLoc);
612 dyn_cast_if_present<LLVM::DISubprogramAttr>(fusedLoc.getMetadata());
622 return FusedLoc::get(loc.getContext(), callSiteLoc, scope);
626 replacer.
addReplacement([&](LLVM::LoopAnnotationAttr loopAnnotation)
627 -> std::pair<Attribute, WalkResult> {
628 FusedLoc newStartLoc = updateLoc(loopAnnotation.getStartLoc());
629 FusedLoc newEndLoc = updateLoc(loopAnnotation.getEndLoc());
630 if (!newStartLoc && !newEndLoc)
632 auto newLoopAnnotation = LLVM::LoopAnnotationAttr::get(
633 loopAnnotation.getContext(), loopAnnotation.getId(),
634 loopAnnotation.getDisableNonforced(), loopAnnotation.getVectorize(),
635 loopAnnotation.getInterleave(), loopAnnotation.getUnroll(),
636 loopAnnotation.getUnrollAndJam(), loopAnnotation.getLicm(),
637 loopAnnotation.getDistribute(), loopAnnotation.getPipeline(),
638 loopAnnotation.getPeeled(), loopAnnotation.getUnswitch(),
639 loopAnnotation.getMustProgress(), loopAnnotation.getIsVectorized(),
640 loopAnnotation.getAlign(), newStartLoc, newEndLoc,
641 loopAnnotation.getParallelAccesses());
646 for (
Block &block : inlinedBlocks)
655 uint64_t requestedAlignment,
657 uint64_t allocaAlignment = alloca.getAlignment().value_or(1);
658 if (requestedAlignment <= allocaAlignment)
660 return allocaAlignment;
664 if (naturalStackAlignmentBits == 0 ||
667 8 * requestedAlignment <= naturalStackAlignmentBits ||
670 8 * allocaAlignment > naturalStackAlignmentBits) {
671 alloca.setAlignment(requestedAlignment);
672 allocaAlignment = requestedAlignment;
674 return allocaAlignment;
686 if (
auto alloca = dyn_cast<LLVM::AllocaOp>(definingOp))
689 if (
auto addressOf = dyn_cast<LLVM::AddressOfOp>(definingOp))
691 definingOp, addressOf.getGlobalNameAttr()))
692 return global.getAlignment().value_or(1);
699 if (
auto func = dyn_cast<LLVM::LLVMFuncOp>(parentOp)) {
702 auto blockArg = llvm::cast<BlockArgument>(value);
704 blockArg.getArgNumber(), LLVM::LLVMDialect::getAlignAttrName()))
705 return cast<IntegerAttr>(alignAttr).getValue().getLimitedValue();
715 uint64_t elementTypeSize,
716 uint64_t targetAlignment) {
731 Value one = LLVM::ConstantOp::create(builder, loc, builder.
getI64Type(),
733 allocaOp = LLVM::AllocaOp::create(builder, loc, argument.
getType(),
734 elementType, one, targetAlignment);
738 LLVM::ConstantOp::create(builder, loc, builder.
getI64Type(),
743 builder.
getNamedAttr(LLVM::LLVMDialect::getAlignAttrName(),
747 LLVM::MemcpyOp::create(builder, loc, allocaOp, argument, copySize,
751 nullptr,
nullptr, argAttrs,
763 uint64_t requestedAlignment) {
764 auto func = cast<LLVM::LLVMFuncOp>(callable);
765 LLVM::MemoryEffectsAttr memoryEffects =
func.getMemoryEffectsAttr();
768 bool isReadOnly = memoryEffects &&
769 memoryEffects.getArgMem() != LLVM::ModRefInfo::ModRef &&
770 memoryEffects.getArgMem() != LLVM::ModRefInfo::Mod;
775 if (requestedAlignment <= minimumAlignment)
777 uint64_t currentAlignment =
779 if (currentAlignment >= requestedAlignment)
782 uint64_t targetAlignment = std::max(requestedAlignment, minimumAlignment);
784 builder, argument.
getLoc(), argument, elementType,
785 dataLayout.
getTypeSize(elementType), targetAlignment);
789struct LLVMInlinerInterface :
public DialectInlinerInterface {
790 using DialectInlinerInterface::DialectInlinerInterface;
792 LLVMInlinerInterface(Dialect *dialect)
793 : DialectInlinerInterface(dialect),
795 disallowedFunctionAttrs({
796 StringAttr::get(dialect->
getContext(),
"noduplicate"),
797 StringAttr::get(dialect->
getContext(),
"presplitcoroutine"),
798 StringAttr::get(dialect->
getContext(),
"returns_twice"),
802 bool wouldBeCloned)
const final {
803 auto callOp = dyn_cast<LLVM::CallOp>(call);
805 LDBG() <<
"Cannot inline: call is not an '"
806 << LLVM::CallOp::getOperationName() <<
"' op";
809 if (callOp.getNoInline()) {
810 LDBG() <<
"Cannot inline: call is marked no_inline";
813 auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(callable);
815 LDBG() <<
"Cannot inline: callable is not an '"
816 << LLVM::LLVMFuncOp::getOperationName() <<
"' op";
819 if (funcOp.isNoInline()) {
820 LDBG() <<
"Cannot inline: function is marked no_inline";
823 if (funcOp.getStrictfp()) {
824 LDBG() <<
"Cannot inline: function is marked strictfp";
827 if (funcOp.isVarArg()) {
828 LDBG() <<
"Cannot inline: callable is variadic";
832 if (
auto attrs = funcOp.getArgAttrs()) {
833 for (DictionaryAttr attrDict : attrs->getAsRange<DictionaryAttr>()) {
834 if (attrDict.contains(LLVM::LLVMDialect::getInAllocaAttrName())) {
835 LDBG() <<
"Cannot inline " << funcOp.getSymName()
836 <<
": inalloca arguments not supported";
842 if (funcOp.getPersonality()) {
843 LDBG() <<
"Cannot inline " << funcOp.getSymName()
844 <<
": unhandled function personality";
847 if (funcOp.getPassthrough()) {
849 if (llvm::any_of(*funcOp.getPassthrough(), [&](Attribute attr) {
850 auto stringAttr = dyn_cast<StringAttr>(attr);
853 if (disallowedFunctionAttrs.contains(stringAttr)) {
854 LDBG() <<
"Cannot inline " << funcOp.getSymName()
855 <<
": found disallowed function attribute " << stringAttr;
869 for (
Block &block : funcOp.getBody()) {
870 if (!block.empty() && !block.back().hasTrait<OpTrait::IsTerminator>()) {
871 LDBG() <<
"Cannot inline " << funcOp.getSymName()
872 <<
": block ends with non-terminator op";
887 return !(isa<LLVM::VaStartOp>(op) || isa<LLVM::BlockTagOp>(op));
892 void handleTerminator(
Operation *op,
Block *newDest)
const final {
894 auto returnOp = dyn_cast<LLVM::ReturnOp>(op);
900 LLVM::BrOp::create(builder, op->getLoc(), returnOp.getOperands(), newDest);
904 bool allowSingleBlockOptimization(
Block *inlinedBlock)
const final {
905 return !isa<LLVM::UnreachableOp>(inlinedBlock->getTerminator());
913 auto returnOp = cast<LLVM::ReturnOp>(op);
916 assert(returnOp.getNumOperands() == valuesToRepl.size());
917 for (
auto [dst, src] : llvm::zip(valuesToRepl, returnOp.getOperands()))
918 dst.replaceAllUsesWith(src);
923 DictionaryAttr argumentAttrs)
const final {
924 if (std::optional<NamedAttribute> attr =
925 argumentAttrs.getNamed(LLVM::LLVMDialect::getByValAttrName())) {
926 Type elementType = cast<TypeAttr>(attr->getValue()).getValue();
927 uint64_t requestedAlignment = 1;
928 if (std::optional<NamedAttribute> alignAttr =
929 argumentAttrs.getNamed(LLVM::LLVMDialect::getAlignAttrName())) {
930 requestedAlignment = cast<IntegerAttr>(alignAttr->getValue())
950 auto copyOp = LLVM::SSACopyOp::create(builder, call->getLoc(), argument);
951 if (argumentAttrs.contains(LLVM::LLVMDialect::getNoAliasAttrName()))
952 copyOp->setDiscardableAttr(
953 builder.getStringAttr(LLVM::LLVMDialect::getNoAliasAttrName()),
954 builder.getUnitAttr());
958 void processInlinedCallBlocks(
979 dialect->addInterfaces<LLVMInlinerInterface>();
static bool hasLifetimeMarkers(LLVM::AllocaOp allocaOp)
Check whether the given alloca is an input to a lifetime intrinsic, optionally passing through one or...
static void handleMemProfMetadata(Operation *call, iterator_range< Region::iterator > inlinedBlocks)
Updates MemProf metadata on calls inlined into call, matching LLVM's propagateMemProfMetadata.
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 handleLoopAnnotations(Operation *call, iterator_range< Region::iterator > inlinedBlocks)
Updates locations inside loop annotations to reflect that they were inlined.
static ArrayAttr concatArrayAttr(ArrayAttr lhs, ArrayAttr rhs)
Creates a new ArrayAttr by concatenating lhs with rhs.
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 m...
static FailureOr< SmallVector< Value > > getUnderlyingObjectSet(Value pointerValue)
Attempts to return the set of all underlying pointer values that pointerValue is based on.
static void handleAccessGroups(Operation *call, iterator_range< Region::iterator > inlinedBlocks)
Appends any access groups of the call operation to any inlined memory operation.
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...
static void handleAliasScopes(Operation *call, iterator_range< Region::iterator > inlinedBlocks)
Handles all interactions with alias scopes during inlining.
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 ...
static bool haveCommonPrefix(ArrayRef< int64_t > mibStack, ArrayRef< int64_t > callsiteStack)
Whether the two call stacks agree up to the shorter length, matching LLVM's haveCommonPrefix: a MemPr...
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 ...
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 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...
static void handleInlinedLocations(Operation *call, iterator_range< Region::iterator > inlinedBlocks)
static void handleInlinedAllocas(Operation *call, iterator_range< Region::iterator > inlinedBlocks)
Handles alloca operations in the inlined blocks:
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.
This is an attribute/type replacer that is naively cached.
void addWalk(WalkFn< Attribute > &&fn)
Register a walk function for a given attribute or type.
WalkResult walk(T element)
Walk the given attribute/type, and recursively walk any sub elements.
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
auto getOps()
Return an iterator range over the operations within this block that are of 'OpT'.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
IntegerAttr getI64IntegerAttr(int64_t value)
Ty getType(Args &&...args)
Get or construct an instance of the type Ty with provided arguments.
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
The main mechanism for performing data layout queries.
static DataLayout closest(Operation *op)
Returns the layout of the closest parent operation carrying layout info.
llvm::TypeSize getTypeSize(Type t) const
Returns the size of the given type in the current scope.
uint64_t getStackAlignment() const
Returns the natural alignment of the stack in bits.
uint64_t getTypeABIAlignment(Type t) const
Returns the required alignment of the given type in the current scope.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext * getContext() const
static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)
This class represents a fused location whose metadata is known to be an instance of the given type.
This is a utility class for mapping one set of IR entities to another.
Location objects represent source locations information in MLIR.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttribute represents a combination of a name and an Attribute value.
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Block * getInsertionBlock() const
Return the block the current insertion point belongs to.
A trait of region holding operations that define a new scope for automatic allocations,...
This class provides the API for ops that are known to be isolated from above.
Operation is the basic unit of execution within MLIR.
void setLoc(Location loc)
Set the source location the operation was defined or derived from.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
bool mightHaveTrait()
Returns true if the operation might have the provided trait.
void setDiscardableAttr(StringAttr name, Attribute value)
Set a discardable attribute by name.
Operation * getParentWithTrait()
Returns the closest surrounding parent operation with trait Trait.
Location getLoc()
The source location the operation was defined or derived from.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Attribute removeDiscardableAttr(StringAttr name)
Remove the discardable attribute with the specified name if it exists.
AttrClass getDiscardableAttrOfType(StringRef name)
Access a discardable attribute by name and cast it to AttrClass.
user_range getUsers()
Returns a range of all users.
Region * getParentRegion()
Returns the region to which the instruction belongs.
MLIRContext * getContext()
Return the context this operation is associated with.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Block * getParentBlock()
Return the Block in which this Value is defined.
Location getLoc() const
Return the location of this value.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
A class to signal how to proceed with the walk of the backward slice:
bool wasInterrupted() const
Returns true if the walk was interrupted.
static WalkContinuation skip()
Creates a continuation that advances the walk without adding any predecessor values to the work list.
static WalkContinuation advanceTo(mlir::ValueRange nextValues)
Creates a continuation that adds the user-specified nextValues to the work list and advances the walk...
static WalkContinuation interrupt()
Creates a continuation that interrupts the walk.
static WalkResult advance()
void recursivelyReplaceElementsIn(Operation *op, bool replaceAttrs=true, bool replaceLocs=false, bool replaceTypes=false)
Replace the elements within the given operation, and all nested operations.
void addReplacement(ReplaceFn< Attribute > fn)
AttrTypeReplacerBase.
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int64_t > content)
ArrayRef< T > asArrayRef() const
void registerInlinerInterface(DialectRegistry ®istry)
Register the LLVMInlinerInterface implementation of DialectInlinerInterface with the LLVM dialect.
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
std::optional< SmallVector< Value > > getControlFlowPredecessors(Value value)
Computes a vector of all control predecessors of value.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
llvm::SetVector< T, Vector, Set, N > SetVector
WalkContinuation walkSlice(mlir::ValueRange rootValues, WalkCallback walkCallback)
Walks the slice starting from the rootValues using a depth-first traversal.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.
This trait indicates that a terminator operation is "return-like".