//===- FoldUtils.cpp ---- Fold Utilities ----------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines various operation fold utilities. These utilities are // intended to be used by passes to unify and simply their logic. // //===----------------------------------------------------------------------===// #include "mlir/Transforms/FoldUtils.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/Operation.h" usingnamespacemlir; /// Given an operation, find the parent region that folded constants should be /// inserted into. static Region * getInsertionRegion(DialectInterfaceCollection<DialectFoldInterface> &interfaces, Block *insertionBlock) { … } /// A utility function used to materialize a constant for a given attribute and /// type. On success, a valid constant value is returned. Otherwise, null is /// returned static Operation *materializeConstant(Dialect *dialect, OpBuilder &builder, Attribute value, Type type, Location loc) { … } //===----------------------------------------------------------------------===// // OperationFolder //===----------------------------------------------------------------------===// LogicalResult OperationFolder::tryToFold(Operation *op, bool *inPlaceUpdate) { … } bool OperationFolder::insertKnownConstant(Operation *op, Attribute constValue) { … } /// Notifies that the given constant `op` should be remove from this /// OperationFolder's internal bookkeeping. void OperationFolder::notifyRemoval(Operation *op) { … } /// Clear out any constants cached inside of the folder. void OperationFolder::clear() { … } /// Get or create a constant using the given builder. On success this returns /// the constant operation, nullptr otherwise. Value OperationFolder::getOrCreateConstant(Block *block, Dialect *dialect, Attribute value, Type type) { … } bool OperationFolder::isFolderOwnedConstant(Operation *op) const { … } /// Tries to perform folding on the given `op`. If successful, populates /// `results` with the results of the folding. LogicalResult OperationFolder::tryToFold(Operation *op, SmallVectorImpl<Value> &results) { … } LogicalResult OperationFolder::processFoldResults(Operation *op, SmallVectorImpl<Value> &results, ArrayRef<OpFoldResult> foldResults) { … } /// Try to get or create a new constant entry. On success this returns the /// constant operation value, nullptr otherwise. Operation * OperationFolder::tryGetOrCreateConstant(ConstantMap &uniquedConstants, Dialect *dialect, Attribute value, Type type, Location loc) { … }