[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Remarks / Remark.cpp
blob057d1a378599fedeb98fef8b6945fcde4dd70bb6
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Remarks/Remark.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/Support/raw_ostream.h"
17 using namespace llvm;
18 using namespace llvm::remarks;
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();
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;
48 extern "C" uint32_t
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)
64 return wrap(&*Loc);
65 return nullptr;
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)
95 return wrap(&*Loc);
96 return nullptr;
99 extern "C" uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark) {
100 if (const Optional<uint64_t> &Hotness = unwrap(Remark)->Hotness)
101 return *Hotness;
102 return 0;
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.
113 if (Args.empty())
114 return NULL;
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.
122 if (ArgIt == NULL)
123 return NULL;
125 auto It = (ArrayRef<Argument>::const_iterator)ArgIt;
126 auto Next = std::next(It);
127 if (Next == unwrap(Remark)->Args.end())
128 return NULL;
130 return reinterpret_cast<LLVMRemarkArgRef>(const_cast<Argument *>(Next));