Skip to content

Commit

Permalink
Introduce SLINKY_TRIVIAL_ABI (#479)
Browse files Browse the repository at this point in the history
https://clang.llvm.org/docs/AttributeReference.html#trivial-abi 

This PR adds SLINKY_TRIVIAL_ABI and annotates ref_count with it.
The binary size (measured internally) impact: libruntime.so: 321K ->
315K, libruntime.a: 413K -> 406K
  • Loading branch information
alexander-shaposhnikov authored Nov 2, 2024
1 parent f93dd94 commit 46195ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/ref_count.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ref_counted {

// A smart pointer to a ref_counted base.
template <typename T>
class ref_count {
class SLINKY_TRIVIAL_ABI ref_count {
T* value;

public:
Expand Down
12 changes: 12 additions & 0 deletions base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ namespace slinky {
#define SLINKY_ALWAYS_INLINE __attribute__((always_inline))
#define SLINKY_NO_INLINE __attribute__((noinline))

#if !defined(__has_attribute)
#define SLINKY_HAS_ATTRIBUTE(x) 0
#else
#define SLINKY_HAS_ATTRIBUTE(x) __has_attribute(x)
#endif

#if SLINKY_HAS_ATTRIBUTE(trivial_abi)
#define SLINKY_TRIVIAL_ABI __attribute__((trivial_abi))
#else
#define SLINKY_TRIVIAL_ABI
#endif

#ifdef NDEBUG
// alloca() will cause stack-smashing code to be inserted;
// while laudable, we use alloca() in time-critical code
Expand Down

0 comments on commit 46195ce

Please sign in to comment.