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/ADT/ArrayRef.h"
15 #include "llvm/Support/raw_ostream.h"
18 using namespace llvm::remarks
;
20 std::string
Remark::getArgsAsMsg() const {
22 raw_string_ostream
OS(Str
);
23 for (const Argument
&Arg
: Args
)
28 // Create wrappers for C Binding types (see CBindingWrapping.h).
29 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(StringRef
, LLVMRemarkStringRef
)
31 extern "C" const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String
) {
32 return unwrap(String
)->data();
35 extern "C" uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String
) {
36 return unwrap(String
)->size();
39 extern "C" LLVMRemarkStringRef
40 LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL
) {
41 return wrap(&unwrap(DL
)->SourceFilePath
);
44 extern "C" uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL
) {
45 return unwrap(DL
)->SourceLine
;
49 LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL
) {
50 return unwrap(DL
)->SourceColumn
;
53 extern "C" LLVMRemarkStringRef
LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg
) {
54 return wrap(&unwrap(Arg
)->Key
);
57 extern "C" LLVMRemarkStringRef
LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg
) {
58 return wrap(&unwrap(Arg
)->Val
);
61 extern "C" LLVMRemarkDebugLocRef
62 LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg
) {
63 if (const Optional
<RemarkLocation
> &Loc
= unwrap(Arg
)->Loc
)
68 extern "C" void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark
) {
69 delete unwrap(Remark
);
72 extern "C" LLVMRemarkType
LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark
) {
73 // Assume here that the enums can be converted both ways.
74 return static_cast<LLVMRemarkType
>(unwrap(Remark
)->RemarkType
);
77 extern "C" LLVMRemarkStringRef
78 LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark
) {
79 return wrap(&unwrap(Remark
)->PassName
);
82 extern "C" LLVMRemarkStringRef
83 LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark
) {
84 return wrap(&unwrap(Remark
)->RemarkName
);
87 extern "C" LLVMRemarkStringRef
88 LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark
) {
89 return wrap(&unwrap(Remark
)->FunctionName
);
92 extern "C" LLVMRemarkDebugLocRef
93 LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark
) {
94 if (const Optional
<RemarkLocation
> &Loc
= unwrap(Remark
)->Loc
)
99 extern "C" uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark
) {
100 if (const Optional
<uint64_t> &Hotness
= unwrap(Remark
)->Hotness
)
105 extern "C" uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark
) {
106 return unwrap(Remark
)->Args
.size();
109 extern "C" LLVMRemarkArgRef
110 LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark
) {
111 ArrayRef
<Argument
> Args
= unwrap(Remark
)->Args
;
112 // No arguments to iterate on.
115 return reinterpret_cast<LLVMRemarkArgRef
>(
116 const_cast<Argument
*>(Args
.begin()));
119 extern "C" LLVMRemarkArgRef
120 LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef ArgIt
, LLVMRemarkEntryRef Remark
) {
121 // No more arguments to iterate on.
125 auto It
= (ArrayRef
<Argument
>::const_iterator
)ArgIt
;
126 auto Next
= std::next(It
);
127 if (Next
== unwrap(Remark
)->Args
.end())
130 return reinterpret_cast<LLVMRemarkArgRef
>(const_cast<Argument
*>(Next
));