Skip to content

[llvm] annotate interfaces in llvm/Support for DLL export #136014

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions llvm/include/llvm/Support/AMDGPUMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define LLVM_SUPPORT_AMDGPUMETADATA_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <string>
#include <system_error>
Expand Down Expand Up @@ -447,10 +448,10 @@ struct Metadata final {
};

/// Converts \p String to \p HSAMetadata.
std::error_code fromString(StringRef String, Metadata &HSAMetadata);
LLVM_ABI std::error_code fromString(StringRef String, Metadata &HSAMetadata);

/// Converts \p HSAMetadata to \p String.
std::error_code toString(Metadata HSAMetadata, std::string &String);
LLVM_ABI std::error_code toString(Metadata HSAMetadata, std::string &String);

//===----------------------------------------------------------------------===//
// HSA metadata for v3 code object.
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Support/ARMAttributeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

#include "ARMBuildAttributes.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ELFAttrParserCompact.h"
#include "llvm/Support/Error.h"

namespace llvm {

class ScopedPrinter;

class ARMAttributeParser : public ELFCompactAttrParser {
class LLVM_ABI ARMAttributeParser : public ELFCompactAttrParser {
struct DisplayHandler {
ARMBuildAttrs::AttrType attribute;
Error (ARMAttributeParser::*routine)(ARMBuildAttrs::AttrType);
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Support/ARMBuildAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
#ifndef LLVM_SUPPORT_ARMBUILDATTRIBUTES_H
#define LLVM_SUPPORT_ARMBUILDATTRIBUTES_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/ELFAttributes.h"

namespace llvm {
namespace ARMBuildAttrs {

const TagNameMap &getARMAttributeTags();
LLVM_ABI const TagNameMap &getARMAttributeTags();

enum SpecialAttr {
// This is for the .cpu asm attr. It translates into one or more
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/Support/ARMWinEH.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_SUPPORT_ARMWINEH_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Endian.h"

namespace llvm {
Expand Down Expand Up @@ -205,8 +206,8 @@ inline uint16_t StackAdjustment(const RuntimeFunction &RF) {

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

/// RuntimeFunctionARM64 - An entry in the table of procedure data (.pdata)
///
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ namespace detail {

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

} // end namespace detail

Expand Down
13 changes: 7 additions & 6 deletions llvm/include/llvm/Support/BalancedPartitioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "raw_ostream.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Compiler.h"

#include <atomic>
#include <condition_variable>
Expand All @@ -67,7 +68,7 @@ class BPFunctionNode {
/// The ID of this node
IDT Id;

void dump(raw_ostream &OS) const;
LLVM_ABI void dump(raw_ostream &OS) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this should be a debug only symbol, why does this need to be exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is a public symbol exposed by the class. If it is not annotated, IDS will warn on it. If it is intended to be debug-only, then should it be guarded?

#ifndef NDEBUG
    void dump(raw_ostream &OS) const;
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have a dedicated macro for dump method:

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  void dump(...) const;
#endif

Preferably, we should also add LLVM_DUMP_METHOD on the dump function but that is to force it be available inside debugger.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM_ENABLE_DUMP should be used and it should not be dependent on asserts (NDEBUG).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to keep this PR focused on adding annotations. I've removed LLVM_ABI from all of the dump() methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really agree with the omission of dump() from the ABI. If dump methods are enabled, they should be exported, we don't want them to get internalized and optimized away.

If we do want to exclude them, isn't it necessary to annotate them with LLVM_ABI_NOT_EXPORTED so that ids doesn't re-add the annotation on the next run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that they should just be exported here. I will put them back to the way IDS converted them. I think ideally they would all be gated by LLVM_ENABLE_DUMP, but such a change does not belong here.


protected:
/// The list of utility nodes associated with this node
Expand Down Expand Up @@ -99,10 +100,10 @@ struct BalancedPartitioningConfig {

class BalancedPartitioning {
public:
BalancedPartitioning(const BalancedPartitioningConfig &Config);
LLVM_ABI BalancedPartitioning(const BalancedPartitioningConfig &Config);

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

private:
struct UtilitySignature;
Expand All @@ -127,7 +128,7 @@ class BalancedPartitioning {
/// Blocking wait for all threads to complete. Unlike ThreadPool, it is
/// acceptable for other threads to add more tasks while blocking on this
/// call.
void wait();
LLVM_ABI void wait();
BPThreadPool(ThreadPoolInterface &TheThreadPool)
: TheThreadPool(TheThreadPool) {}
};
Expand Down Expand Up @@ -192,8 +193,8 @@ class BalancedPartitioning {

protected:
/// Compute the move gain for uniform log-gap cost
static float moveGain(const BPFunctionNode &N, bool FromLeftToRight,
const SignaturesT &Signatures);
LLVM_ABI static float moveGain(const BPFunctionNode &N, bool FromLeftToRight,
const SignaturesT &Signatures);
friend class BalancedPartitioningTest_MoveGain_Test;
};

Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Support/Base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_SUPPORT_BASE64_H
#define LLVM_SUPPORT_BASE64_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include <cstdint>
#include <string>
Expand Down Expand Up @@ -54,7 +55,8 @@ template <class InputBytes> std::string encodeBase64(InputBytes const &Bytes) {
return Buffer;
}

llvm::Error decodeBase64(llvm::StringRef Input, std::vector<char> &Output);
LLVM_ABI llvm::Error decodeBase64(llvm::StringRef Input,
std::vector<char> &Output);

} // end namespace llvm

Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Support/BinaryStreamError.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_SUPPORT_BINARYSTREAMERROR_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"

#include <string>
Expand All @@ -24,7 +25,7 @@ enum class stream_error_code {
};

/// Base class for errors originating when parsing raw PDB files
class BinaryStreamError : public ErrorInfo<BinaryStreamError> {
class LLVM_ABI BinaryStreamError : public ErrorInfo<BinaryStreamError> {
public:
static char ID;
explicit BinaryStreamError(stream_error_code C);
Expand Down
38 changes: 20 additions & 18 deletions llvm/include/llvm/Support/BinaryStreamReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/Support/Alignment.h"
#include "llvm/Support/BinaryStreamArray.h"
#include "llvm/Support/BinaryStreamRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
Expand All @@ -29,10 +30,11 @@ namespace llvm {
class BinaryStreamReader {
public:
BinaryStreamReader() = default;
explicit BinaryStreamReader(BinaryStreamRef Ref);
explicit BinaryStreamReader(BinaryStream &Stream);
explicit BinaryStreamReader(ArrayRef<uint8_t> Data, llvm::endianness Endian);
explicit BinaryStreamReader(StringRef Data, llvm::endianness Endian);
LLVM_ABI explicit BinaryStreamReader(BinaryStreamRef Ref);
LLVM_ABI explicit BinaryStreamReader(BinaryStream &Stream);
LLVM_ABI explicit BinaryStreamReader(ArrayRef<uint8_t> Data,
llvm::endianness Endian);
LLVM_ABI explicit BinaryStreamReader(StringRef Data, llvm::endianness Endian);

BinaryStreamReader(const BinaryStreamReader &Other) = default;

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

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

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

/// Read a signed LEB128 encoded value.
///
/// \returns a success error code if the data was successfully read, otherwise
/// returns an appropriate error code.
Error readSLEB128(int64_t &Dest);
LLVM_ABI Error readSLEB128(int64_t &Dest);

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

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

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

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

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

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

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

/// Examine the next byte of the underlying stream without advancing the
/// stream's offset. If the stream is empty the behavior is undefined.
///
/// \returns the next byte in the stream.
uint8_t peek() const;
LLVM_ABI uint8_t peek() const;

Error padToAlignment(uint32_t Align);
LLVM_ABI Error padToAlignment(uint32_t Align);

std::pair<BinaryStreamReader, BinaryStreamReader>
LLVM_ABI std::pair<BinaryStreamReader, BinaryStreamReader>
split(uint64_t Offset) const;

private:
Expand Down
37 changes: 20 additions & 17 deletions llvm/include/llvm/Support/BinaryStreamRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/BinaryStream.h"
#include "llvm/Support/BinaryStreamError.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include <cstdint>
#include <memory>
Expand Down Expand Up @@ -160,11 +161,12 @@ class BinaryStreamRef

public:
BinaryStreamRef() = default;
BinaryStreamRef(BinaryStream &Stream);
BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
std::optional<uint64_t> Length);
explicit BinaryStreamRef(ArrayRef<uint8_t> Data, llvm::endianness Endian);
explicit BinaryStreamRef(StringRef Data, llvm::endianness Endian);
LLVM_ABI BinaryStreamRef(BinaryStream &Stream);
LLVM_ABI BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
std::optional<uint64_t> Length);
LLVM_ABI explicit BinaryStreamRef(ArrayRef<uint8_t> Data,
llvm::endianness Endian);
LLVM_ABI explicit BinaryStreamRef(StringRef Data, llvm::endianness Endian);

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

/// Given an Offset into this BinaryStreamRef, return a reference to the
/// largest buffer the stream could support without necessitating a copy.
///
/// \returns a success error code if implementation could read the data,
/// and an appropriate error code otherwise.
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) const;
LLVM_ABI Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) const;
};

struct BinarySubstreamRef {
Expand Down Expand Up @@ -233,11 +235,12 @@ class WritableBinaryStreamRef

public:
WritableBinaryStreamRef() = default;
WritableBinaryStreamRef(WritableBinaryStream &Stream);
WritableBinaryStreamRef(WritableBinaryStream &Stream, uint64_t Offset,
std::optional<uint64_t> Length);
explicit WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
llvm::endianness Endian);
LLVM_ABI WritableBinaryStreamRef(WritableBinaryStream &Stream);
LLVM_ABI WritableBinaryStreamRef(WritableBinaryStream &Stream,
uint64_t Offset,
std::optional<uint64_t> Length);
LLVM_ABI explicit WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
llvm::endianness Endian);
WritableBinaryStreamRef(const WritableBinaryStreamRef &Other) = default;
WritableBinaryStreamRef &
operator=(const WritableBinaryStreamRef &Other) = default;
Expand All @@ -255,13 +258,13 @@ class WritableBinaryStreamRef
/// \returns a success error code if the data could fit within the underlying
/// stream at the specified location and the implementation could write the
/// data, and an appropriate error code otherwise.
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) const;
LLVM_ABI Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) const;

/// Conver this WritableBinaryStreamRef to a read-only BinaryStreamRef.
operator BinaryStreamRef() const;
LLVM_ABI operator BinaryStreamRef() const;

/// For buffered streams, commits changes to the backing store.
Error commit();
LLVM_ABI Error commit();
};

} // end namespace llvm
Expand Down
Loading