Skip to content

[llvm] annotate interfaces in XRay for DLL export #143765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/XRay/BlockIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_XRAY_BLOCKINDEXER_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Compiler.h"
#include "llvm/XRay/FDRRecords.h"
#include <cstdint>
#include <vector>
Expand All @@ -23,7 +24,7 @@ namespace xray {

// The BlockIndexer will gather all related records associated with a
// process+thread and group them by 'Block'.
class BlockIndexer : public RecordVisitor {
class LLVM_ABI BlockIndexer : public RecordVisitor {
public:
struct Block {
uint64_t ProcessID;
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/XRay/BlockPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#ifndef LLVM_XRAY_BLOCKPRINTER_H
#define LLVM_XRAY_BLOCKPRINTER_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/XRay/FDRRecords.h"
#include "llvm/XRay/RecordPrinter.h"

namespace llvm {
namespace xray {

class BlockPrinter : public RecordVisitor {
class LLVM_ABI BlockPrinter : public RecordVisitor {
enum class State {
Start,
Preamble,
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/XRay/BlockVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#ifndef LLVM_XRAY_BLOCKVERIFIER_H
#define LLVM_XRAY_BLOCKVERIFIER_H

#include "llvm/Support/Compiler.h"
#include "llvm/XRay/FDRRecords.h"

namespace llvm {
namespace xray {

class BlockVerifier : public RecordVisitor {
class LLVM_ABI BlockVerifier : public RecordVisitor {
public:
// We force State elements to be size_t, to be used as indices for containers.
enum class State : std::size_t {
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/XRay/FDRRecordConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef LLVM_XRAY_FDRRECORDCONSUMER_H
#define LLVM_XRAY_FDRRECORDCONSUMER_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/XRay/FDRRecords.h"
#include <algorithm>
Expand All @@ -25,7 +26,7 @@ class RecordConsumer {

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

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

public:
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/XRay/FDRRecordProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef LLVM_XRAY_FDRRECORDPRODUCER_H
#define LLVM_XRAY_FDRRECORDPRODUCER_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/XRay/FDRRecords.h"
#include "llvm/XRay/XRayRecord.h"
Expand All @@ -24,7 +25,7 @@ class RecordProducer {
virtual ~RecordProducer() = default;
};

class FileBasedRecordProducer : public RecordProducer {
class LLVM_ABI FileBasedRecordProducer : public RecordProducer {
const XRayFileHeader &Header;
DataExtractor &E;
uint64_t &OffsetPtr;
Expand Down
29 changes: 15 additions & 14 deletions llvm/include/llvm/XRay/FDRRecords.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_XRAY_FDRRECORDS_H
#define LLVM_XRAY_FDRRECORDS_H

#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <string>

Expand Down Expand Up @@ -47,7 +48,7 @@ class Record {
RK_Function,
};

static StringRef kindToString(RecordKind K);
LLVM_ABI static StringRef kindToString(RecordKind K);

private:
const RecordKind T;
Expand Down Expand Up @@ -107,7 +108,7 @@ class MetadataRecord : public Record {
// What follows are specific Metadata record types which encapsulate the
// information associated with specific metadata record types in an FDR mode
// log.
class BufferExtents : public MetadataRecord {
class LLVM_ABI BufferExtents : public MetadataRecord {
uint64_t Size = 0;
friend class RecordInitializer;

Expand All @@ -130,7 +131,7 @@ class BufferExtents : public MetadataRecord {
}
};

class WallclockRecord : public MetadataRecord {
class LLVM_ABI WallclockRecord : public MetadataRecord {
uint64_t Seconds = 0;
uint32_t Nanos = 0;
friend class RecordInitializer;
Expand All @@ -155,7 +156,7 @@ class WallclockRecord : public MetadataRecord {
}
};

class NewCPUIDRecord : public MetadataRecord {
class LLVM_ABI NewCPUIDRecord : public MetadataRecord {
uint16_t CPUId = 0;
uint64_t TSC = 0;
friend class RecordInitializer;
Expand All @@ -181,7 +182,7 @@ class NewCPUIDRecord : public MetadataRecord {
}
};

class TSCWrapRecord : public MetadataRecord {
class LLVM_ABI TSCWrapRecord : public MetadataRecord {
uint64_t BaseTSC = 0;
friend class RecordInitializer;

Expand All @@ -203,7 +204,7 @@ class TSCWrapRecord : public MetadataRecord {
}
};

class CustomEventRecord : public MetadataRecord {
class LLVM_ABI CustomEventRecord : public MetadataRecord {
int32_t Size = 0;
uint64_t TSC = 0;
uint16_t CPU = 0;
Expand Down Expand Up @@ -232,7 +233,7 @@ class CustomEventRecord : public MetadataRecord {
}
};

class CustomEventRecordV5 : public MetadataRecord {
class LLVM_ABI CustomEventRecordV5 : public MetadataRecord {
int32_t Size = 0;
int32_t Delta = 0;
std::string Data{};
Expand All @@ -259,7 +260,7 @@ class CustomEventRecordV5 : public MetadataRecord {
}
};

class TypedEventRecord : public MetadataRecord {
class LLVM_ABI TypedEventRecord : public MetadataRecord {
int32_t Size = 0;
int32_t Delta = 0;
uint16_t EventType = 0;
Expand Down Expand Up @@ -288,7 +289,7 @@ class TypedEventRecord : public MetadataRecord {
}
};

class CallArgRecord : public MetadataRecord {
class LLVM_ABI CallArgRecord : public MetadataRecord {
uint64_t Arg = 0;
friend class RecordInitializer;

Expand All @@ -310,7 +311,7 @@ class CallArgRecord : public MetadataRecord {
}
};

class PIDRecord : public MetadataRecord {
class LLVM_ABI PIDRecord : public MetadataRecord {
int32_t PID = 0;
friend class RecordInitializer;

Expand All @@ -333,7 +334,7 @@ class PIDRecord : public MetadataRecord {
}
};

class NewBufferRecord : public MetadataRecord {
class LLVM_ABI NewBufferRecord : public MetadataRecord {
int32_t TID = 0;
friend class RecordInitializer;

Expand All @@ -356,7 +357,7 @@ class NewBufferRecord : public MetadataRecord {
}
};

class EndBufferRecord : public MetadataRecord {
class LLVM_ABI EndBufferRecord : public MetadataRecord {
public:
EndBufferRecord()
: MetadataRecord(RecordKind::RK_Metadata_EndOfBuffer,
Expand All @@ -369,7 +370,7 @@ class EndBufferRecord : public MetadataRecord {
}
};

class FunctionRecord : public Record {
class LLVM_ABI FunctionRecord : public Record {
RecordTypes Kind;
int32_t FuncId = 0;
uint32_t Delta = 0;
Expand Down Expand Up @@ -415,7 +416,7 @@ class RecordVisitor {
virtual Error visit(TypedEventRecord &) = 0;
};

class RecordInitializer : public RecordVisitor {
class LLVM_ABI RecordInitializer : public RecordVisitor {
DataExtractor &E;
uint64_t &OffsetPtr;
uint16_t Version;
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/XRay/FDRTraceWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#ifndef LLVM_XRAY_FDRTRACEWRITER_H
#define LLVM_XRAY_FDRTRACEWRITER_H

#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/XRay/FDRRecords.h"
#include "llvm/XRay/XRayRecord.h"

Expand All @@ -26,7 +27,7 @@ namespace xray {
/// generate various kinds of execution traces without using the XRay runtime.
/// Note that this writer does not do any validation, but uses the types of
/// records defined in the FDRRecords.h file.
class FDRTraceWriter : public RecordVisitor {
class LLVM_ABI FDRTraceWriter : public RecordVisitor {
public:
// Construct an FDRTraceWriter associated with an output stream.
explicit FDRTraceWriter(raw_ostream &O, const XRayFileHeader &H);
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/XRay/FileHeaderReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_XRAY_FILEHEADERREADER_H
#define LLVM_XRAY_FILEHEADERREADER_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Error.h"
#include "llvm/XRay/XRayRecord.h"
Expand All @@ -23,8 +24,8 @@ namespace xray {

/// Convenience function for loading the file header given a data extractor at a
/// specified offset.
Expected<XRayFileHeader> readBinaryFormatHeader(DataExtractor &HeaderExtractor,
uint64_t &OffsetPtr);
LLVM_ABI Expected<XRayFileHeader>
readBinaryFormatHeader(DataExtractor &HeaderExtractor, uint64_t &OffsetPtr);

} // namespace xray
} // namespace llvm
Expand Down
11 changes: 7 additions & 4 deletions llvm/include/llvm/XRay/InstrumentationMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_XRAY_INSTRUMENTATIONMAP_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/YAMLTraits.h"
#include <cstdint>
Expand All @@ -31,7 +32,8 @@ class InstrumentationMap;

/// Loads the instrumentation map from |Filename|. This auto-deduces the type of
/// the instrumentation map.
Expected<InstrumentationMap> loadInstrumentationMap(StringRef Filename);
LLVM_ABI Expected<InstrumentationMap>
loadInstrumentationMap(StringRef Filename);

/// Represents an XRay instrumentation sled entry from an object file.
struct SledEntry {
Expand Down Expand Up @@ -83,17 +85,18 @@ class InstrumentationMap {
FunctionAddressMap FunctionAddresses;
FunctionAddressReverseMap FunctionIds;

friend Expected<InstrumentationMap> loadInstrumentationMap(StringRef);
LLVM_ABI_FRIEND friend Expected<InstrumentationMap>
loadInstrumentationMap(StringRef);

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

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

/// Returns the function address for a function id.
std::optional<uint64_t> getFunctionAddr(int32_t FuncId) const;
LLVM_ABI std::optional<uint64_t> getFunctionAddr(int32_t FuncId) const;

/// Provide read-only access to the entries of the instrumentation map.
const SledContainer &sleds() const { return Sleds; };
Expand Down
19 changes: 10 additions & 9 deletions llvm/include/llvm/XRay/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include <list>
#include <utility>
Expand All @@ -34,18 +35,18 @@ class Trace;
///
/// For any errors encountered in the loading of the profile data from
/// |Filename|, this function will return an Error condition appropriately.
Expected<Profile> loadProfile(StringRef Filename);
LLVM_ABI Expected<Profile> loadProfile(StringRef Filename);

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

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

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

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

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

/// Appends a fully-formed Block instance into the Profile.
///
/// Returns an error condition in the following cases:
///
/// - The PathData component of the Block is empty
///
Error addBlock(Block &&B);
LLVM_ABI Error addBlock(Block &&B);

Profile() = default;
~Profile() = default;
Expand All @@ -99,8 +100,8 @@ class Profile {
return *this;
}

Profile(const Profile &);
Profile &operator=(const Profile &);
LLVM_ABI Profile(const Profile &);
LLVM_ABI Profile &operator=(const Profile &);

friend void swap(Profile &L, Profile &R) {
using std::swap;
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/XRay/RecordPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
#ifndef LLVM_XRAY_RECORDPRINTER_H
#define LLVM_XRAY_RECORDPRINTER_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/XRay/FDRRecords.h"

namespace llvm {
namespace xray {

class RecordPrinter : public RecordVisitor {
class LLVM_ABI RecordPrinter : public RecordVisitor {
raw_ostream &OS;
std::string Delim;

Expand Down
Loading
Loading