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