diff --git a/llvm/include/llvm/Remarks/Remark.h b/llvm/include/llvm/Remarks/Remark.h --- a/llvm/include/llvm/Remarks/Remark.h +++ b/llvm/include/llvm/Remarks/Remark.h @@ -17,6 +17,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/CBindingWrapping.h" +#include "llvm/Support/raw_ostream.h" #include #include @@ -32,6 +33,9 @@ StringRef SourceFilePath; unsigned SourceLine = 0; unsigned SourceColumn = 0; + + /// Implement operator<< on RemarkLocation. + void print(raw_ostream &OS) const; }; // Create wrappers for C Binding types (see CBindingWrapping.h). @@ -45,6 +49,9 @@ StringRef Val; // If set, the debug location corresponding to the value. std::optional Loc; + + /// Implement operator<< on Argument. + void print(raw_ostream &OS) const; }; // Create wrappers for C Binding types (see CBindingWrapping.h). @@ -63,6 +70,25 @@ Last = Failure }; +inline StringRef typeToStr(Type Ty) { + switch (Ty) { + case Type::Unknown: + return "Unknown"; + case Type::Missed: + return "Missed"; + case Type::Passed: + return "Passed"; + case Type::Analysis: + return "Analysis"; + case Type::AnalysisFPCommute: + return "AnalysisFPCommute"; + case Type::AnalysisAliasing: + return "AnalysisAliasing"; + default: + return "Failure"; + } +} + /// A remark type used for both emission and parsing. struct Remark { /// The type of the remark. @@ -99,6 +125,9 @@ /// Clone this remark to explicitly ask for a copy. Remark clone() const { return *this; } + /// Implement operator<< on Remark. + void print(raw_ostream &OS) const; + private: /// In order to avoid unwanted copies, "delete" the copy constructor. /// If a copy is needed, it should be done through `Remark::clone()`. @@ -171,6 +200,21 @@ RHS.FunctionName, RHS.Loc, RHS.Hotness, RHS.Args); } +inline raw_ostream &operator<<(raw_ostream &OS, const RemarkLocation &RLoc) { + RLoc.print(OS); + return OS; +} + +inline raw_ostream &operator<<(raw_ostream &OS, const Argument &Arg) { + Arg.print(OS); + return OS; +} + +inline raw_ostream &operator<<(raw_ostream &OS, const Remark &Remark) { + Remark.print(OS); + return OS; +} + } // end namespace remarks } // end namespace llvm diff --git a/llvm/lib/Remarks/Remark.cpp b/llvm/lib/Remarks/Remark.cpp --- a/llvm/lib/Remarks/Remark.cpp +++ b/llvm/lib/Remarks/Remark.cpp @@ -12,7 +12,6 @@ #include "llvm/Remarks/Remark.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/Support/raw_ostream.h" #include using namespace llvm; @@ -26,6 +25,33 @@ return OS.str(); } +void RemarkLocation::print(raw_ostream &OS) const { + OS << "{ " + << "File: " << SourceFilePath << ", Line: " << SourceLine + << " Column:" << SourceColumn << " }\n"; +} + +void Argument::print(raw_ostream &OS) const { + OS << Key << ": " << Val << "\n"; +} + +void Remark::print(raw_ostream &OS) const { + OS << "Name: "; + OS << RemarkName << "\n"; + OS << "Type: " << typeToStr(RemarkType) << "\n"; + OS << "FunctionName: " << FunctionName << "\n"; + OS << "PassName: " << PassName << "\n"; + if (Loc) + OS << "Loc: " << Loc.value(); + if (Hotness) + OS << "Hotness: " << Hotness; + if (!Args.empty()) { + OS << "Args:\n"; + for (auto Arg : Args) + OS << "\t" << Arg; + } +} + // Create wrappers for C Binding types (see CBindingWrapping.h). DEFINE_SIMPLE_CONVERSION_FUNCTIONS(StringRef, LLVMRemarkStringRef)