[llvm] 3161db8 - [Remark] Overload `<<` for Remark, RemarkType and RemarkLocation.
Zain Jaffal via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 06:49:19 PDT 2023
Author: Zain Jaffal
Date: 2023-07-24T14:49:01+01:00
New Revision: 3161db8ca07eaf76106cb73128f8c4e08571bde1
URL: https://github.com/llvm/llvm-project/commit/3161db8ca07eaf76106cb73128f8c4e08571bde1
DIFF: https://github.com/llvm/llvm-project/commit/3161db8ca07eaf76106cb73128f8c4e08571bde1.diff
LOG: [Remark] Overload `<<` for Remark, RemarkType and RemarkLocation.
Represent different remark concepts as strings by overloading the `<<`
operator.
Reviewed By: thegameg
Differential Revision: https://reviews.llvm.org/D155058
Added:
Modified:
llvm/include/llvm/Remarks/Remark.h
llvm/lib/Remarks/Remark.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Remarks/Remark.h b/llvm/include/llvm/Remarks/Remark.h
index 2ac881be619651..a66f7ed73f2f50 100644
--- 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 <optional>
#include <string>
@@ -32,6 +33,9 @@ struct RemarkLocation {
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 @@ struct Argument {
StringRef Val;
// If set, the debug location corresponding to the value.
std::optional<RemarkLocation> Loc;
+
+ /// Implement operator<< on Argument.
+ void print(raw_ostream &OS) const;
};
// Create wrappers for C Binding types (see CBindingWrapping.h).
@@ -63,6 +70,25 @@ enum class Type {
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 @@ struct Remark {
/// 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 @@ inline bool operator<(const Remark &LHS, const Remark &RHS) {
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
index a038f81874d1f4..1b248db41747ed 100644
--- 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 <optional>
using namespace llvm;
@@ -26,6 +25,33 @@ std::string Remark::getArgsAsMsg() const {
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)
More information about the llvm-commits
mailing list