Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/Transforms/Bufferize.h
Show All 22 Lines | |||||
// those cases, BufferizeConversionPattern and its related classes should be | // those cases, BufferizeConversionPattern and its related classes should be | ||||
// used, which provide access to a BufferizeTypeConverter directly. | // used, which provide access to a BufferizeTypeConverter directly. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef MLIR_TRANSFORMS_BUFFERIZE_H | #ifndef MLIR_TRANSFORMS_BUFFERIZE_H | ||||
#define MLIR_TRANSFORMS_BUFFERIZE_H | #define MLIR_TRANSFORMS_BUFFERIZE_H | ||||
#include "mlir/Analysis/BufferAliasAnalysis.h" | |||||
#include "mlir/Analysis/Liveness.h" | #include "mlir/Analysis/Liveness.h" | ||||
#include "mlir/Dialect/StandardOps/IR/Ops.h" | #include "mlir/Dialect/StandardOps/IR/Ops.h" | ||||
#include "mlir/IR/Builders.h" | #include "mlir/IR/Builders.h" | ||||
#include "mlir/IR/Dominance.h" | #include "mlir/IR/Dominance.h" | ||||
#include "mlir/IR/Function.h" | #include "mlir/IR/Function.h" | ||||
#include "mlir/IR/Operation.h" | #include "mlir/IR/Operation.h" | ||||
#include "mlir/Transforms/DialectConversion.h" | #include "mlir/Transforms/DialectConversion.h" | ||||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | patterns.insert< | ||||
BufferizeCallOpConverter, | BufferizeCallOpConverter, | ||||
BufferizeFuncOpConverter, | BufferizeFuncOpConverter, | ||||
BufferizeReturnOpConverter | BufferizeReturnOpConverter | ||||
<ReturnOpSourceTy, ReturnOpTargetTy, CopyOpTy> | <ReturnOpSourceTy, ReturnOpTargetTy, CopyOpTy> | ||||
>(context, converter); | >(context, converter); | ||||
// clang-format on | // clang-format on | ||||
} | } | ||||
/// A straight-forward alias analysis which ensures that all aliases of all | |||||
/// values will be determined. This is a requirement for the BufferPlacement | |||||
/// class since you need to determine safe positions to place alloc and | |||||
/// deallocs. | |||||
class BufferPlacementAliasAnalysis { | |||||
public: | |||||
using ValueSetT = SmallPtrSet<Value, 16>; | |||||
using ValueMapT = llvm::DenseMap<Value, ValueSetT>; | |||||
public: | |||||
/// Constructs a new alias analysis using the op provided. | |||||
BufferPlacementAliasAnalysis(Operation *op); | |||||
/// Find all immediate aliases this value could potentially have. | |||||
ValueMapT::const_iterator find(Value value) const { | |||||
return aliases.find(value); | |||||
} | |||||
/// Returns the begin iterator to iterate over all aliases. | |||||
ValueMapT::const_iterator begin() const { return aliases.begin(); } | |||||
/// Returns the end iterator that can be used in combination with find. | |||||
ValueMapT::const_iterator end() const { return aliases.end(); } | |||||
/// Find all immediate and indirect aliases this value could potentially | |||||
/// have. Note that the resulting set will also contain the value provided as | |||||
/// it is an alias of itself. | |||||
ValueSetT resolve(Value value) const; | |||||
/// Removes the given values from all alias sets. | |||||
void remove(const SmallPtrSetImpl<Value> &aliasValues); | |||||
private: | |||||
/// This function constructs a mapping from values to its immediate aliases. | |||||
void build(Operation *op); | |||||
/// Maps values to all immediate aliases this value can have. | |||||
ValueMapT aliases; | |||||
}; | |||||
/// A simple analysis that detects allocation operations. | /// A simple analysis that detects allocation operations. | ||||
class BufferPlacementAllocs { | class BufferPlacementAllocs { | ||||
public: | public: | ||||
/// Represents a tuple of allocValue and deallocOperation. | /// Represents a tuple of allocValue and deallocOperation. | ||||
using AllocEntry = std::tuple<Value, Operation *>; | using AllocEntry = std::tuple<Value, Operation *>; | ||||
/// Represents a list containing all alloc entries. | /// Represents a list containing all alloc entries. | ||||
using AllocEntryList = SmallVector<AllocEntry, 8>; | using AllocEntryList = SmallVector<AllocEntry, 8>; | ||||
Show All 34 Lines | |||||
private: | private: | ||||
/// Maps allocation nodes to their associated blocks. | /// Maps allocation nodes to their associated blocks. | ||||
AllocEntryList allocs; | AllocEntryList allocs; | ||||
}; | }; | ||||
/// The base class for all BufferPlacement transformations. | /// The base class for all BufferPlacement transformations. | ||||
class BufferPlacementTransformationBase { | class BufferPlacementTransformationBase { | ||||
public: | public: | ||||
using ValueSetT = BufferPlacementAliasAnalysis::ValueSetT; | using ValueSetT = BufferAliasAnalysis::ValueSetT; | ||||
/// Finds a common dominator for the given value while taking the positions | /// Finds a common dominator for the given value while taking the positions | ||||
/// of the values in the value set into account. It supports dominator and | /// of the values in the value set into account. It supports dominator and | ||||
/// post-dominator analyses via template arguments. | /// post-dominator analyses via template arguments. | ||||
template <typename DominatorT> | template <typename DominatorT> | ||||
static Block *findCommonDominator(Value value, const ValueSetT &values, | static Block *findCommonDominator(Value value, const ValueSetT &values, | ||||
const DominatorT &doms) { | const DominatorT &doms) { | ||||
// Start with the current block the value is defined in. | // Start with the current block the value is defined in. | ||||
Show All 18 Lines | public: | ||||
/// control-flow edges for cycles. | /// control-flow edges for cycles. | ||||
static bool isLoop(Operation *op); | static bool isLoop(Operation *op); | ||||
/// Constructs a new operation base using the given root operation. | /// Constructs a new operation base using the given root operation. | ||||
BufferPlacementTransformationBase(Operation *op); | BufferPlacementTransformationBase(Operation *op); | ||||
protected: | protected: | ||||
/// Alias information that can be updated during the insertion of copies. | /// Alias information that can be updated during the insertion of copies. | ||||
BufferPlacementAliasAnalysis aliases; | BufferAliasAnalysis aliases; | ||||
/// Stores all internally managed allocations. | /// Stores all internally managed allocations. | ||||
BufferPlacementAllocs allocs; | BufferPlacementAllocs allocs; | ||||
/// The underlying liveness analysis to compute fine grained information | /// The underlying liveness analysis to compute fine grained information | ||||
/// about alloc and dealloc positions. | /// about alloc and dealloc positions. | ||||
Liveness liveness; | Liveness liveness; | ||||
}; | }; | ||||
} // end namespace mlir | } // end namespace mlir | ||||
#endif // MLIR_TRANSFORMS_BUFFERIZE_H | #endif // MLIR_TRANSFORMS_BUFFERIZE_H |