LLVM 22.0.0git
Remark.cpp
Go to the documentation of this file.
1//===- Remark.cpp ---------------------------------------------------------===//
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// Implementation of the Remark type and the C API.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Remarks/Remark.h"
14#include "llvm/ADT/APInt.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/STLExtras.h"
17#include <optional>
18
19using namespace llvm;
20using namespace llvm::remarks;
21
22std::string Remark::getArgsAsMsg() const {
23 std::string Str;
24 raw_string_ostream OS(Str);
25 for (const Argument &Arg : Args)
26 OS << Arg.Val;
27 return Str;
28}
29
31 auto *It = find_if(Args, [&](auto &Arg) { return Arg.Key == Key; });
32 if (It == Args.end())
33 return nullptr;
34 return &*It;
35}
36
38 OS << "{ "
39 << "File: " << SourceFilePath << ", Line: " << SourceLine
40 << " Column:" << SourceColumn << " }\n";
41}
42
44 OS << Key << ": " << Val << "\n";
45}
46
47void Remark::print(raw_ostream &OS) const {
48 OS << "Name: ";
49 OS << RemarkName << "\n";
50 OS << "Type: " << typeToStr(RemarkType) << "\n";
51 OS << "FunctionName: " << FunctionName << "\n";
52 OS << "PassName: " << PassName << "\n";
53 if (Loc)
54 OS << "Loc: " << Loc.value();
55 if (Hotness)
56 OS << "Hotness: " << Hotness;
57 if (!Args.empty()) {
58 OS << "Args:\n";
59 for (auto Arg : Args)
60 OS << "\t" << Arg;
61 }
62}
63
64// Create wrappers for C Binding types (see CBindingWrapping.h).
66
68 return unwrap(String)->data();
69}
70
74
75extern "C" LLVMRemarkStringRef
79
83
84extern "C" uint32_t
88
90 return wrap(&unwrap(Arg)->Key);
91}
92
94 return wrap(&unwrap(Arg)->Val);
95}
96
97extern "C" LLVMRemarkDebugLocRef
99 if (const std::optional<RemarkLocation> &Loc = unwrap(Arg)->Loc)
100 return wrap(&*Loc);
101 return nullptr;
102}
103
105 delete unwrap(Remark);
106}
107
109 // Assume here that the enums can be converted both ways.
110 return static_cast<LLVMRemarkType>(unwrap(Remark)->RemarkType);
111}
112
113extern "C" LLVMRemarkStringRef
117
118extern "C" LLVMRemarkStringRef
122
123extern "C" LLVMRemarkStringRef
127
128extern "C" LLVMRemarkDebugLocRef
130 if (const std::optional<RemarkLocation> &Loc = unwrap(Remark)->Loc)
131 return wrap(&*Loc);
132 return nullptr;
133}
134
136 if (const std::optional<uint64_t> &Hotness = unwrap(Remark)->Hotness)
137 return *Hotness;
138 return 0;
139}
140
142 return unwrap(Remark)->Args.size();
143}
144
145extern "C" LLVMRemarkArgRef
147 ArrayRef<Argument> Args = unwrap(Remark)->Args;
148 // No arguments to iterate on.
149 if (Args.empty())
150 return nullptr;
151 return reinterpret_cast<LLVMRemarkArgRef>(
152 const_cast<Argument *>(Args.begin()));
153}
154
155extern "C" LLVMRemarkArgRef
157 // No more arguments to iterate on.
158 if (ArgIt == nullptr)
159 return nullptr;
160
161 auto It = (ArrayRef<Argument>::const_iterator)ArgIt;
162 auto Next = std::next(It);
163 if (Next == unwrap(Remark)->Args.end())
164 return nullptr;
165
166 return reinterpret_cast<LLVMRemarkArgRef>(const_cast<Argument *>(Next));
167}
aarch64 promote const
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
This file contains some templates that are useful if you are working with the STL at all.
static const char PassName[]
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
const_pointer const_iterator
Definition ArrayRef.h:49
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
LLVM_C_ABI LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It, LLVMRemarkEntryRef Remark)
Get the next argument in Remark from the position of It.
Definition Remark.cpp:156
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg)
Returns the value of an argument.
Definition Remark.cpp:93
struct LLVMRemarkOpaqueEntry * LLVMRemarkEntryRef
A remark emitted by the compiler.
Definition Remarks.h:146
LLVM_C_ABI uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String)
Returns the size of the string.
Definition Remark.cpp:71
LLVMRemarkType
The type of the emitted remark.
Definition Remarks.h:42
struct LLVMRemarkOpaqueString * LLVMRemarkStringRef
String containing a buffer and a length.
Definition Remarks.h:58
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark)
Get the name of the function being processed when the remark was emitted.
Definition Remark.cpp:124
LLVM_C_ABI const char * LLVMRemarkStringGetData(LLVMRemarkStringRef String)
Returns the buffer holding the string.
Definition Remark.cpp:67
LLVM_C_ABI LLVMRemarkDebugLocRef LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark)
Returns the debug location that is attached to this remark.
Definition Remark.cpp:129
LLVM_C_ABI LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg)
Returns the debug location that is attached to the value of this argument.
Definition Remark.cpp:98
LLVM_C_ABI uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL)
Return the column in the source file for a debug location.
Definition Remark.cpp:85
struct LLVMRemarkOpaqueArg * LLVMRemarkArgRef
Element of the "Args" list.
Definition Remarks.h:113
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark)
Get the name of the pass that emitted this remark.
Definition Remark.cpp:114
LLVM_C_ABI uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark)
The number of arguments the remark holds.
Definition Remark.cpp:141
LLVM_C_ABI void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark)
Free the resources used by the remark entry.
Definition Remark.cpp:104
LLVM_C_ABI enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark)
The type of the remark.
Definition Remark.cpp:108
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg)
Returns the key of an argument.
Definition Remark.cpp:89
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark)
Get an identifier of the remark.
Definition Remark.cpp:119
LLVM_C_ABI uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark)
Return the hotness of the remark.
Definition Remark.cpp:135
struct LLVMRemarkOpaqueDebugLoc * LLVMRemarkDebugLocRef
DebugLoc containing File, Line and Column.
Definition Remarks.h:80
LLVM_C_ABI LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark)
Get a new iterator to iterate over a remark's argument.
Definition Remark.cpp:146
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL)
Return the path to the source file for a debug location.
Definition Remark.cpp:76
LLVM_C_ABI uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL)
Return the line in the source file for a debug location.
Definition Remark.cpp:80
StringRef typeToStr(Type Ty)
Definition Remark.h:87
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:351
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1758
LLVMAttributeRef wrap(Attribute Attr)
Definition Attributes.h:346
A key-value pair with a debug location that is used to display the remarks at the right place in the ...
Definition Remark.h:47
LLVM_ABI void print(raw_ostream &OS) const
Implement operator<< on Argument.
Definition Remark.cpp:43
LLVM_ABI void print(raw_ostream &OS) const
Implement operator<< on RemarkLocation.
Definition Remark.cpp:37
StringRef SourceFilePath
Absolute path of the source file corresponding to this remark.
Definition Remark.h:34
A remark type used for both emission and parsing.
Definition Remark.h:107
LLVM_ABI void print(raw_ostream &OS) const
Implement operator<< on Remark.
Definition Remark.cpp:47
Type RemarkType
The type of the remark.
Definition Remark.h:109
StringRef PassName
Name of the pass that triggers the emission of this remark.
Definition Remark.h:112
std::optional< RemarkLocation > Loc
The location in the source file of the remark.
Definition Remark.h:123
std::optional< uint64_t > Hotness
If profile information is available, this is the number of times the corresponding code was executed ...
Definition Remark.h:127
StringRef RemarkName
Textual identifier for the remark (single-word, camel-case).
Definition Remark.h:117
LLVM_ABI std::string getArgsAsMsg() const
Return a message composed from the arguments as a string.
Definition Remark.cpp:22
StringRef FunctionName
Mangled name of the function that triggers the emssion of this remark.
Definition Remark.h:120
LLVM_ABI Argument * getArgByKey(StringRef Key)
Return the first argument with the specified key or nullptr if no such argument was found.
Definition Remark.cpp:30
SmallVector< Argument, 5 > Args
Arguments collected via the streaming interface.
Definition Remark.h:130