1 //===- ToolUtilities.h - MLIR Tool 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 declares common utilities for implementing MLIR tools. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef MLIR_SUPPORT_TOOLUTILITIES_H 14 #define MLIR_SUPPORT_TOOLUTILITIES_H 15 16 #include "mlir/Support/LLVM.h" 17 #include "llvm/ADT/STLExtras.h" 18 #include <memory> 19 20 namespace llvm { 21 class MemoryBuffer; 22 } // namespace llvm 23 24 namespace mlir { 25 struct LogicalResult; 26 27 using ChunkBufferHandler = function_ref<LogicalResult( 28 std::unique_ptr<llvm::MemoryBuffer> chunkBuffer, raw_ostream &os)>; 29 30 /// Splits the specified buffer on a marker (`// -----`), processes each chunk 31 /// independently according to the normal `processChunkBuffer` logic, and writes 32 /// all results to `os`. 33 /// 34 /// This is used to allow a large number of small independent tests to be put 35 /// into a single file. `enableSplitting` can be used to toggle if splitting 36 /// should be enabled, e.g. to allow for merging split and non-split code paths. 37 /// When `insertMarkerInOutput` is true, split markers (`//-----`) are placed 38 /// between each of the processed output chunks. 39 LogicalResult 40 splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> originalBuffer, 41 ChunkBufferHandler processChunkBuffer, raw_ostream &os, 42 bool enableSplitting = true, 43 bool insertMarkerInOutput = false); 44 } // namespace mlir 45 46 #endif // MLIR_SUPPORT_TOOLUTILITIES_H 47