MLIR  20.0.0git
DebugStringHelper.h
Go to the documentation of this file.
1 //===- DebugStringHelper.h - helpers to generate debug strings --*- 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 // Convenience functions to make it easier to get a string representation for
10 // ops that have a print method. For use in debugging output and errors
11 // returned.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef MLIR_SUPPORT_DEBUGSTRINGHELPER_H
16 #define MLIR_SUPPORT_DEBUGSTRINGHELPER_H
17 
18 #include <string>
19 
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/Support/raw_os_ostream.h"
22 #include "llvm/Support/raw_ostream.h"
23 
24 namespace mlir {
25 
26 // Simple helper function that returns a string as printed from a op.
27 template <typename T>
28 static std::string debugString(T &&op) {
29  std::string instrStr;
30  llvm::raw_string_ostream os(instrStr);
31  os << op;
32  return os.str();
33 }
34 
35 } // namespace mlir
36 
37 inline std::ostream &operator<<(std::ostream &out, const llvm::Twine &twine) {
38  llvm::raw_os_ostream rout(out);
39  rout << twine;
40  return out;
41 }
42 
43 #endif // MLIR_SUPPORT_DEBUGSTRINGHELPER_H
std::ostream & operator<<(std::ostream &out, const llvm::Twine &twine)
Include the generated interface declarations.
static std::string debugString(T &&op)