MLIR  20.0.0git
ToolUtilities.h
Go to the documentation of this file.
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 "llvm/ADT/StringRef.h"
19 
20 #include <memory>
21 
22 namespace llvm {
23 class MemoryBuffer;
24 } // namespace llvm
25 
26 namespace mlir {
27 using ChunkBufferHandler = function_ref<LogicalResult(
28  std::unique_ptr<llvm::MemoryBuffer> chunkBuffer, raw_ostream &os)>;
29 
30 extern inline const char *const kDefaultSplitMarker = "// -----";
31 
32 /// Splits the specified buffer on a marker (`// -----` by default), processes
33 /// each chunk independently according to the normal `processChunkBuffer` logic,
34 /// and writes all results to `os`.
35 ///
36 /// This is used to allow a large number of small independent tests to be put
37 /// into a single file. The input split marker is configurable. If it is empty,
38 /// merging is disabled, which allows for merging split and non-split code
39 /// paths. Output split markers (`//-----` by default) followed by a new line
40 /// character, respectively, are placed between each of the processed output
41 /// chunks. (The new line character is inserted even if the split marker is
42 /// empty.)
43 LogicalResult
44 splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> originalBuffer,
45  ChunkBufferHandler processChunkBuffer, raw_ostream &os,
46  llvm::StringRef inputSplitMarker = kDefaultSplitMarker,
47  llvm::StringRef outputSplitMarker = "");
48 } // namespace mlir
49 
50 #endif // MLIR_SUPPORT_TOOLUTILITIES_H
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.
const char *const kDefaultSplitMarker
LogicalResult splitAndProcessBuffer(std::unique_ptr< llvm::MemoryBuffer > originalBuffer, ChunkBufferHandler processChunkBuffer, raw_ostream &os, llvm::StringRef inputSplitMarker=kDefaultSplitMarker, llvm::StringRef outputSplitMarker="")
Splits the specified buffer on a marker (// ----- by default), processes each chunk independently acc...