#ifndef LLVM_REMARKS_REMARK_H
#define LLVM_REMARKS_REMARK_H
#include "llvm-c/Remarks.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CBindingWrapping.h"
#include <string>
namespace llvm {
namespace remarks {
constexpr uint64_t CurrentRemarkVersion = 0;
struct RemarkLocation {
StringRef SourceFilePath;
unsigned SourceLine = 0;
unsigned SourceColumn = 0;
};
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkLocation, LLVMRemarkDebugLocRef)
struct Argument {
StringRef Key;
StringRef Val;
Optional<RemarkLocation> Loc;
};
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Argument, LLVMRemarkArgRef)
enum class Type {
Unknown,
Passed,
Missed,
Analysis,
AnalysisFPCommute,
AnalysisAliasing,
Failure,
First = Unknown,
Last = Failure
};
struct Remark {
Type RemarkType = Type::Unknown;
StringRef PassName;
StringRef RemarkName;
StringRef FunctionName;
Optional<RemarkLocation> Loc;
Optional<uint64_t> Hotness;
SmallVector<Argument, 5> Args;
Remark() = default;
Remark(Remark &&) = default;
Remark &operator=(Remark &&) = default;
std::string getArgsAsMsg() const;
Remark clone() const { return *this; }
private:
Remark(const Remark &) = default;
Remark& operator=(const Remark &) = default;
};
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef)
template <typename T>
bool operator<(const Optional<T> &LHS, const Optional<T> &RHS) {
if (!LHS && !RHS)
return false;
if (!LHS && RHS)
return true;
if (LHS && !RHS)
return false;
return *LHS < *RHS;
}
inline bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS) {
return LHS.SourceFilePath == RHS.SourceFilePath &&
LHS.SourceLine == RHS.SourceLine &&
LHS.SourceColumn == RHS.SourceColumn;
}
inline bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS) {
return !(LHS == RHS);
}
inline bool operator<(const RemarkLocation &LHS, const RemarkLocation &RHS) {
return std::make_tuple(LHS.SourceFilePath, LHS.SourceLine, LHS.SourceColumn) <
std::make_tuple(RHS.SourceFilePath, RHS.SourceLine, RHS.SourceColumn);
}
inline bool operator==(const Argument &LHS, const Argument &RHS) {
return LHS.Key == RHS.Key && LHS.Val == RHS.Val && LHS.Loc == RHS.Loc;
}
inline bool operator!=(const Argument &LHS, const Argument &RHS) {
return !(LHS == RHS);
}
inline bool operator<(const Argument &LHS, const Argument &RHS) {
return std::make_tuple(LHS.Key, LHS.Val, LHS.Loc) <
std::make_tuple(RHS.Key, RHS.Val, RHS.Loc);
}
inline bool operator==(const Remark &LHS, const Remark &RHS) {
return LHS.RemarkType == RHS.RemarkType && LHS.PassName == RHS.PassName &&
LHS.RemarkName == RHS.RemarkName &&
LHS.FunctionName == RHS.FunctionName && LHS.Loc == RHS.Loc &&
LHS.Hotness == RHS.Hotness && LHS.Args == RHS.Args;
}
inline bool operator!=(const Remark &LHS, const Remark &RHS) {
return !(LHS == RHS);
}
inline bool operator<(const Remark &LHS, const Remark &RHS) {
return std::make_tuple(LHS.RemarkType, LHS.PassName, LHS.RemarkName,
LHS.FunctionName, LHS.Loc, LHS.Hotness, LHS.Args) <
std::make_tuple(RHS.RemarkType, RHS.PassName, RHS.RemarkName,
RHS.FunctionName, RHS.Loc, RHS.Hotness, RHS.Args);
}
} }
#endif