1 //===- Remark.cpp ---------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implementation of the Remark type and the C API.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Remarks/Remark.h"
14 #include "llvm-c/Remarks.h"
15 #include "llvm/Support/CBindingWrapping.h"
16 #include "llvm/Support/raw_ostream.h"
19 using namespace llvm::remarks
;
21 std::string
Remark::getArgsAsMsg() const {
23 raw_string_ostream
OS(Str
);
24 for (const Argument
&Arg
: Args
)
29 // Create wrappers for C Binding types (see CBindingWrapping.h).
30 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(StringRef
, LLVMRemarkStringRef
)
32 extern "C" const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String
) {
33 return unwrap(String
)->data();
36 extern "C" uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String
) {
37 return unwrap(String
)->size();
40 extern "C" LLVMRemarkStringRef
41 LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL
) {
42 return wrap(&unwrap(DL
)->SourceFilePath
);
45 extern "C" uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL
) {
46 return unwrap(DL
)->SourceLine
;
50 LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL
) {
51 return unwrap(DL
)->SourceColumn
;
54 extern "C" LLVMRemarkStringRef
LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg
) {
55 return wrap(&unwrap(Arg
)->Key
);
58 extern "C" LLVMRemarkStringRef
LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg
) {
59 return wrap(&unwrap(Arg
)->Val
);
62 extern "C" LLVMRemarkDebugLocRef
63 LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg
) {
64 if (const Optional
<RemarkLocation
> &Loc
= unwrap(Arg
)->Loc
)
69 extern "C" LLVMRemarkType
LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark
) {
70 // Assume here that the enums can be converted both ways.
71 return static_cast<LLVMRemarkType
>(unwrap(Remark
)->RemarkType
);
74 extern "C" LLVMRemarkStringRef
75 LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark
) {
76 return wrap(&unwrap(Remark
)->PassName
);
79 extern "C" LLVMRemarkStringRef
80 LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark
) {
81 return wrap(&unwrap(Remark
)->RemarkName
);
84 extern "C" LLVMRemarkStringRef
85 LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark
) {
86 return wrap(&unwrap(Remark
)->FunctionName
);
89 extern "C" LLVMRemarkDebugLocRef
90 LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark
) {
91 if (const Optional
<RemarkLocation
> &Loc
= unwrap(Remark
)->Loc
)
96 extern "C" uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark
) {
97 if (const Optional
<uint64_t> &Hotness
= unwrap(Remark
)->Hotness
)
102 extern "C" uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark
) {
103 return unwrap(Remark
)->Args
.size();
106 extern "C" LLVMRemarkArgRef
107 LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark
) {
108 ArrayRef
<Argument
> Args
= unwrap(Remark
)->Args
;
109 // No arguments to iterate on.
112 return reinterpret_cast<LLVMRemarkArgRef
>(
113 const_cast<Argument
*>(Args
.begin()));
116 extern "C" LLVMRemarkArgRef
117 LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef ArgIt
, LLVMRemarkEntryRef Remark
) {
118 // No more arguments to iterate on.
122 auto It
= (ArrayRef
<Argument
>::const_iterator
)ArgIt
;
123 auto Next
= std::next(It
);
124 if (Next
== unwrap(Remark
)->Args
.end())
127 return reinterpret_cast<LLVMRemarkArgRef
>(const_cast<Argument
*>(Next
));