-
Notifications
You must be signed in to change notification settings - Fork 14k
[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
Conversation
@llvm/pr-subscribers-xray Author: Andrew Rogers (andrurogerz) ChangesPurposeThis patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the BackgroundThis effort is tracked in #109483. Additional context is provided in this discourse, and documentation for The bulk of these changes were generated automatically using the Interface Definition Scanner (IDS) tool, followed formatting with Additionally, I manually added ValidationLocal builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:
Full diff: https://github.com/llvm/llvm-project/pull/143765.diff 13 Files Affected:
diff --git a/llvm/include/llvm-c/Error.h b/llvm/include/llvm-c/Error.h
index 874bbcfe8f21a..99b38fb585f23 100644
--- a/llvm/include/llvm-c/Error.h
+++ b/llvm/include/llvm-c/Error.h
@@ -15,6 +15,7 @@
#define LLVM_C_ERROR_H
#include "llvm-c/ExternC.h"
+#include "llvm/Support/Compiler.h"
LLVM_C_EXTERN_C_BEGIN
diff --git a/llvm/include/llvm/XRay/BlockIndexer.h b/llvm/include/llvm/XRay/BlockIndexer.h
index 77af77e5ec269..e9782dafed618 100644
--- a/llvm/include/llvm/XRay/BlockIndexer.h
+++ b/llvm/include/llvm/XRay/BlockIndexer.h
@@ -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>
@@ -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;
diff --git a/llvm/include/llvm/XRay/BlockPrinter.h b/llvm/include/llvm/XRay/BlockPrinter.h
index 2f9fed668069c..caf78c5c4a5a6 100644
--- a/llvm/include/llvm/XRay/BlockPrinter.h
+++ b/llvm/include/llvm/XRay/BlockPrinter.h
@@ -13,6 +13,7 @@
#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"
@@ -20,7 +21,7 @@
namespace llvm {
namespace xray {
-class BlockPrinter : public RecordVisitor {
+class LLVM_ABI BlockPrinter : public RecordVisitor {
enum class State {
Start,
Preamble,
diff --git a/llvm/include/llvm/XRay/BlockVerifier.h b/llvm/include/llvm/XRay/BlockVerifier.h
index 2450ad89ffe3d..b88785c393e37 100644
--- a/llvm/include/llvm/XRay/BlockVerifier.h
+++ b/llvm/include/llvm/XRay/BlockVerifier.h
@@ -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 {
diff --git a/llvm/include/llvm/XRay/FDRRecordConsumer.h b/llvm/include/llvm/XRay/FDRRecordConsumer.h
index 8fff9fb861582..473777f0e04f2 100644
--- a/llvm/include/llvm/XRay/FDRRecordConsumer.h
+++ b/llvm/include/llvm/XRay/FDRRecordConsumer.h
@@ -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>
@@ -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:
@@ -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:
diff --git a/llvm/include/llvm/XRay/FDRRecordProducer.h b/llvm/include/llvm/XRay/FDRRecordProducer.h
index 25c123aec1b29..083b57139d397 100644
--- a/llvm/include/llvm/XRay/FDRRecordProducer.h
+++ b/llvm/include/llvm/XRay/FDRRecordProducer.h
@@ -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"
@@ -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;
diff --git a/llvm/include/llvm/XRay/FDRRecords.h b/llvm/include/llvm/XRay/FDRRecords.h
index 8af88f5b0e132..7ee8db61b2106 100644
--- a/llvm/include/llvm/XRay/FDRRecords.h
+++ b/llvm/include/llvm/XRay/FDRRecords.h
@@ -13,6 +13,7 @@
#ifndef LLVM_XRAY_FDRRECORDS_H
#define LLVM_XRAY_FDRRECORDS_H
+#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <string>
@@ -47,7 +48,7 @@ class Record {
RK_Function,
};
- static StringRef kindToString(RecordKind K);
+ LLVM_ABI static StringRef kindToString(RecordKind K);
private:
const RecordKind T;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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{};
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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,
@@ -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;
@@ -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;
diff --git a/llvm/include/llvm/XRay/FDRTraceWriter.h b/llvm/include/llvm/XRay/FDRTraceWriter.h
index 40d5f5af91c92..a3dc58e03333e 100644
--- a/llvm/include/llvm/XRay/FDRTraceWriter.h
+++ b/llvm/include/llvm/XRay/FDRTraceWriter.h
@@ -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"
@@ -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);
diff --git a/llvm/include/llvm/XRay/FileHeaderReader.h b/llvm/include/llvm/XRay/FileHeaderReader.h
index 485d26d71456b..ecdb975a30661 100644
--- a/llvm/include/llvm/XRay/FileHeaderReader.h
+++ b/llvm/include/llvm/XRay/FileHeaderReader.h
@@ -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"
@@ -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
diff --git a/llvm/include/llvm/XRay/InstrumentationMap.h b/llvm/include/llvm/XRay/InstrumentationMap.h
index 1979108ff4133..54737e226df89 100644
--- a/llvm/include/llvm/XRay/InstrumentationMap.h
+++ b/llvm/include/llvm/XRay/InstrumentationMap.h
@@ -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>
@@ -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 {
@@ -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; };
diff --git a/llvm/include/llvm/XRay/Profile.h b/llvm/include/llvm/XRay/Profile.h
index 79d9b53387f39..e30c01e489d33 100644
--- a/llvm/include/llvm/XRay/Profile.h
+++ b/llvm/include/llvm/XRay/Profile.h
@@ -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>
@@ -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 {
@@ -68,11 +69,11 @@ 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.
///
@@ -80,7 +81,7 @@ class Profile {
///
/// - The PathData component of the Block is empty
///
- Error addBlock(Block &&B);
+ LLVM_ABI Error addBlock(Block &&B);
Profile() = default;
~Profile() = default;
@@ -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;
diff --git a/llvm/include/llvm/XRay/RecordPrinter.h b/llvm/include/llvm/XRay/RecordPrinter.h
index 8ca4794dce5e2..5d2c27757255a 100644
--- a/llvm/include/llvm/XRay/RecordPrinter.h
+++ b/llvm/include/llvm/XRay/RecordPrinter.h
@@ -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;
diff --git a/llvm/include/llvm/XRay/Trace.h b/llvm/include/llvm/XRay/Trace.h
index eb1f03b2a0d4a..af1d35c67817b 100644
--- a/llvm/include/llvm/XRay/Trace.h
+++ b/llvm/include/llvm/XRay/Trace.h
@@ -16,6 +16,7 @@
#include <vector>
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Error.h"
#include "llvm/XRay/XRayRecord.h"
@@ -50,7 +51,7 @@ class Trace {
typedef std::vector<XRayRecord>::const_iterator citerator;
- friend Expected<Trace> loadTrace(const DataExtractor &, bool);
+ LLVM_ABI_FRIEND friend Expected<Trace> loadTrace(const DataExtractor &, bool);
public:
using size_type = RecordVector::size_type;
@@ -68,11 +69,12 @@ class Trace {
/// This function will attempt to load XRay trace records from the provided
/// |Filename|.
-Expected<Trace> loadTraceFile(StringRef Filename, bool Sort = false);
+LLVM_ABI Expected<Trace> loadTraceFile(StringRef Filename, bool Sort = false);
/// This function will attempt to load XRay trace records from the provided
/// DataExtractor.
-Expected<Trace> loadTrace(const DataExtractor &Extractor, bool Sort = false);
+LLVM_ABI Expected<Trace> loadTrace(const DataExtractor &Extractor,
+ bool Sort = false);
} // namespace xray
} // namespace llvm
|
a47ede4
to
ff10026
Compare
@compnerd, @vgvassilev here's another one for review when you get a chance, thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
ff10026
to
30136cb
Compare
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, and documentation for
LLVM_ABI
and related annotations is found in the LLVM repo here.The bulk of these changes were generated automatically using the Interface Definition Scanner (IDS) tool, followed formatting with
git clang-format
.Additionally, I manually added
LLVM_ABI_FRIEND
to friend member functions declared withLLVM_ABI
.Validation
Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: