LLVM 17.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/ArrayRef.h"
16#include <optional>
17
18using namespace llvm;
19using namespace llvm::remarks;
20
21std::string Remark::getArgsAsMsg() const {
22 std::string Str;
23 raw_string_ostream OS(Str);
24 for (const Argument &Arg : Args)
25 OS << Arg.Val;
26 return OS.str();
27}
28
29// Create wrappers for C Binding types (see CBindingWrapping.h).
31
33 return unwrap(String)->data();
34}
35
37 return unwrap(String)->size();
38}
39
40extern "C" LLVMRemarkStringRef
42 return wrap(&unwrap(DL)->SourceFilePath);
43}
44
46 return unwrap(DL)->SourceLine;
47}
48
49extern "C" uint32_t
51 return unwrap(DL)->SourceColumn;
52}
53
55 return wrap(&unwrap(Arg)->Key);
56}
57
59 return wrap(&unwrap(Arg)->Val);
60}
61
62extern "C" LLVMRemarkDebugLocRef
64 if (const std::optional<RemarkLocation> &Loc = unwrap(Arg)->Loc)
65 return wrap(&*Loc);
66 return nullptr;
67}
68
70 delete unwrap(Remark);
71}
72
74 // Assume here that the enums can be converted both ways.
75 return static_cast<LLVMRemarkType>(unwrap(Remark)->RemarkType);
76}
77
78extern "C" LLVMRemarkStringRef
80 return wrap(&unwrap(Remark)->PassName);
81}
82
83extern "C" LLVMRemarkStringRef
85 return wrap(&unwrap(Remark)->RemarkName);
86}
87
88extern "C" LLVMRemarkStringRef
90 return wrap(&unwrap(Remark)->FunctionName);
91}
92
93extern "C" LLVMRemarkDebugLocRef
95 if (const std::optional<RemarkLocation> &Loc = unwrap(Remark)->Loc)
96 return wrap(&*Loc);
97 return nullptr;
98}
99
101 if (const std::optional<uint64_t> &Hotness = unwrap(Remark)->Hotness)
102 return *Hotness;
103 return 0;
104}
105
107 return unwrap(Remark)->Args.size();
108}
109
110extern "C" LLVMRemarkArgRef
112 ArrayRef<Argument> Args = unwrap(Remark)->Args;
113 // No arguments to iterate on.
114 if (Args.empty())
115 return nullptr;
116 return reinterpret_cast<LLVMRemarkArgRef>(
117 const_cast<Argument *>(Args.begin()));
118}
119
120extern "C" LLVMRemarkArgRef
122 // No more arguments to iterate on.
123 if (ArgIt == nullptr)
124 return nullptr;
125
126 auto It = (ArrayRef<Argument>::const_iterator)ArgIt;
127 auto Next = std::next(It);
128 if (Next == unwrap(Remark)->Args.end())
129 return nullptr;
130
131 return reinterpret_cast<LLVMRemarkArgRef>(const_cast<Argument *>(Next));
132}
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
static const char PassName[]
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:660
LLVMRemarkStringRef LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark)
Get the name of the pass that emitted this remark.
Definition: Remark.cpp:79
LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg)
Returns the key of an argument.
Definition: Remark.cpp:54
const char * LLVMRemarkStringGetData(LLVMRemarkStringRef String)
Returns the buffer holding the string.
Definition: Remark.cpp:32
uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String)
Returns the size of the string.
Definition: Remark.cpp:36
struct LLVMRemarkOpaqueEntry * LLVMRemarkEntryRef
A remark emitted by the compiler.
Definition: Remarks.h:140
LLVMRemarkType
The type of the emitted remark.
Definition: Remarks.h:41
struct LLVMRemarkOpaqueString * LLVMRemarkStringRef
String containing a buffer and a length.
Definition: Remarks.h:57
void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark)
Free the resources used by the remark entry.
Definition: Remark.cpp:69
struct LLVMRemarkOpaqueArg * LLVMRemarkArgRef
Element of the "Args" list.
Definition: Remarks.h:109
uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL)
Return the line in the source file for a debug location.
Definition: Remark.cpp:45
enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark)
The type of the remark.
Definition: Remark.cpp:73
LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark)
Get a new iterator to iterate over a remark's argument.
Definition: Remark.cpp:111
LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It, LLVMRemarkEntryRef Remark)
Get the next argument in Remark from the position of It.
Definition: Remark.cpp:121
LLVMRemarkStringRef LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL)
Return the path to the source file for a debug location.
Definition: Remark.cpp:41
LLVMRemarkDebugLocRef LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark)
Returns the debug location that is attached to this remark.
Definition: Remark.cpp:94
uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark)
The number of arguments the remark holds.
Definition: Remark.cpp:106
LLVMRemarkStringRef LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark)
Get an identifier of the remark.
Definition: Remark.cpp:84
LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg)
Returns the value of an argument.
Definition: Remark.cpp:58
uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL)
Return the column in the source file for a debug location.
Definition: Remark.cpp:50
struct LLVMRemarkOpaqueDebugLoc * LLVMRemarkDebugLocRef
DebugLoc containing File, Line and Column.
Definition: Remarks.h:78
LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg)
Returns the debug location that is attached to the value of this argument.
Definition: Remark.cpp:63
LLVMRemarkStringRef LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark)
Get the name of the function being processed when the remark was emitted.
Definition: Remark.cpp:89
uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark)
Return the hotness of the remark.
Definition: Remark.cpp:100
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:285
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:280
A key-value pair with a debug location that is used to display the remarks at the right place in the ...
Definition: Remark.h:42
A remark type used for both emission and parsing.
Definition: Remark.h:67
std::string getArgsAsMsg() const
Return a message composed from the arguments as a string.
Definition: Remark.cpp:21
SmallVector< Argument, 5 > Args
Arguments collected via the streaming interface.
Definition: Remark.h:90