[Alignment][NFC] Support compile time constants
[llvm-core.git] / include / llvm / Remarks / Remark.h
blob1243311fb8c5f04308c19bbbfaef095a0e134db0
1 //===-- llvm/Remarks/Remark.h - The remark type -----------------*- 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 // This file defines an abstraction for handling remarks.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_REMARKS_REMARK_H
14 #define LLVM_REMARKS_REMARK_H
16 #include "llvm-c/Remarks.h"
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/CBindingWrapping.h"
21 #include <string>
23 namespace llvm {
24 namespace remarks {
26 /// The current version of the remark entry.
27 constexpr uint64_t CurrentRemarkVersion = 0;
29 /// The debug location used to track a remark back to the source file.
30 struct RemarkLocation {
31 /// Absolute path of the source file corresponding to this remark.
32 StringRef SourceFilePath;
33 unsigned SourceLine;
34 unsigned SourceColumn;
37 // Create wrappers for C Binding types (see CBindingWrapping.h).
38 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkLocation, LLVMRemarkDebugLocRef)
40 /// A key-value pair with a debug location that is used to display the remarks
41 /// at the right place in the source.
42 struct Argument {
43 StringRef Key;
44 // FIXME: We might want to be able to store other types than strings here.
45 StringRef Val;
46 // If set, the debug location corresponding to the value.
47 Optional<RemarkLocation> Loc;
50 // Create wrappers for C Binding types (see CBindingWrapping.h).
51 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Argument, LLVMRemarkArgRef)
53 /// The type of the remark.
54 enum class Type {
55 Unknown,
56 Passed,
57 Missed,
58 Analysis,
59 AnalysisFPCommute,
60 AnalysisAliasing,
61 Failure,
62 First = Unknown,
63 Last = Failure
66 /// A remark type used for both emission and parsing.
67 struct Remark {
68 /// The type of the remark.
69 Type RemarkType = Type::Unknown;
71 /// Name of the pass that triggers the emission of this remark.
72 StringRef PassName;
74 /// Textual identifier for the remark (single-word, camel-case). Can be used
75 /// by external tools reading the output file for remarks to identify the
76 /// remark.
77 StringRef RemarkName;
79 /// Mangled name of the function that triggers the emssion of this remark.
80 StringRef FunctionName;
82 /// The location in the source file of the remark.
83 Optional<RemarkLocation> Loc;
85 /// If profile information is available, this is the number of times the
86 /// corresponding code was executed in a profile instrumentation run.
87 Optional<uint64_t> Hotness;
89 /// Arguments collected via the streaming interface.
90 SmallVector<Argument, 5> Args;
92 Remark() = default;
93 Remark(Remark &&) = default;
94 Remark &operator=(Remark &&) = default;
96 /// Return a message composed from the arguments as a string.
97 std::string getArgsAsMsg() const;
99 /// Clone this remark to explicitly ask for a copy.
100 Remark clone() const { return *this; }
102 private:
103 /// In order to avoid unwanted copies, "delete" the copy constructor.
104 /// If a copy is needed, it should be done through `Remark::clone()`.
105 Remark(const Remark &) = default;
106 Remark& operator=(const Remark &) = default;
109 // Create wrappers for C Binding types (see CBindingWrapping.h).
110 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef)
112 /// Comparison operators for Remark objects and dependent objects.
113 inline bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS) {
114 return LHS.SourceFilePath == RHS.SourceFilePath &&
115 LHS.SourceLine == RHS.SourceLine &&
116 LHS.SourceColumn == RHS.SourceColumn;
119 inline bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS) {
120 return !(LHS == RHS);
123 inline bool operator==(const Argument &LHS, const Argument &RHS) {
124 return LHS.Key == RHS.Key && LHS.Val == RHS.Val && LHS.Loc == RHS.Loc;
127 inline bool operator!=(const Argument &LHS, const Argument &RHS) {
128 return !(LHS == RHS);
131 inline bool operator==(const Remark &LHS, const Remark &RHS) {
132 return LHS.RemarkType == RHS.RemarkType && LHS.PassName == RHS.PassName &&
133 LHS.RemarkName == RHS.RemarkName &&
134 LHS.FunctionName == RHS.FunctionName && LHS.Loc == RHS.Loc &&
135 LHS.Hotness == RHS.Hotness && LHS.Args == RHS.Args;
138 inline bool operator!=(const Remark &LHS, const Remark &RHS) {
139 return !(LHS == RHS);
142 } // end namespace remarks
143 } // end namespace llvm
145 #endif /* LLVM_REMARKS_REMARK_H */