MLIR  20.0.0git
Typedefs | Functions
OneShotModuleBufferize.cpp File Reference
#include "mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h"
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
#include "mlir/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.h"
#include "mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h"
#include "mlir/Dialect/Bufferization/Transforms/Transforms.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Operation.h"

Go to the source code of this file.

Typedefs

using FuncCallerMap = DenseMap< func::FuncOp, DenseSet< Operation * > >
 A mapping of FuncOps to their callers. More...
 

Functions

static FuncAnalysisStategetOrCreateFuncAnalysisState (OneShotAnalysisState &state)
 Get or create FuncAnalysisState. More...
 
static void removeBufferizationAttributes (BlockArgument bbArg)
 Remove bufferization attributes on FuncOp arguments. More...
 
static func::FuncOp getCalledFunction (func::CallOp callOp)
 Return the func::FuncOp called by callOp. More...
 
static void equivalenceAnalysis (func::FuncOp funcOp, OneShotAnalysisState &state, FuncAnalysisState &funcState)
 Gather equivalence info of CallOps. More...
 
static bool hasTensorSignature (func::FuncOp funcOp)
 Return "true" if the given function signature has tensor semantics. More...
 
static LogicalResult getFuncOpsOrderedByCalls (ModuleOp moduleOp, SmallVectorImpl< func::FuncOp > &orderedFuncOps, SmallVectorImpl< func::FuncOp > &remainingFuncOps, FuncCallerMap &callerMap)
 Store all functions of the moduleOp in orderedFuncOps, sorted by callee-caller order (i.e., callees without callers first). More...
 
static Value unpackCast (Value v)
 Helper function that extracts the source from a memref.cast. More...
 
static SmallVector< TypegetReturnTypes (SmallVector< func::ReturnOp > returnOps)
 Helper function that returns the return types (skipping casts) of the given func.return ops. More...
 
static void foldMemRefCasts (func::FuncOp funcOp)
 Fold return values that are memref casts and update function return types. More...
 

Typedef Documentation

◆ FuncCallerMap

using FuncCallerMap = DenseMap<func::FuncOp, DenseSet<Operation *> >

A mapping of FuncOps to their callers.

Definition at line 78 of file OneShotModuleBufferize.cpp.

Function Documentation

◆ equivalenceAnalysis()

static void equivalenceAnalysis ( func::FuncOp  funcOp,
OneShotAnalysisState state,
FuncAnalysisState funcState 
)
static

Gather equivalence info of CallOps.

Note: This only adds new equivalence info if the called function was already analyzed.

Definition at line 296 of file OneShotModuleBufferize.cpp.

◆ foldMemRefCasts()

static void foldMemRefCasts ( func::FuncOp  funcOp)
static

Fold return values that are memref casts and update function return types.

During FuncOp bufferization, the exact type of the returned memrefs (if any) is not known yet. Therefore, the bufferization uses memref types with the most generic layout map as function return types. After bufferizing the entire function body, a more concise memref type can potentially be used for the return type of the function.

Definition at line 431 of file OneShotModuleBufferize.cpp.

References mlir::get(), mlir::bufferization::getReturnOps(), getReturnTypes(), and unpackCast().

Referenced by mlir::bufferization::bufferizeModuleOp().

◆ getCalledFunction()

static func::FuncOp getCalledFunction ( func::CallOp  callOp)
static

Return the func::FuncOp called by callOp.

Definition at line 283 of file OneShotModuleBufferize.cpp.

References mlir::SymbolTable::lookupNearestSymbolFrom().

◆ getFuncOpsOrderedByCalls()

static LogicalResult getFuncOpsOrderedByCalls ( ModuleOp  moduleOp,
SmallVectorImpl< func::FuncOp > &  orderedFuncOps,
SmallVectorImpl< func::FuncOp > &  remainingFuncOps,
FuncCallerMap callerMap 
)
static

Store all functions of the moduleOp in orderedFuncOps, sorted by callee-caller order (i.e., callees without callers first).

Store all remaining functions (i.e., the ones that call each other recursively) in remainingFuncOps.

Store the map of FuncOp to all its callers in callerMap.

Return failure() if we are unable to retrieve the called FuncOp from any func::CallOp.

Definition at line 338 of file OneShotModuleBufferize.cpp.

References mlir::WalkResult::advance(), mlir::bufferization::func_ext::getCalledFunction(), hasTensorSignature(), mlir::WalkResult::skip(), and mlir::WalkResult::wasInterrupted().

Referenced by mlir::bufferization::bufferizeModuleOp().

◆ getOrCreateFuncAnalysisState()

static FuncAnalysisState& getOrCreateFuncAnalysisState ( OneShotAnalysisState state)
static

Get or create FuncAnalysisState.

Definition at line 82 of file OneShotModuleBufferize.cpp.

◆ getReturnTypes()

static SmallVector<Type> getReturnTypes ( SmallVector< func::ReturnOp >  returnOps)
static

Helper function that returns the return types (skipping casts) of the given func.return ops.

This function returns as many types as the return ops have operands. If the i-th operand is not the same for all func.return ops, then the i-th returned type is an "empty" type.

Definition at line 401 of file OneShotModuleBufferize.cpp.

References mlir::Value::getType(), and unpackCast().

Referenced by foldMemRefCasts().

◆ hasTensorSignature()

static bool hasTensorSignature ( func::FuncOp  funcOp)
static

Return "true" if the given function signature has tensor semantics.

Definition at line 322 of file OneShotModuleBufferize.cpp.

Referenced by getFuncOpsOrderedByCalls().

◆ removeBufferizationAttributes()

static void removeBufferizationAttributes ( BlockArgument  bbArg)
static

Remove bufferization attributes on FuncOp arguments.

Definition at line 274 of file OneShotModuleBufferize.cpp.

References mlir::BlockArgument::getArgNumber(), mlir::BlockArgument::getOwner(), and mlir::Block::getParentOp().

Referenced by mlir::bufferization::removeBufferizationAttributesInModule().

◆ unpackCast()

static Value unpackCast ( Value  v)
static

Helper function that extracts the source from a memref.cast.

If the given value is not a memref.cast result, simply returns the given value.

Definition at line 390 of file OneShotModuleBufferize.cpp.

References mlir::Value::getDefiningOp().

Referenced by foldMemRefCasts(), and getReturnTypes().