LLVM  10.0.0svn
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 //===----------------------------------------------------------------------===//
13 #include "llvm/Remarks/Remark.h"
14 #include "llvm-c/Remarks.h"
18 using namespace llvm;
19 using namespace llvm::remarks;
21 std::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 }
29 // Create wrappers for C Binding types (see CBindingWrapping.h).
33  return unwrap(String)->data();
34 }
37  return unwrap(String)->size();
38 }
40 extern "C" LLVMRemarkStringRef
42  return wrap(&unwrap(DL)->SourceFilePath);
43 }
46  return unwrap(DL)->SourceLine;
47 }
49 extern "C" uint32_t
51  return unwrap(DL)->SourceColumn;
52 }
55  return wrap(&unwrap(Arg)->Key);
56 }
59  return wrap(&unwrap(Arg)->Val);
60 }
62 extern "C" LLVMRemarkDebugLocRef
64  if (const Optional<RemarkLocation> &Loc = unwrap(Arg)->Loc)
65  return wrap(&*Loc);
66  return nullptr;
67 }
70  delete unwrap(Remark);
71 }
74  // Assume here that the enums can be converted both ways.
75  return static_cast<LLVMRemarkType>(unwrap(Remark)->RemarkType);
76 }
78 extern "C" LLVMRemarkStringRef
80  return wrap(&unwrap(Remark)->PassName);
81 }
83 extern "C" LLVMRemarkStringRef
85  return wrap(&unwrap(Remark)->RemarkName);
86 }
88 extern "C" LLVMRemarkStringRef
90  return wrap(&unwrap(Remark)->FunctionName);
91 }
93 extern "C" LLVMRemarkDebugLocRef
95  if (const Optional<RemarkLocation> &Loc = unwrap(Remark)->Loc)
96  return wrap(&*Loc);
97  return nullptr;
98 }
101  if (const Optional<uint64_t> &Hotness = unwrap(Remark)->Hotness)
102  return *Hotness;
103  return 0;
104 }
107  return unwrap(Remark)->Args.size();
108 }
110 extern "C" LLVMRemarkArgRef
112  ArrayRef<Argument> Args = unwrap(Remark)->Args;
113  // No arguments to iterate on.
114  if (Args.empty())
115  return NULL;
116  return reinterpret_cast<LLVMRemarkArgRef>(
117  const_cast<Argument *>(Args.begin()));
118 }
120 extern "C" LLVMRemarkArgRef
122  // No more arguments to iterate on.
123  if (ArgIt == NULL)
124  return NULL;
126  auto It = (ArrayRef<Argument>::const_iterator)ArgIt;
127  auto Next = std::next(It);
128  if (Next == unwrap(Remark)->Args.end())
129  return NULL;
131  return reinterpret_cast<LLVMRemarkArgRef>(const_cast<Argument *>(Next));
132 }
uint64_t CallInst * C
void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark)
Free the resources used by the remark entry.
Definition: Remark.cpp:69
LLVMRemarkStringRef LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark)
Get the name of the function being processed when the remark was emitted.
Definition: Remark.cpp:89
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringRef PassName
Name of the pass that triggers the emission of this remark.
Definition: Remark.h:72
iterator begin() const
Definition: ArrayRef.h:136
LLVMRemarkStringRef LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL)
Return the path to the source file for a debug location.
Definition: Remark.cpp:41
uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark)
The number of arguments the remark holds.
Definition: Remark.cpp:106
Optional< uint64_t > Hotness
If profile information is available, this is the number of times the corresponding code was executed ...
Definition: Remark.h:87
uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL)
Return the line in the source file for a debug location.
Definition: Remark.cpp:45
A remark type used for both emission and parsing.
Definition: Remark.h:67
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:204
StringRef RemarkName
Textual identifier for the remark (single-word, camel-case).
Definition: Remark.h:77
LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef ArgIt, LLVMRemarkEntryRef Remark)
Get the next argument in Remark from the position of It.
Definition: Remark.cpp:121
PAL metadata keys.
struct LLVMRemarkOpaqueArg * LLVMRemarkArgRef
Element of the "Args" list.
Definition: Remarks.h:107
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String)
Returns the size of the string.
Definition: Remark.cpp:36
Optional< RemarkLocation > Loc
The location in the source file of the remark.
Definition: Remark.h:83
The type of the emitted remark.
Definition: Remarks.h:39
LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg)
Returns the debug location that is attached to the value of this argument.
Definition: Remark.cpp:63
uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark)
Return the hotness of the remark.
Definition: Remark.cpp:100
LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark)
The type of the remark.
Definition: Remark.cpp:73
struct LLVMRemarkOpaqueDebugLoc * LLVMRemarkDebugLocRef
DebugLoc containing File, Line and Column.
Definition: Remarks.h:76
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark)
Get a new iterator to iterate over a remark&#39;s argument.
Definition: Remark.cpp:111
std::string getArgsAsMsg() const
Return a message composed from the arguments as a string.
Definition: Remark.cpp:21
LLVMRemarkStringRef LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark)
Get an identifier of the remark.
Definition: Remark.cpp:84
std::string & str()
Flushes the stream contents to the target string and returns the string&#39;s reference.
Definition: raw_ostream.h:519
struct LLVMRemarkOpaqueString * LLVMRemarkStringRef
String containing a buffer and a length.
Definition: Remarks.h:55
LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg)
Returns the key of an argument.
Definition: Remark.cpp:54
LLVMRemarkDebugLocRef LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark)
Returns the debug location that is attached to this remark.
Definition: Remark.cpp:94
const char * LLVMRemarkStringGetData(LLVMRemarkStringRef String)
Returns the buffer holding the string.
Definition: Remark.cpp:32
uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL)
Return the column in the source file for a debug location.
Definition: Remark.cpp:50
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
StringRef FunctionName
Mangled name of the function that triggers the emssion of this remark.
Definition: Remark.h:80
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:199
LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg)
Returns the value of an argument.
Definition: Remark.cpp:58
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:503
aarch64 promote const
SmallVector< Argument, 5 > Args
Arguments collected via the streaming interface.
Definition: Remark.h:90
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
struct LLVMRemarkOpaqueEntry * LLVMRemarkEntryRef
A remark emitted by the compiler.
Definition: Remarks.h:138
LLVMRemarkStringRef LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark)
Get the name of the pass that emitted this remark.
Definition: Remark.cpp:79
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143