Skip to content

Commit febb7e8

Browse files
authored
[llvm] annotate interfaces in XRay for DLL export (#143765)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/XRay` library. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. Additionally, I manually added `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI`. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent ffc4d87 commit febb7e8

12 files changed

+56
-41
lines changed

llvm/include/llvm/XRay/BlockIndexer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_XRAY_BLOCKINDEXER_H
1515

1616
#include "llvm/ADT/DenseMap.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/XRay/FDRRecords.h"
1819
#include <cstdint>
1920
#include <vector>
@@ -23,7 +24,7 @@ namespace xray {
2324

2425
// The BlockIndexer will gather all related records associated with a
2526
// process+thread and group them by 'Block'.
26-
class BlockIndexer : public RecordVisitor {
27+
class LLVM_ABI BlockIndexer : public RecordVisitor {
2728
public:
2829
struct Block {
2930
uint64_t ProcessID;

llvm/include/llvm/XRay/BlockPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#ifndef LLVM_XRAY_BLOCKPRINTER_H
1414
#define LLVM_XRAY_BLOCKPRINTER_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/Support/raw_ostream.h"
1718
#include "llvm/XRay/FDRRecords.h"
1819
#include "llvm/XRay/RecordPrinter.h"
1920

2021
namespace llvm {
2122
namespace xray {
2223

23-
class BlockPrinter : public RecordVisitor {
24+
class LLVM_ABI BlockPrinter : public RecordVisitor {
2425
enum class State {
2526
Start,
2627
Preamble,

llvm/include/llvm/XRay/BlockVerifier.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
#ifndef LLVM_XRAY_BLOCKVERIFIER_H
1414
#define LLVM_XRAY_BLOCKVERIFIER_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/XRay/FDRRecords.h"
1718

1819
namespace llvm {
1920
namespace xray {
2021

21-
class BlockVerifier : public RecordVisitor {
22+
class LLVM_ABI BlockVerifier : public RecordVisitor {
2223
public:
2324
// We force State elements to be size_t, to be used as indices for containers.
2425
enum class State : std::size_t {

llvm/include/llvm/XRay/FDRRecordConsumer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef LLVM_XRAY_FDRRECORDCONSUMER_H
99
#define LLVM_XRAY_FDRRECORDCONSUMER_H
1010

11+
#include "llvm/Support/Compiler.h"
1112
#include "llvm/Support/Error.h"
1213
#include "llvm/XRay/FDRRecords.h"
1314
#include <algorithm>
@@ -25,7 +26,7 @@ class RecordConsumer {
2526

2627
// This consumer will collect all the records into a vector of records, in
2728
// arrival order.
28-
class LogBuilderConsumer : public RecordConsumer {
29+
class LLVM_ABI LogBuilderConsumer : public RecordConsumer {
2930
std::vector<std::unique_ptr<Record>> &Records;
3031

3132
public:
@@ -38,7 +39,7 @@ class LogBuilderConsumer : public RecordConsumer {
3839
// A PipelineConsumer applies a set of visitors to every consumed Record, in the
3940
// order by which the visitors are added to the pipeline in the order of
4041
// appearance.
41-
class PipelineConsumer : public RecordConsumer {
42+
class LLVM_ABI PipelineConsumer : public RecordConsumer {
4243
std::vector<RecordVisitor *> Visitors;
4344

4445
public:

llvm/include/llvm/XRay/FDRRecordProducer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef LLVM_XRAY_FDRRECORDPRODUCER_H
99
#define LLVM_XRAY_FDRRECORDPRODUCER_H
1010

11+
#include "llvm/Support/Compiler.h"
1112
#include "llvm/Support/Error.h"
1213
#include "llvm/XRay/FDRRecords.h"
1314
#include "llvm/XRay/XRayRecord.h"
@@ -24,7 +25,7 @@ class RecordProducer {
2425
virtual ~RecordProducer() = default;
2526
};
2627

27-
class FileBasedRecordProducer : public RecordProducer {
28+
class LLVM_ABI FileBasedRecordProducer : public RecordProducer {
2829
const XRayFileHeader &Header;
2930
DataExtractor &E;
3031
uint64_t &OffsetPtr;

llvm/include/llvm/XRay/FDRRecords.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_XRAY_FDRRECORDS_H
1414
#define LLVM_XRAY_FDRRECORDS_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include <cstdint>
1718
#include <string>
1819

@@ -47,7 +48,7 @@ class Record {
4748
RK_Function,
4849
};
4950

50-
static StringRef kindToString(RecordKind K);
51+
LLVM_ABI static StringRef kindToString(RecordKind K);
5152

5253
private:
5354
const RecordKind T;
@@ -107,7 +108,7 @@ class MetadataRecord : public Record {
107108
// What follows are specific Metadata record types which encapsulate the
108109
// information associated with specific metadata record types in an FDR mode
109110
// log.
110-
class BufferExtents : public MetadataRecord {
111+
class LLVM_ABI BufferExtents : public MetadataRecord {
111112
uint64_t Size = 0;
112113
friend class RecordInitializer;
113114

@@ -130,7 +131,7 @@ class BufferExtents : public MetadataRecord {
130131
}
131132
};
132133

133-
class WallclockRecord : public MetadataRecord {
134+
class LLVM_ABI WallclockRecord : public MetadataRecord {
134135
uint64_t Seconds = 0;
135136
uint32_t Nanos = 0;
136137
friend class RecordInitializer;
@@ -155,7 +156,7 @@ class WallclockRecord : public MetadataRecord {
155156
}
156157
};
157158

158-
class NewCPUIDRecord : public MetadataRecord {
159+
class LLVM_ABI NewCPUIDRecord : public MetadataRecord {
159160
uint16_t CPUId = 0;
160161
uint64_t TSC = 0;
161162
friend class RecordInitializer;
@@ -181,7 +182,7 @@ class NewCPUIDRecord : public MetadataRecord {
181182
}
182183
};
183184

184-
class TSCWrapRecord : public MetadataRecord {
185+
class LLVM_ABI TSCWrapRecord : public MetadataRecord {
185186
uint64_t BaseTSC = 0;
186187
friend class RecordInitializer;
187188

@@ -203,7 +204,7 @@ class TSCWrapRecord : public MetadataRecord {
203204
}
204205
};
205206

206-
class CustomEventRecord : public MetadataRecord {
207+
class LLVM_ABI CustomEventRecord : public MetadataRecord {
207208
int32_t Size = 0;
208209
uint64_t TSC = 0;
209210
uint16_t CPU = 0;
@@ -232,7 +233,7 @@ class CustomEventRecord : public MetadataRecord {
232233
}
233234
};
234235

235-
class CustomEventRecordV5 : public MetadataRecord {
236+
class LLVM_ABI CustomEventRecordV5 : public MetadataRecord {
236237
int32_t Size = 0;
237238
int32_t Delta = 0;
238239
std::string Data{};
@@ -259,7 +260,7 @@ class CustomEventRecordV5 : public MetadataRecord {
259260
}
260261
};
261262

262-
class TypedEventRecord : public MetadataRecord {
263+
class LLVM_ABI TypedEventRecord : public MetadataRecord {
263264
int32_t Size = 0;
264265
int32_t Delta = 0;
265266
uint16_t EventType = 0;
@@ -288,7 +289,7 @@ class TypedEventRecord : public MetadataRecord {
288289
}
289290
};
290291

291-
class CallArgRecord : public MetadataRecord {
292+
class LLVM_ABI CallArgRecord : public MetadataRecord {
292293
uint64_t Arg = 0;
293294
friend class RecordInitializer;
294295

@@ -310,7 +311,7 @@ class CallArgRecord : public MetadataRecord {
310311
}
311312
};
312313

313-
class PIDRecord : public MetadataRecord {
314+
class LLVM_ABI PIDRecord : public MetadataRecord {
314315
int32_t PID = 0;
315316
friend class RecordInitializer;
316317

@@ -333,7 +334,7 @@ class PIDRecord : public MetadataRecord {
333334
}
334335
};
335336

336-
class NewBufferRecord : public MetadataRecord {
337+
class LLVM_ABI NewBufferRecord : public MetadataRecord {
337338
int32_t TID = 0;
338339
friend class RecordInitializer;
339340

@@ -356,7 +357,7 @@ class NewBufferRecord : public MetadataRecord {
356357
}
357358
};
358359

359-
class EndBufferRecord : public MetadataRecord {
360+
class LLVM_ABI EndBufferRecord : public MetadataRecord {
360361
public:
361362
EndBufferRecord()
362363
: MetadataRecord(RecordKind::RK_Metadata_EndOfBuffer,
@@ -369,7 +370,7 @@ class EndBufferRecord : public MetadataRecord {
369370
}
370371
};
371372

372-
class FunctionRecord : public Record {
373+
class LLVM_ABI FunctionRecord : public Record {
373374
RecordTypes Kind;
374375
int32_t FuncId = 0;
375376
uint32_t Delta = 0;
@@ -415,7 +416,7 @@ class RecordVisitor {
415416
virtual Error visit(TypedEventRecord &) = 0;
416417
};
417418

418-
class RecordInitializer : public RecordVisitor {
419+
class LLVM_ABI RecordInitializer : public RecordVisitor {
419420
DataExtractor &E;
420421
uint64_t &OffsetPtr;
421422
uint16_t Version;

llvm/include/llvm/XRay/FDRTraceWriter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#ifndef LLVM_XRAY_FDRTRACEWRITER_H
1313
#define LLVM_XRAY_FDRTRACEWRITER_H
1414

15-
#include "llvm/Support/raw_ostream.h"
15+
#include "llvm/Support/Compiler.h"
1616
#include "llvm/Support/EndianStream.h"
17+
#include "llvm/Support/raw_ostream.h"
1718
#include "llvm/XRay/FDRRecords.h"
1819
#include "llvm/XRay/XRayRecord.h"
1920

@@ -26,7 +27,7 @@ namespace xray {
2627
/// generate various kinds of execution traces without using the XRay runtime.
2728
/// Note that this writer does not do any validation, but uses the types of
2829
/// records defined in the FDRRecords.h file.
29-
class FDRTraceWriter : public RecordVisitor {
30+
class LLVM_ABI FDRTraceWriter : public RecordVisitor {
3031
public:
3132
// Construct an FDRTraceWriter associated with an output stream.
3233
explicit FDRTraceWriter(raw_ostream &O, const XRayFileHeader &H);

llvm/include/llvm/XRay/FileHeaderReader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_XRAY_FILEHEADERREADER_H
1414
#define LLVM_XRAY_FILEHEADERREADER_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/Support/DataExtractor.h"
1718
#include "llvm/Support/Error.h"
1819
#include "llvm/XRay/XRayRecord.h"
@@ -23,8 +24,8 @@ namespace xray {
2324

2425
/// Convenience function for loading the file header given a data extractor at a
2526
/// specified offset.
26-
Expected<XRayFileHeader> readBinaryFormatHeader(DataExtractor &HeaderExtractor,
27-
uint64_t &OffsetPtr);
27+
LLVM_ABI Expected<XRayFileHeader>
28+
readBinaryFormatHeader(DataExtractor &HeaderExtractor, uint64_t &OffsetPtr);
2829

2930
} // namespace xray
3031
} // namespace llvm

llvm/include/llvm/XRay/InstrumentationMap.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_XRAY_INSTRUMENTATIONMAP_H
1616

1717
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Support/Compiler.h"
1819
#include "llvm/Support/Error.h"
1920
#include "llvm/Support/YAMLTraits.h"
2021
#include <cstdint>
@@ -31,7 +32,8 @@ class InstrumentationMap;
3132

3233
/// Loads the instrumentation map from |Filename|. This auto-deduces the type of
3334
/// the instrumentation map.
34-
Expected<InstrumentationMap> loadInstrumentationMap(StringRef Filename);
35+
LLVM_ABI Expected<InstrumentationMap>
36+
loadInstrumentationMap(StringRef Filename);
3537

3638
/// Represents an XRay instrumentation sled entry from an object file.
3739
struct SledEntry {
@@ -83,17 +85,18 @@ class InstrumentationMap {
8385
FunctionAddressMap FunctionAddresses;
8486
FunctionAddressReverseMap FunctionIds;
8587

86-
friend Expected<InstrumentationMap> loadInstrumentationMap(StringRef);
88+
LLVM_ABI_FRIEND friend Expected<InstrumentationMap>
89+
loadInstrumentationMap(StringRef);
8790

8891
public:
8992
/// Provides a raw accessor to the unordered map of function addresses.
9093
const FunctionAddressMap &getFunctionAddresses() { return FunctionAddresses; }
9194

9295
/// Returns an XRay computed function id, provided a function address.
93-
std::optional<int32_t> getFunctionId(uint64_t Addr) const;
96+
LLVM_ABI std::optional<int32_t> getFunctionId(uint64_t Addr) const;
9497

9598
/// Returns the function address for a function id.
96-
std::optional<uint64_t> getFunctionAddr(int32_t FuncId) const;
99+
LLVM_ABI std::optional<uint64_t> getFunctionAddr(int32_t FuncId) const;
97100

98101
/// Provide read-only access to the entries of the instrumentation map.
99102
const SledContainer &sleds() const { return Sleds; };

llvm/include/llvm/XRay/Profile.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/DenseMap.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringRef.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Support/Error.h"
2021
#include <list>
2122
#include <utility>
@@ -34,18 +35,18 @@ class Trace;
3435
///
3536
/// For any errors encountered in the loading of the profile data from
3637
/// |Filename|, this function will return an Error condition appropriately.
37-
Expected<Profile> loadProfile(StringRef Filename);
38+
LLVM_ABI Expected<Profile> loadProfile(StringRef Filename);
3839

3940
/// This algorithm will merge two Profile instances into a single Profile
4041
/// instance, aggregating blocks by Thread ID.
41-
Profile mergeProfilesByThread(const Profile &L, const Profile &R);
42+
LLVM_ABI Profile mergeProfilesByThread(const Profile &L, const Profile &R);
4243

4344
/// This algorithm will merge two Profile instances into a single Profile
4445
/// instance, aggregating blocks by function call stack.
45-
Profile mergeProfilesByStack(const Profile &L, const Profile &R);
46+
LLVM_ABI Profile mergeProfilesByStack(const Profile &L, const Profile &R);
4647

4748
/// This function takes a Trace and creates a Profile instance from it.
48-
Expected<Profile> profileFromTrace(const Trace &T);
49+
LLVM_ABI Expected<Profile> profileFromTrace(const Trace &T);
4950

5051
/// Profile instances are thread-compatible.
5152
class Profile {
@@ -68,19 +69,19 @@ class Profile {
6869
///
6970
/// Returns an error if |P| had not been interned before into the Profile.
7071
///
71-
Expected<std::vector<FuncID>> expandPath(PathID P) const;
72+
LLVM_ABI Expected<std::vector<FuncID>> expandPath(PathID P) const;
7273

7374
/// The stack represented in |P| must be in stack order (leaf to root). This
7475
/// will always return the same PathID for |P| that has the same sequence.
75-
PathID internPath(ArrayRef<FuncID> P);
76+
LLVM_ABI PathID internPath(ArrayRef<FuncID> P);
7677

7778
/// Appends a fully-formed Block instance into the Profile.
7879
///
7980
/// Returns an error condition in the following cases:
8081
///
8182
/// - The PathData component of the Block is empty
8283
///
83-
Error addBlock(Block &&B);
84+
LLVM_ABI Error addBlock(Block &&B);
8485

8586
Profile() = default;
8687
~Profile() = default;
@@ -99,8 +100,8 @@ class Profile {
99100
return *this;
100101
}
101102

102-
Profile(const Profile &);
103-
Profile &operator=(const Profile &);
103+
LLVM_ABI Profile(const Profile &);
104+
LLVM_ABI Profile &operator=(const Profile &);
104105

105106
friend void swap(Profile &L, Profile &R) {
106107
using std::swap;

llvm/include/llvm/XRay/RecordPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
#ifndef LLVM_XRAY_RECORDPRINTER_H
1414
#define LLVM_XRAY_RECORDPRINTER_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/Support/raw_ostream.h"
1718
#include "llvm/XRay/FDRRecords.h"
1819

1920
namespace llvm {
2021
namespace xray {
2122

22-
class RecordPrinter : public RecordVisitor {
23+
class LLVM_ABI RecordPrinter : public RecordVisitor {
2324
raw_ostream &OS;
2425
std::string Delim;
2526

0 commit comments

Comments
 (0)