1 //===- ReductionTreeUtils.h - Reduction Tree utilities ----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the Reduction Tree Utilities. It defines pass independent 10 // methods that help in the reduction passes of the MLIR Reduce tool. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_REDUCER_REDUCTIONTREEUTILS_H 15 #define MLIR_REDUCER_REDUCTIONTREEUTILS_H 16 17 #include <tuple> 18 19 #include "PassDetail.h" 20 #include "ReductionNode.h" 21 #include "mlir/Reducer/Tester.h" 22 #include "llvm/Support/Debug.h" 23 24 namespace mlir { 25 26 // Defines the utilities for the implementation of custom reduction 27 // passes using the ReductionTreePass framework. 28 namespace ReductionTreeUtils { 29 30 /// Update the golden module's content with that of the reduced module. 31 void updateGoldenModule(ModuleOp &golden, ModuleOp reduced); 32 33 /// Update the smallest node traversed so far in the reduction tree and 34 /// print the debugging information for the currNode being traversed. 35 void updateSmallestNode(ReductionNode *currNode, ReductionNode *&smallestNode, 36 std::vector<int> path); 37 38 /// Create a transform space index vector based on the specified number of 39 /// indices. 40 std::vector<bool> createTransformSpace(ModuleOp module, int numIndices); 41 42 /// Create the specified number of variants by applying the transform method 43 /// to different ranges of indices in the parent module. The isDeletion boolean 44 /// specifies if the transformation is the deletion of indices. 45 void createVariants(ReductionNode *parent, const Tester &test, int numVariants, 46 llvm::function_ref<void(ModuleOp, int, int)> transform, 47 bool isDeletion); 48 49 } // namespace ReductionTreeUtils 50 51 } // end namespace mlir 52 53 #endif 54