MLIR 22.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
22namespace llvm {
23class MemoryBuffer;
24class MemoryBufferRef;
25} // namespace llvm
26
27namespace mlir {
28// A function that processes a chunk of a buffer and writes the result to an
29// output stream.
30using ChunkBufferHandler = function_ref<LogicalResult(
31 std::unique_ptr<llvm::MemoryBuffer> chunkBuffer,
32 const llvm::MemoryBufferRef &sourceBuffer, raw_ostream &os)>;
34 std::unique_ptr<llvm::MemoryBuffer> chunkBuffer, raw_ostream &os)>;
35
36extern inline const char *const kDefaultSplitMarker = "// -----";
37
38/// Splits the specified buffer on a marker (`// -----` by default), processes
39/// each chunk independently according to the normal `processChunkBuffer` logic,
40/// and writes all results to `os`.
41///
42/// This is used to allow a large number of small independent tests to be put
43/// into a single file. The input split marker is configurable. If it is empty,
44/// merging is disabled, which allows for merging split and non-split code
45/// paths. Output split markers (`//-----` by default) followed by a new line
46/// character, respectively, are placed between each of the processed output
47/// chunks. (The new line character is inserted even if the split marker is
48/// empty.)
49LogicalResult
50splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> originalBuffer,
51 ChunkBufferHandler processChunkBuffer, raw_ostream &os,
52 llvm::StringRef inputSplitMarker = kDefaultSplitMarker,
53 llvm::StringRef outputSplitMarker = "");
54
55/// Same as above, but for case where the original buffer is not used while
56/// processing the chunk.
57LogicalResult
58splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> originalBuffer,
59 NoSourceChunkBufferHandler processChunkBuffer,
60 raw_ostream &os,
61 llvm::StringRef inputSplitMarker = kDefaultSplitMarker,
62 llvm::StringRef outputSplitMarker = "");
63} // namespace mlir
64
65#endif // MLIR_SUPPORT_TOOLUTILITIES_H
The OpAsmOpInterface, see OpAsmInterface.td for more details.
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...
function_ref< LogicalResult( std::unique_ptr< llvm::MemoryBuffer > chunkBuffer, raw_ostream &os)> NoSourceChunkBufferHandler
function_ref< LogicalResult( std::unique_ptr< llvm::MemoryBuffer > chunkBuffer, const llvm::MemoryBufferRef &sourceBuffer, raw_ostream &os)> ChunkBufferHandler
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152