Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame^] | 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. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_REMARKS_REMARK_H |
| 14 | #define LLVM_REMARKS_REMARK_H |
| 15 | |
| 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> |
| 22 | |
| 23 | namespace llvm { |
| 24 | namespace remarks { |
| 25 | |
| 26 | constexpr uint64_t Version = 0; |
| 27 | constexpr StringRef Magic("REMARKS", 7); |
| 28 | |
| 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; |
| 35 | }; |
| 36 | |
| 37 | // Create wrappers for C Binding types (see CBindingWrapping.h). |
| 38 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkLocation, LLVMRemarkDebugLocRef) |
| 39 | |
| 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; |
| 48 | }; |
| 49 | |
| 50 | // Create wrappers for C Binding types (see CBindingWrapping.h). |
| 51 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Argument, LLVMRemarkArgRef) |
| 52 | |
| 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 | LastTypeValue = Failure |
| 63 | }; |
| 64 | |
| 65 | /// A remark type used for both emission and parsing. |
| 66 | struct Remark { |
| 67 | /// The type of the remark. |
| 68 | Type RemarkType = Type::Unknown; |
| 69 | |
| 70 | /// Name of the pass that triggers the emission of this remark. |
| 71 | StringRef PassName; |
| 72 | |
| 73 | /// Textual identifier for the remark (single-word, camel-case). Can be used |
| 74 | /// by external tools reading the output file for remarks to identify the |
| 75 | /// remark. |
| 76 | StringRef RemarkName; |
| 77 | |
| 78 | /// Mangled name of the function that triggers the emssion of this remark. |
| 79 | StringRef FunctionName; |
| 80 | |
| 81 | /// The location in the source file of the remark. |
| 82 | Optional<RemarkLocation> Loc; |
| 83 | |
| 84 | /// If profile information is available, this is the number of times the |
| 85 | /// corresponding code was executed in a profile instrumentation run. |
| 86 | Optional<uint64_t> Hotness; |
| 87 | |
| 88 | /// Arguments collected via the streaming interface. |
| 89 | ArrayRef<Argument> Args; |
| 90 | |
| 91 | /// Return a message composed from the arguments as a string. |
| 92 | std::string getArgsAsMsg() const; |
| 93 | }; |
| 94 | |
| 95 | // Create wrappers for C Binding types (see CBindingWrapping.h). |
| 96 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef) |
| 97 | |
| 98 | } // end namespace remarks |
| 99 | } // end namespace llvm |
| 100 | |
| 101 | #endif /* LLVM_REMARKS_REMARK_H */ |