Skip to content

[llvm] annotate interfaces in llvm/ADT for DLL export #136629

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
May 19, 2025

Conversation

andrurogerz
Copy link
Contributor

@andrurogerz andrurogerz commented Apr 21, 2025

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the llvm/ADT 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.

The following manual adjustments were also applied after running IDS:

  • 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_FRIEND to a small number of friend function declarations
  • Add LLVM_ABI to a subset of private class methods and fields that require export

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

Copy link

github-actions bot commented Apr 21, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@vgvassilev
Copy link
Contributor

Can we mention the mega issue #109483 in the pr description of such PRs?

@vgvassilev vgvassilev requested a review from MaskRay April 23, 2025 18:55
@andrurogerz andrurogerz force-pushed the llvmdll-lib-ADT branch 3 times, most recently from e973a55 to ccf7acd Compare May 5, 2025 18:54
@andrurogerz andrurogerz marked this pull request as ready for review May 13, 2025 00:29
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-llvm-adt

Author: Andrew Rogers (andrurogerz)

Changes

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the llvm/ADT 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.

The following manual adjustments were also applied after running IDS:

  • 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_FRIEND to a small number of friend function declarations
  • Add LLVM_ABI to a subset of private class methods and fields that require export

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

Patch is 133.93 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/136629.diff

23 Files Affected:

  • (modified) llvm/include/llvm/ADT/APFixedPoint.h (+36-30)
  • (modified) llvm/include/llvm/ADT/APFloat.h (+210-194)
  • (modified) llvm/include/llvm/ADT/APInt.h (+169-159)
  • (modified) llvm/include/llvm/ADT/APSInt.h (+3-2)
  • (modified) llvm/include/llvm/ADT/DAGDeltaAlgorithm.h (+2-1)
  • (modified) llvm/include/llvm/ADT/DeltaAlgorithm.h (+2-1)
  • (modified) llvm/include/llvm/ADT/DeltaTree.h (+7-5)
  • (modified) llvm/include/llvm/ADT/DynamicAPInt.h (+5-4)
  • (modified) llvm/include/llvm/ADT/FloatingPointMode.h (+5-4)
  • (modified) llvm/include/llvm/ADT/FoldingSet.h (+26-23)
  • (modified) llvm/include/llvm/ADT/IntEqClasses.h (+6-5)
  • (modified) llvm/include/llvm/ADT/IntervalMap.h (+9-8)
  • (modified) llvm/include/llvm/ADT/RewriteBuffer.h (+8-5)
  • (modified) llvm/include/llvm/ADT/RewriteRope.h (+11-10)
  • (modified) llvm/include/llvm/ADT/SlowDynamicAPInt.h (+79-74)
  • (modified) llvm/include/llvm/ADT/SmallPtrSet.h (+18-14)
  • (modified) llvm/include/llvm/ADT/SmallVector.h (+3-3)
  • (modified) llvm/include/llvm/ADT/Statistic.h (+10-9)
  • (modified) llvm/include/llvm/ADT/StringExtras.h (+13-12)
  • (modified) llvm/include/llvm/ADT/StringMap.h (+9-8)
  • (modified) llvm/include/llvm/ADT/StringRef.h (+49-42)
  • (modified) llvm/include/llvm/ADT/TrieRawHashMap.h (+16-15)
  • (modified) llvm/include/llvm/ADT/Twine.h (+9-7)
diff --git a/llvm/include/llvm/ADT/APFixedPoint.h b/llvm/include/llvm/ADT/APFixedPoint.h
index 70d7f325702cf..658e7ff9caec8 100644
--- a/llvm/include/llvm/ADT/APFixedPoint.h
+++ b/llvm/include/llvm/ADT/APFixedPoint.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
@@ -84,11 +85,11 @@ class FixedPointSemantics {
   /// precision semantic that can precisely represent the precision and ranges
   /// of both input values. This does not compute the resulting semantics for a
   /// given binary operation.
-  FixedPointSemantics
+  LLVM_ABI FixedPointSemantics
   getCommonSemantics(const FixedPointSemantics &Other) const;
 
   /// Print semantics for debug purposes
-  void print(llvm::raw_ostream& OS) const;
+  LLVM_ABI void print(llvm::raw_ostream &OS) const;
 
   /// Returns true if this fixed-point semantic with its value bits interpreted
   /// as an integer can fit in the given floating point semantic without
@@ -97,7 +98,7 @@ class FixedPointSemantics {
   /// minimum integer representation of 127 and -128, respectively. If both of
   /// these values can be represented (possibly inexactly) in the floating
   /// point semantic without overflowing, this returns true.
-  bool fitsInFloatSemantics(const fltSemantics &FloatSema) const;
+  LLVM_ABI bool fitsInFloatSemantics(const fltSemantics &FloatSema) const;
 
   /// Return the FixedPointSemantics for an integer type.
   static FixedPointSemantics GetIntegerSemantics(unsigned Width,
@@ -118,10 +119,10 @@ class FixedPointSemantics {
   /// The result is dependent on the host endianness and not stable across LLVM
   /// versions. See getFromOpaqueInt() to convert it back to a
   /// FixedPointSemantics object.
-  uint32_t toOpaqueInt() const;
+  LLVM_ABI uint32_t toOpaqueInt() const;
   /// Create a FixedPointSemantics object from an integer created via
   /// toOpaqueInt().
-  static FixedPointSemantics getFromOpaqueInt(uint32_t);
+  LLVM_ABI static FixedPointSemantics getFromOpaqueInt(uint32_t);
 
 private:
   unsigned Width          : WidthBitWidth;
@@ -190,22 +191,26 @@ class APFixedPoint {
   // Convert this number to match the semantics provided. If the overflow
   // parameter is provided, set this value to true or false to indicate if this
   // operation results in an overflow.
-  APFixedPoint convert(const FixedPointSemantics &DstSema,
-                       bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint convert(const FixedPointSemantics &DstSema,
+                                bool *Overflow = nullptr) const;
 
   // Perform binary operations on a fixed point type. The resulting fixed point
   // value will be in the common, full precision semantics that can represent
   // the precision and ranges of both input values. See convert() for an
   // explanation of the Overflow parameter.
-  APFixedPoint add(const APFixedPoint &Other, bool *Overflow = nullptr) const;
-  APFixedPoint sub(const APFixedPoint &Other, bool *Overflow = nullptr) const;
-  APFixedPoint mul(const APFixedPoint &Other, bool *Overflow = nullptr) const;
-  APFixedPoint div(const APFixedPoint &Other, bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint add(const APFixedPoint &Other,
+                            bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint sub(const APFixedPoint &Other,
+                            bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint mul(const APFixedPoint &Other,
+                            bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint div(const APFixedPoint &Other,
+                            bool *Overflow = nullptr) const;
 
   // Perform shift operations on a fixed point type. Unlike the other binary
   // operations, the resulting fixed point value will be in the original
   // semantic.
-  APFixedPoint shl(unsigned Amt, bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint shl(unsigned Amt, bool *Overflow = nullptr) const;
   APFixedPoint shr(unsigned Amt, bool *Overflow = nullptr) const {
     // Right shift cannot overflow.
     if (Overflow)
@@ -215,7 +220,7 @@ class APFixedPoint {
 
   /// Perform a unary negation (-X) on this fixed point type, taking into
   /// account saturation if applicable.
-  APFixedPoint negate(bool *Overflow = nullptr) const;
+  LLVM_ABI APFixedPoint negate(bool *Overflow = nullptr) const;
 
   /// Return the integral part of this fixed point number, rounded towards
   /// zero. (-2.5k -> -2)
@@ -234,25 +239,25 @@ class APFixedPoint {
   /// If the overflow parameter is provided, and the integral value is not able
   /// to be fully stored in the provided width and sign, the overflow parameter
   /// is set to true.
-  APSInt convertToInt(unsigned DstWidth, bool DstSign,
-                      bool *Overflow = nullptr) const;
+  LLVM_ABI APSInt convertToInt(unsigned DstWidth, bool DstSign,
+                               bool *Overflow = nullptr) const;
 
   /// Convert this fixed point number to a floating point value with the
   /// provided semantics.
-  APFloat convertToFloat(const fltSemantics &FloatSema) const;
+  LLVM_ABI APFloat convertToFloat(const fltSemantics &FloatSema) const;
 
-  void toString(SmallVectorImpl<char> &Str) const;
+  LLVM_ABI void toString(SmallVectorImpl<char> &Str) const;
   std::string toString() const {
     SmallString<40> S;
     toString(S);
     return std::string(S);
   }
 
-  void print(raw_ostream &) const;
-  void dump() const;
+  LLVM_ABI void print(raw_ostream &) const;
+  LLVM_ABI void dump() const;
 
   // If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1.
-  int compare(const APFixedPoint &Other) const;
+  LLVM_ABI int compare(const APFixedPoint &Other) const;
   bool operator==(const APFixedPoint &Other) const {
     return compare(Other) == 0;
   }
@@ -268,21 +273,22 @@ class APFixedPoint {
     return compare(Other) <= 0;
   }
 
-  static APFixedPoint getMax(const FixedPointSemantics &Sema);
-  static APFixedPoint getMin(const FixedPointSemantics &Sema);
-  static APFixedPoint getEpsilon(const FixedPointSemantics &Sema);
+  LLVM_ABI static APFixedPoint getMax(const FixedPointSemantics &Sema);
+  LLVM_ABI static APFixedPoint getMin(const FixedPointSemantics &Sema);
+  LLVM_ABI static APFixedPoint getEpsilon(const FixedPointSemantics &Sema);
 
   /// Given a floating point semantic, return the next floating point semantic
   /// with a larger exponent and larger or equal mantissa.
-  static const fltSemantics *promoteFloatSemantics(const fltSemantics *S);
+  LLVM_ABI static const fltSemantics *
+  promoteFloatSemantics(const fltSemantics *S);
 
   /// Create an APFixedPoint with a value equal to that of the provided integer,
   /// and in the same semantics as the provided target semantics. If the value
   /// is not able to fit in the specified fixed point semantics, and the
   /// overflow parameter is provided, it is set to true.
-  static APFixedPoint getFromIntValue(const APSInt &Value,
-                                      const FixedPointSemantics &DstFXSema,
-                                      bool *Overflow = nullptr);
+  LLVM_ABI static APFixedPoint
+  getFromIntValue(const APSInt &Value, const FixedPointSemantics &DstFXSema,
+                  bool *Overflow = nullptr);
 
   /// Create an APFixedPoint with a value equal to that of the provided
   /// floating point value, in the provided target semantics. If the value is
@@ -291,9 +297,9 @@ class APFixedPoint {
   /// For NaN, the Overflow flag is always set. For +inf and -inf, if the
   /// semantic is saturating, the value saturates. Otherwise, the Overflow flag
   /// is set.
-  static APFixedPoint getFromFloatValue(const APFloat &Value,
-                                        const FixedPointSemantics &DstFXSema,
-                                        bool *Overflow = nullptr);
+  LLVM_ABI static APFixedPoint
+  getFromFloatValue(const APFloat &Value, const FixedPointSemantics &DstFXSema,
+                    bool *Overflow = nullptr);
 
 private:
   APSInt Val;
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index ed49380cfc05f..c671830185737 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/float128.h"
 #include <memory>
@@ -253,38 +254,39 @@ struct APFloatBase {
     S_MaxSemantics = S_x87DoubleExtended,
   };
 
-  static const llvm::fltSemantics &EnumToSemantics(Semantics S);
-  static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem);
-
-  static const fltSemantics &IEEEhalf() LLVM_READNONE;
-  static const fltSemantics &BFloat() LLVM_READNONE;
-  static const fltSemantics &IEEEsingle() LLVM_READNONE;
-  static const fltSemantics &IEEEdouble() LLVM_READNONE;
-  static const fltSemantics &IEEEquad() LLVM_READNONE;
-  static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
-  static const fltSemantics &PPCDoubleDoubleLegacy() LLVM_READNONE;
-  static const fltSemantics &Float8E5M2() LLVM_READNONE;
-  static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
-  static const fltSemantics &Float8E4M3() LLVM_READNONE;
-  static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
-  static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
-  static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
-  static const fltSemantics &Float8E3M4() LLVM_READNONE;
-  static const fltSemantics &FloatTF32() LLVM_READNONE;
-  static const fltSemantics &Float8E8M0FNU() LLVM_READNONE;
-  static const fltSemantics &Float6E3M2FN() LLVM_READNONE;
-  static const fltSemantics &Float6E2M3FN() LLVM_READNONE;
-  static const fltSemantics &Float4E2M1FN() LLVM_READNONE;
-  static const fltSemantics &x87DoubleExtended() LLVM_READNONE;
+  LLVM_ABI static const llvm::fltSemantics &EnumToSemantics(Semantics S);
+  LLVM_ABI static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem);
+
+  LLVM_ABI static const fltSemantics &IEEEhalf() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &BFloat() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &IEEEsingle() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &IEEEdouble() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &IEEEquad() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &PPCDoubleDoubleLegacy() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E5M2() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E4M3() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E3M4() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &FloatTF32() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float8E8M0FNU() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float6E3M2FN() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float6E2M3FN() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Float4E2M1FN() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &x87DoubleExtended() LLVM_READNONE;
 
   /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
   /// anything real.
-  static const fltSemantics &Bogus() LLVM_READNONE;
+  LLVM_ABI static const fltSemantics &Bogus() LLVM_READNONE;
 
   // Returns true if any number described by this semantics can be precisely
   // represented by the specified semantics. Does not take into account
   // the value of fltNonfiniteBehavior, hasZero, hasSignedRepr.
-  static bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B);
+  LLVM_ABI static bool isRepresentableBy(const fltSemantics &A,
+                                         const fltSemantics &B);
 
   /// @}
 
@@ -344,26 +346,27 @@ struct APFloatBase {
     IEK_Inf = INT_MAX
   };
 
-  static unsigned int semanticsPrecision(const fltSemantics &);
-  static ExponentType semanticsMinExponent(const fltSemantics &);
-  static ExponentType semanticsMaxExponent(const fltSemantics &);
-  static unsigned int semanticsSizeInBits(const fltSemantics &);
-  static unsigned int semanticsIntSizeInBits(const fltSemantics&, bool);
-  static bool semanticsHasZero(const fltSemantics &);
-  static bool semanticsHasSignedRepr(const fltSemantics &);
-  static bool semanticsHasInf(const fltSemantics &);
-  static bool semanticsHasNaN(const fltSemantics &);
-  static bool isIEEELikeFP(const fltSemantics &);
-  static bool hasSignBitInMSB(const fltSemantics &);
+  LLVM_ABI static unsigned int semanticsPrecision(const fltSemantics &);
+  LLVM_ABI static ExponentType semanticsMinExponent(const fltSemantics &);
+  LLVM_ABI static ExponentType semanticsMaxExponent(const fltSemantics &);
+  LLVM_ABI static unsigned int semanticsSizeInBits(const fltSemantics &);
+  LLVM_ABI static unsigned int semanticsIntSizeInBits(const fltSemantics &,
+                                                      bool);
+  LLVM_ABI static bool semanticsHasZero(const fltSemantics &);
+  LLVM_ABI static bool semanticsHasSignedRepr(const fltSemantics &);
+  LLVM_ABI static bool semanticsHasInf(const fltSemantics &);
+  LLVM_ABI static bool semanticsHasNaN(const fltSemantics &);
+  LLVM_ABI static bool isIEEELikeFP(const fltSemantics &);
+  LLVM_ABI static bool hasSignBitInMSB(const fltSemantics &);
 
   // Returns true if any number described by \p Src can be precisely represented
   // by a normal (not subnormal) value in \p Dst.
-  static bool isRepresentableAsNormalIn(const fltSemantics &Src,
-                                        const fltSemantics &Dst);
+  LLVM_ABI static bool isRepresentableAsNormalIn(const fltSemantics &Src,
+                                                 const fltSemantics &Dst);
 
   /// Returns the size of the floating point number (in bits) in the given
   /// semantics.
-  static unsigned getSizeInBits(const fltSemantics &Sem);
+  LLVM_ABI static unsigned getSizeInBits(const fltSemantics &Sem);
 };
 
 namespace detail {
@@ -404,15 +407,15 @@ class IEEEFloat final {
   /// \name Constructors
   /// @{
 
-  IEEEFloat(const fltSemantics &); // Default construct to +0.0
-  IEEEFloat(const fltSemantics &, integerPart);
-  IEEEFloat(const fltSemantics &, uninitializedTag);
-  IEEEFloat(const fltSemantics &, const APInt &);
-  explicit IEEEFloat(double d);
-  explicit IEEEFloat(float f);
-  IEEEFloat(const IEEEFloat &);
-  IEEEFloat(IEEEFloat &&);
-  ~IEEEFloat();
+  LLVM_ABI IEEEFloat(const fltSemantics &); // Default construct to +0.0
+  LLVM_ABI IEEEFloat(const fltSemantics &, integerPart);
+  LLVM_ABI IEEEFloat(const fltSemantics &, uninitializedTag);
+  LLVM_ABI IEEEFloat(const fltSemantics &, const APInt &);
+  LLVM_ABI explicit IEEEFloat(double d);
+  LLVM_ABI explicit IEEEFloat(float f);
+  LLVM_ABI IEEEFloat(const IEEEFloat &);
+  LLVM_ABI IEEEFloat(IEEEFloat &&);
+  LLVM_ABI ~IEEEFloat();
 
   /// @}
 
@@ -427,46 +430,49 @@ class IEEEFloat final {
   /// \name Arithmetic
   /// @{
 
-  opStatus add(const IEEEFloat &, roundingMode);
-  opStatus subtract(const IEEEFloat &, roundingMode);
-  opStatus multiply(const IEEEFloat &, roundingMode);
-  opStatus divide(const IEEEFloat &, roundingMode);
+  LLVM_ABI opStatus add(const IEEEFloat &, roundingMode);
+  LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode);
+  LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode);
+  LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode);
   /// IEEE remainder.
-  opStatus remainder(const IEEEFloat &);
+  LLVM_ABI opStatus remainder(const IEEEFloat &);
   /// C fmod, or llvm frem.
-  opStatus mod(const IEEEFloat &);
-  opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode);
-  opStatus roundToIntegral(roundingMode);
+  LLVM_ABI opStatus mod(const IEEEFloat &);
+  LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &,
+                                     roundingMode);
+  LLVM_ABI opStatus roundToIntegral(roundingMode);
   /// IEEE-754R 5.3.1: nextUp/nextDown.
-  opStatus next(bool nextDown);
+  LLVM_ABI opStatus next(bool nextDown);
 
   /// @}
 
   /// \name Sign operations.
   /// @{
 
-  void changeSign();
+  LLVM_ABI void changeSign();
 
   /// @}
 
   /// \name Conversions
   /// @{
 
-  opStatus convert(const fltSemantics &, roundingMode, bool *);
-  opStatus convertToInteger(MutableArrayRef<integerPart>, unsigned int, bool,
-                            roundingMode, bool *) const;
-  opStatus convertFromAPInt(const APInt &, bool, roundingMode);
-  opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int,
-                                          bool, roundingMode);
-  opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
-                                          bool, roundingMode);
-  Expected<opStatus> convertFromString(StringRef, roundingMode);
-  APInt bitcastToAPInt() const;
-  double convertToDouble() const;
+  LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *);
+  LLVM_ABI opStatus convertToInteger(MutableArrayRef<integerPart>, unsigned int,
+                                     bool, roundingMode, bool *) const;
+  LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode);
+  LLVM_ABI opStatus convertFromSignExtendedInteger(const integerPart *,
+                                                   unsigned int, bool,
+                                                   roundingMode);
+  LLVM_ABI opStatus convertFromZeroExtendedInteger(const integerPart *,
+                                                   unsigned int, bool,
+                                                   roundingMode);
+  LLVM_ABI Expected<opStatus> convertFromString(StringRef, roundingMode);
+  LLVM_ABI APInt bitcastToAPInt() const;
+  LLVM_ABI double convertToDouble() const;
 #ifdef HAS_IEE754_FLOAT128
-  float128 convertToQuad() const;
+  LLVM_ABI float128 convertToQuad() const;
 #endif
-  float convertToFloat() const;
+  LLVM_ABI float convertToFloat() const;
 
   /// @}
 
@@ -477,16 +483,16 @@ class IEEEFloat final {
 
   /// IEEE comparison with another floating point number (NaNs compare
   /// unordered, 0==-0).
-  cmpResult compare(const IEEEFloat &) const;
+  LLVM_ABI cmpResult compare(const IEEEFloat &) const;
 
   /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
-  bool bitwiseIsEqual(const IEEEFloat &) const;
+  LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const;
 
   /// Write out a hexadecimal representation of the floating point value to DST,
   /// which must be of sufficient size, in the C99 form [-]0xh.hhhhp[+-]d.
   /// Return the number of characters written, excluding the terminating NUL.
-  unsigned int convertToHexString(char *dst, unsigned int hexDigits,
-                                  bool upperCase, roundingMode) const;
+  LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits,
+                                           bool upperCase, roundingMode) const;
 
   /// \name IEEE-754R 5.7.2 General operations.
   /// @{
@@ -514,7 +520,7 @@ class IEEEFloat final {
 
   /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
   /// denormal.
-  bool isDenormal() const;
+  LLVM_ABI bool isDenormal() const;
 
   /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
   bool isInfinity() const { return category == fcInfinity; }
@@ -523,7 +529,7 @@ class IEEEFloat final {
   bool isNaN() const { return category == fcNaN; }
 
   /// Returns true if and only if the float is a signaling NaN.
-  bool isSignaling() const;
+  LLVM_ABI bool isSignaling() const;
 
   /// @}
 
@@ -539,23 +545,23 @@ class IEEEFloat final {
 
   /// Returns true if and only if the number has the smallest possible non-zero
   /// magnitude in the current semantics.
-  bool isSmallest() const;
+  LLVM_ABI bool isSmallest() const;
 
   /// Returns true if this is the smallest (by magnitude) normalized finite
   /// number in the given semantics.
-  ...
[truncated]

@andrurogerz
Copy link
Contributor Author

@compnerd mind having a look?

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me with minor quibbles about dump being introduced into the ABI.

@andrurogerz
Copy link
Contributor Author

#139804 addresses the dump method feedback; I will rebase + update this PR once that is accepted and merged

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Lgtm.

compnerd pushed a commit that referenced this pull request May 14, 2025
## Purpose
Add proper preprocessor guards for all `dump()` methods in the LLVM
support library. This change ensures these methods are not part of the
public ABI for release builds.

## Overview
* Annotates all `dump` methods in Support and ADT source with the
`LLVM_DUMP_METHOD` macro.
* Conditionally includes all `dump` method definitions in Support and
ADT source so they are only present on debug/assert builds and when
`LLVM_ENABLE_DUMP` is explicitly defined.

NOTE: For many of these `dump` methods, the implementation was already
properly guarded but the declaration in the header file was not.

## Background
This issue was raised in comments on #136629. I am addressing it as a
separate change since it is independent from the changes being made in
that PR.

According to [this
documentation](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L637),
`dump` methods should be annotated with `LLVM_DUMP_METHOD` and
conditionally included as follows:
```
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  LLVM_DUMP_METHOD void dump() const;
#endif
```

## Validation
* Local release build succeeds.
* CI
@andrurogerz
Copy link
Contributor Author

PR #139938 will add proper gating for the dump() methods, so I just removed the LLVM_ABI annotations from them in this PR.

compnerd pushed a commit that referenced this pull request May 14, 2025
## Purpose
Add proper preprocessor guards for all `dump()` methods in the LLVM
support library. This change ensures these methods are not part of the
public ABI for release builds.

## Overview
* Annotates all `dump` methods in Support and ADT source with the
`LLVM_DUMP_METHOD` macro.
* Conditionally includes all `dump` method definitions in Support and
ADT source so they are only present on debug/assert builds and when
`LLVM_ENABLE_DUMP` is explicitly defined.

NOTE: For many of these `dump` methods, the implementation was already
properly guarded but the declaration in the header file was not.

## Background
This PR is a redo of #139804 with some changes to fix clang and unit
test build breaks.

This issue was raised in comments on #136629. I am addressing it as a
separate change since it is independent from the changes being made in
that PR.

According to [this
documentation](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L637),
`dump` methods should be annotated with `LLVM_DUMP_METHOD` and
conditionally included as follows:
```
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  LLVM_DUMP_METHOD void dump() const;
#endif
```

## Validation
* Local release build succeeds.
* CI
@andrurogerz
Copy link
Contributor Author

Rebased on #139938.

@compnerd compnerd merged commit 553d4c1 into llvm:main May 19, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants