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_DEBUGSTRINGHELPER_H_ 16 #define MLIR_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. debugString(T & op)27template <typename T> static std::string debugString(T &op) { 28 std::string instr_str; 29 llvm::raw_string_ostream os(instr_str); 30 op.print(os); 31 return os.str(); 32 } 33 34 } // namespace mlir 35 36 inline std::ostream &operator<<(std::ostream &out, const llvm::Twine &twine) { 37 llvm::raw_os_ostream rout(out); 38 rout << twine; 39 return out; 40 } 41 42 #endif // MLIR_DEBUGSTRINGHELPER_H_ 43