Skip to content

Commit 9c5f451

Browse files
authored
[llvm] annotate interfaces in llvm/Support for DLL export (#136014)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/Support` 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`. The following manual adjustments were also applied after running IDS on Linux: - Add `#include "llvm/Support/Compiler.h"` to files where it was not auto-added by IDS due to no pre-existing block of include statements. - Add `LLVM_ABI` to Windows-only code (auto generated with IDS on Windows) - Explicitly make classes non-copyable where needed to due IDS adding `LLVM_ABI` at the class level - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates - Add `LLVM_ABI_FRIEND` to a small number of `friend` function declarations - Add `LLVM_ABI` to a subset of private class methods and fields that require export - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers - Add `LLVM_ABI` functions defined via X-macro ## 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 9f8ff4b commit 9c5f451

File tree

126 files changed

+1622
-1340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1622
-1340
lines changed

llvm/include/llvm/Support/AArch64AttributeParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#ifndef LLVM_SUPPORT_AARCH64ATTRIBUTEPARSER_H
1010
#define LLVM_SUPPORT_AARCH64ATTRIBUTEPARSER_H
1111

12+
#include "llvm/Support/Compiler.h"
1213
#include "llvm/Support/ELFAttrParserExtended.h"
1314
#include "llvm/Support/ELFAttributes.h"
1415

1516
namespace llvm {
1617

1718
class AArch64AttributeParser : public ELFExtendedAttrParser {
18-
static std::vector<SubsectionAndTagToTagName> &returnTagsNamesMap();
19+
LLVM_ABI static std::vector<SubsectionAndTagToTagName> &returnTagsNamesMap();
1920

2021
public:
2122
AArch64AttributeParser(ScopedPrinter *Sw)

llvm/include/llvm/Support/AMDGPUMetadata.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define LLVM_SUPPORT_AMDGPUMETADATA_H
1717

1818
#include "llvm/ADT/StringRef.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include <cstdint>
2021
#include <string>
2122
#include <system_error>
@@ -447,10 +448,10 @@ struct Metadata final {
447448
};
448449

449450
/// Converts \p String to \p HSAMetadata.
450-
std::error_code fromString(StringRef String, Metadata &HSAMetadata);
451+
LLVM_ABI std::error_code fromString(StringRef String, Metadata &HSAMetadata);
451452

452453
/// Converts \p HSAMetadata to \p String.
453-
std::error_code toString(Metadata HSAMetadata, std::string &String);
454+
LLVM_ABI std::error_code toString(Metadata HSAMetadata, std::string &String);
454455

455456
//===----------------------------------------------------------------------===//
456457
// HSA metadata for v3 code object.

llvm/include/llvm/Support/ARMAttributeParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
#include "ARMBuildAttributes.h"
1313
#include "llvm/ADT/StringRef.h"
14+
#include "llvm/Support/Compiler.h"
1415
#include "llvm/Support/ELFAttrParserCompact.h"
1516
#include "llvm/Support/Error.h"
1617

1718
namespace llvm {
1819

1920
class ScopedPrinter;
2021

21-
class ARMAttributeParser : public ELFCompactAttrParser {
22+
class LLVM_ABI ARMAttributeParser : public ELFCompactAttrParser {
2223
struct DisplayHandler {
2324
ARMBuildAttrs::AttrType attribute;
2425
Error (ARMAttributeParser::*routine)(ARMBuildAttrs::AttrType);

llvm/include/llvm/Support/ARMBuildAttributes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#ifndef LLVM_SUPPORT_ARMBUILDATTRIBUTES_H
1919
#define LLVM_SUPPORT_ARMBUILDATTRIBUTES_H
2020

21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/ELFAttributes.h"
2223

2324
namespace llvm {
2425
namespace ARMBuildAttrs {
2526

26-
const TagNameMap &getARMAttributeTags();
27+
LLVM_ABI const TagNameMap &getARMAttributeTags();
2728

2829
enum SpecialAttr {
2930
// This is for the .cpu asm attr. It translates into one or more

llvm/include/llvm/Support/ARMWinEH.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_SUPPORT_ARMWINEH_H
1111

1212
#include "llvm/ADT/ArrayRef.h"
13+
#include "llvm/Support/Compiler.h"
1314
#include "llvm/Support/Endian.h"
1415

1516
namespace llvm {
@@ -205,8 +206,8 @@ inline uint16_t StackAdjustment(const RuntimeFunction &RF) {
205206

206207
/// SavedRegisterMask - Utility function to calculate the set of saved general
207208
/// purpose (r0-r15) and VFP (d0-d31) registers.
208-
std::pair<uint16_t, uint32_t> SavedRegisterMask(const RuntimeFunction &RF,
209-
bool Prologue = true);
209+
LLVM_ABI std::pair<uint16_t, uint32_t>
210+
SavedRegisterMask(const RuntimeFunction &RF, bool Prologue = true);
210211

211212
/// RuntimeFunctionARM64 - An entry in the table of procedure data (.pdata)
212213
///

llvm/include/llvm/Support/Allocator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ namespace detail {
3636

3737
// We call out to an external function to actually print the message as the
3838
// printing code uses Allocator.h in its implementation.
39-
void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t BytesAllocated,
40-
size_t TotalMemory);
39+
LLVM_ABI void printBumpPtrAllocatorStats(unsigned NumSlabs,
40+
size_t BytesAllocated,
41+
size_t TotalMemory);
4142

4243
} // end namespace detail
4344

llvm/include/llvm/Support/BalancedPartitioning.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include "raw_ostream.h"
4343
#include "llvm/ADT/ArrayRef.h"
44+
#include "llvm/Support/Compiler.h"
4445

4546
#include <atomic>
4647
#include <condition_variable>
@@ -67,7 +68,7 @@ class BPFunctionNode {
6768
/// The ID of this node
6869
IDT Id;
6970

70-
void dump(raw_ostream &OS) const;
71+
LLVM_ABI void dump(raw_ostream &OS) const;
7172

7273
protected:
7374
/// The list of utility nodes associated with this node
@@ -99,10 +100,10 @@ struct BalancedPartitioningConfig {
99100

100101
class BalancedPartitioning {
101102
public:
102-
BalancedPartitioning(const BalancedPartitioningConfig &Config);
103+
LLVM_ABI BalancedPartitioning(const BalancedPartitioningConfig &Config);
103104

104105
/// Run recursive graph partitioning that optimizes a given objective.
105-
void run(std::vector<BPFunctionNode> &Nodes) const;
106+
LLVM_ABI void run(std::vector<BPFunctionNode> &Nodes) const;
106107

107108
private:
108109
struct UtilitySignature;
@@ -127,7 +128,7 @@ class BalancedPartitioning {
127128
/// Blocking wait for all threads to complete. Unlike ThreadPool, it is
128129
/// acceptable for other threads to add more tasks while blocking on this
129130
/// call.
130-
void wait();
131+
LLVM_ABI void wait();
131132
BPThreadPool(ThreadPoolInterface &TheThreadPool)
132133
: TheThreadPool(TheThreadPool) {}
133134
};
@@ -192,8 +193,8 @@ class BalancedPartitioning {
192193

193194
protected:
194195
/// Compute the move gain for uniform log-gap cost
195-
static float moveGain(const BPFunctionNode &N, bool FromLeftToRight,
196-
const SignaturesT &Signatures);
196+
LLVM_ABI static float moveGain(const BPFunctionNode &N, bool FromLeftToRight,
197+
const SignaturesT &Signatures);
197198
friend class BalancedPartitioningTest_MoveGain_Test;
198199
};
199200

llvm/include/llvm/Support/Base64.h

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

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/Support/Error.h"
1718
#include <cstdint>
1819
#include <string>
@@ -54,7 +55,8 @@ template <class InputBytes> std::string encodeBase64(InputBytes const &Bytes) {
5455
return Buffer;
5556
}
5657

57-
llvm::Error decodeBase64(llvm::StringRef Input, std::vector<char> &Output);
58+
LLVM_ABI llvm::Error decodeBase64(llvm::StringRef Input,
59+
std::vector<char> &Output);
5860

5961
} // end namespace llvm
6062

llvm/include/llvm/Support/BinaryStreamError.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_SUPPORT_BINARYSTREAMERROR_H
1111

1212
#include "llvm/ADT/StringRef.h"
13+
#include "llvm/Support/Compiler.h"
1314
#include "llvm/Support/Error.h"
1415

1516
#include <string>
@@ -24,7 +25,7 @@ enum class stream_error_code {
2425
};
2526

2627
/// Base class for errors originating when parsing raw PDB files
27-
class BinaryStreamError : public ErrorInfo<BinaryStreamError> {
28+
class LLVM_ABI BinaryStreamError : public ErrorInfo<BinaryStreamError> {
2829
public:
2930
static char ID;
3031
explicit BinaryStreamError(stream_error_code C);

llvm/include/llvm/Support/BinaryStreamReader.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/Support/Alignment.h"
1515
#include "llvm/Support/BinaryStreamArray.h"
1616
#include "llvm/Support/BinaryStreamRef.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/ConvertUTF.h"
1819
#include "llvm/Support/Endian.h"
1920
#include "llvm/Support/Error.h"
@@ -29,10 +30,11 @@ namespace llvm {
2930
class BinaryStreamReader {
3031
public:
3132
BinaryStreamReader() = default;
32-
explicit BinaryStreamReader(BinaryStreamRef Ref);
33-
explicit BinaryStreamReader(BinaryStream &Stream);
34-
explicit BinaryStreamReader(ArrayRef<uint8_t> Data, llvm::endianness Endian);
35-
explicit BinaryStreamReader(StringRef Data, llvm::endianness Endian);
33+
LLVM_ABI explicit BinaryStreamReader(BinaryStreamRef Ref);
34+
LLVM_ABI explicit BinaryStreamReader(BinaryStream &Stream);
35+
LLVM_ABI explicit BinaryStreamReader(ArrayRef<uint8_t> Data,
36+
llvm::endianness Endian);
37+
LLVM_ABI explicit BinaryStreamReader(StringRef Data, llvm::endianness Endian);
3638

3739
BinaryStreamReader(const BinaryStreamReader &Other) = default;
3840

@@ -46,7 +48,7 @@ class BinaryStreamReader {
4648
///
4749
/// \returns a success error code if the data was successfully read, otherwise
4850
/// returns an appropriate error code.
49-
Error readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer);
51+
LLVM_ABI Error readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer);
5052

5153
/// Read \p Size bytes from the underlying stream at the current offset and
5254
/// and set \p Buffer to the resulting data slice. Whether a copy occurs
@@ -55,7 +57,7 @@ class BinaryStreamReader {
5557
///
5658
/// \returns a success error code if the data was successfully read, otherwise
5759
/// returns an appropriate error code.
58-
Error readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size);
60+
LLVM_ABI Error readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size);
5961

6062
/// Read an integer of the specified endianness into \p Dest and update the
6163
/// stream's offset. The data is always copied from the stream's underlying
@@ -91,44 +93,44 @@ class BinaryStreamReader {
9193
///
9294
/// \returns a success error code if the data was successfully read, otherwise
9395
/// returns an appropriate error code.
94-
Error readULEB128(uint64_t &Dest);
96+
LLVM_ABI Error readULEB128(uint64_t &Dest);
9597

9698
/// Read a signed LEB128 encoded value.
9799
///
98100
/// \returns a success error code if the data was successfully read, otherwise
99101
/// returns an appropriate error code.
100-
Error readSLEB128(int64_t &Dest);
102+
LLVM_ABI Error readSLEB128(int64_t &Dest);
101103

102104
/// Read a null terminated string from \p Dest. Whether a copy occurs depends
103105
/// on the implementation of the underlying stream. Updates the stream's
104106
/// offset to point after the newly read data.
105107
///
106108
/// \returns a success error code if the data was successfully read, otherwise
107109
/// returns an appropriate error code.
108-
Error readCString(StringRef &Dest);
110+
LLVM_ABI Error readCString(StringRef &Dest);
109111

110112
/// Similar to readCString, however read a null-terminated UTF16 string
111113
/// instead.
112114
///
113115
/// \returns a success error code if the data was successfully read, otherwise
114116
/// returns an appropriate error code.
115-
Error readWideString(ArrayRef<UTF16> &Dest);
117+
LLVM_ABI Error readWideString(ArrayRef<UTF16> &Dest);
116118

117119
/// Read a \p Length byte string into \p Dest. Whether a copy occurs depends
118120
/// on the implementation of the underlying stream. Updates the stream's
119121
/// offset to point after the newly read data.
120122
///
121123
/// \returns a success error code if the data was successfully read, otherwise
122124
/// returns an appropriate error code.
123-
Error readFixedString(StringRef &Dest, uint32_t Length);
125+
LLVM_ABI Error readFixedString(StringRef &Dest, uint32_t Length);
124126

125127
/// Read the entire remainder of the underlying stream into \p Ref. This is
126128
/// equivalent to calling getUnderlyingStream().slice(Offset). Updates the
127129
/// stream's offset to point to the end of the stream. Never causes a copy.
128130
///
129131
/// \returns a success error code if the data was successfully read, otherwise
130132
/// returns an appropriate error code.
131-
Error readStreamRef(BinaryStreamRef &Ref);
133+
LLVM_ABI Error readStreamRef(BinaryStreamRef &Ref);
132134

133135
/// Read \p Length bytes from the underlying stream into \p Ref. This is
134136
/// equivalent to calling getUnderlyingStream().slice(Offset, Length).
@@ -137,7 +139,7 @@ class BinaryStreamReader {
137139
///
138140
/// \returns a success error code if the data was successfully read, otherwise
139141
/// returns an appropriate error code.
140-
Error readStreamRef(BinaryStreamRef &Ref, uint32_t Length);
142+
LLVM_ABI Error readStreamRef(BinaryStreamRef &Ref, uint32_t Length);
141143

142144
/// Read \p Length bytes from the underlying stream into \p Ref. This is
143145
/// equivalent to calling getUnderlyingStream().slice(Offset, Length).
@@ -146,7 +148,7 @@ class BinaryStreamReader {
146148
///
147149
/// \returns a success error code if the data was successfully read, otherwise
148150
/// returns an appropriate error code.
149-
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length);
151+
LLVM_ABI Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length);
150152

151153
/// Get a pointer to an object of type T from the underlying stream, as if by
152154
/// memcpy, and store the result into \p Dest. It is up to the caller to
@@ -251,17 +253,17 @@ class BinaryStreamReader {
251253
///
252254
/// \returns a success error code if at least \p Amount bytes remain in the
253255
/// stream, otherwise returns an appropriate error code.
254-
Error skip(uint64_t Amount);
256+
LLVM_ABI Error skip(uint64_t Amount);
255257

256258
/// Examine the next byte of the underlying stream without advancing the
257259
/// stream's offset. If the stream is empty the behavior is undefined.
258260
///
259261
/// \returns the next byte in the stream.
260-
uint8_t peek() const;
262+
LLVM_ABI uint8_t peek() const;
261263

262-
Error padToAlignment(uint32_t Align);
264+
LLVM_ABI Error padToAlignment(uint32_t Align);
263265

264-
std::pair<BinaryStreamReader, BinaryStreamReader>
266+
LLVM_ABI std::pair<BinaryStreamReader, BinaryStreamReader>
265267
split(uint64_t Offset) const;
266268

267269
private:

llvm/include/llvm/Support/BinaryStreamRef.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/Support/BinaryStream.h"
1414
#include "llvm/Support/BinaryStreamError.h"
15+
#include "llvm/Support/Compiler.h"
1516
#include "llvm/Support/Error.h"
1617
#include <cstdint>
1718
#include <memory>
@@ -160,11 +161,12 @@ class BinaryStreamRef
160161

161162
public:
162163
BinaryStreamRef() = default;
163-
BinaryStreamRef(BinaryStream &Stream);
164-
BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
165-
std::optional<uint64_t> Length);
166-
explicit BinaryStreamRef(ArrayRef<uint8_t> Data, llvm::endianness Endian);
167-
explicit BinaryStreamRef(StringRef Data, llvm::endianness Endian);
164+
LLVM_ABI BinaryStreamRef(BinaryStream &Stream);
165+
LLVM_ABI BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
166+
std::optional<uint64_t> Length);
167+
LLVM_ABI explicit BinaryStreamRef(ArrayRef<uint8_t> Data,
168+
llvm::endianness Endian);
169+
LLVM_ABI explicit BinaryStreamRef(StringRef Data, llvm::endianness Endian);
168170

169171
BinaryStreamRef(const BinaryStreamRef &Other) = default;
170172
BinaryStreamRef &operator=(const BinaryStreamRef &Other) = default;
@@ -181,16 +183,16 @@ class BinaryStreamRef
181183
/// \returns a success error code if the entire range of data is within the
182184
/// bounds of this BinaryStreamRef's view and the implementation could read
183185
/// the data, and an appropriate error code otherwise.
184-
Error readBytes(uint64_t Offset, uint64_t Size,
185-
ArrayRef<uint8_t> &Buffer) const;
186+
LLVM_ABI Error readBytes(uint64_t Offset, uint64_t Size,
187+
ArrayRef<uint8_t> &Buffer) const;
186188

187189
/// Given an Offset into this BinaryStreamRef, return a reference to the
188190
/// largest buffer the stream could support without necessitating a copy.
189191
///
190192
/// \returns a success error code if implementation could read the data,
191193
/// and an appropriate error code otherwise.
192-
Error readLongestContiguousChunk(uint64_t Offset,
193-
ArrayRef<uint8_t> &Buffer) const;
194+
LLVM_ABI Error readLongestContiguousChunk(uint64_t Offset,
195+
ArrayRef<uint8_t> &Buffer) const;
194196
};
195197

196198
struct BinarySubstreamRef {
@@ -233,11 +235,12 @@ class WritableBinaryStreamRef
233235

234236
public:
235237
WritableBinaryStreamRef() = default;
236-
WritableBinaryStreamRef(WritableBinaryStream &Stream);
237-
WritableBinaryStreamRef(WritableBinaryStream &Stream, uint64_t Offset,
238-
std::optional<uint64_t> Length);
239-
explicit WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
240-
llvm::endianness Endian);
238+
LLVM_ABI WritableBinaryStreamRef(WritableBinaryStream &Stream);
239+
LLVM_ABI WritableBinaryStreamRef(WritableBinaryStream &Stream,
240+
uint64_t Offset,
241+
std::optional<uint64_t> Length);
242+
LLVM_ABI explicit WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
243+
llvm::endianness Endian);
241244
WritableBinaryStreamRef(const WritableBinaryStreamRef &Other) = default;
242245
WritableBinaryStreamRef &
243246
operator=(const WritableBinaryStreamRef &Other) = default;
@@ -255,13 +258,13 @@ class WritableBinaryStreamRef
255258
/// \returns a success error code if the data could fit within the underlying
256259
/// stream at the specified location and the implementation could write the
257260
/// data, and an appropriate error code otherwise.
258-
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) const;
261+
LLVM_ABI Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) const;
259262

260263
/// Conver this WritableBinaryStreamRef to a read-only BinaryStreamRef.
261-
operator BinaryStreamRef() const;
264+
LLVM_ABI operator BinaryStreamRef() const;
262265

263266
/// For buffered streams, commits changes to the backing store.
264-
Error commit();
267+
LLVM_ABI Error commit();
265268
};
266269

267270
} // end namespace llvm

0 commit comments

Comments
 (0)