[llvm] r351891 - [ADT] Move away from __attribute__((always_inline)).

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 14:40:36 PST 2019


Author: davide
Date: Tue Jan 22 14:40:35 2019
New Revision: 351891

URL: http://llvm.org/viewvc/llvm-project?rev=351891&view=rev
Log:
[ADT] Move away from __attribute__((always_inline)).

Some member functions of StringRef/SmallVector/StringSwitch
are marked with the `always_inline` attribute. The result
is that  the body of these functions is not emitted, hence the
debugger can't evaluate them (a typical example is
StringRef::size()), even if the code is built with `-O0`.

The main driver behind this was that of getting faster turnaround
when running `check-llvm`. A previous commit clarifies how to
get good performance when running the testsuite, so we can
get rid of the attribute here.

An alternative approach considered was that of using attribute `used`,
but in the end we preferred to not slap yet another attribute on
these functions.

Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h
    llvm/trunk/include/llvm/ADT/StringRef.h
    llvm/trunk/include/llvm/ADT/StringSwitch.h

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=351891&r1=351890&r2=351891&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Tue Jan 22 14:40:35 2019
@@ -124,13 +124,9 @@ public:
   using const_pointer = const T *;
 
   // forward iterator creation methods.
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   iterator begin() { return (iterator)this->BeginX; }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   const_iterator begin() const { return (const_iterator)this->BeginX; }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   iterator end() { return begin() + size(); }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   const_iterator end() const { return begin() + size(); }
 
   // reverse iterator creation methods.
@@ -149,12 +145,10 @@ public:
   /// Return a pointer to the vector's buffer, even if empty().
   const_pointer data() const { return const_pointer(begin()); }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   reference operator[](size_type idx) {
     assert(idx < size());
     return begin()[idx];
   }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   const_reference operator[](size_type idx) const {
     assert(idx < size());
     return begin()[idx];

Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=351891&r1=351890&r2=351891&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Tue Jan 22 14:40:35 2019
@@ -62,7 +62,6 @@ namespace llvm {
 
     // Workaround memcmp issue with null pointers (undefined behavior)
     // by providing a specialized version
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     static int compareMemory(const char *Lhs, const char *Rhs, size_t Length) {
       if (Length == 0) { return 0; }
       return ::memcmp(Lhs,Rhs,Length);
@@ -80,17 +79,14 @@ namespace llvm {
     StringRef(std::nullptr_t) = delete;
 
     /// Construct a string ref from a cstring.
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     /*implicit*/ StringRef(const char *Str)
         : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
 
     /// Construct a string ref from a pointer and length.
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     /*implicit*/ constexpr StringRef(const char *data, size_t length)
         : Data(data), Length(length) {}
 
     /// Construct a string ref from an std::string.
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     /*implicit*/ StringRef(const std::string &Str)
       : Data(Str.data()), Length(Str.length()) {}
 
@@ -123,17 +119,14 @@ namespace llvm {
     /// data - Get a pointer to the start of the string (which may not be null
     /// terminated).
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     const char *data() const { return Data; }
 
     /// empty - Check if the string is empty.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool empty() const { return Length == 0; }
 
     /// size - Get the string size.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     size_t size() const { return Length; }
 
     /// front - Get the first character in the string.
@@ -164,7 +157,6 @@ namespace llvm {
     /// equals - Check for string equality, this is more efficient than
     /// compare() when the relative ordering of inequal strings isn't needed.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool equals(StringRef RHS) const {
       return (Length == RHS.Length &&
               compareMemory(Data, RHS.Data, RHS.Length) == 0);
@@ -179,7 +171,6 @@ namespace llvm {
     /// compare - Compare two strings; the result is -1, 0, or 1 if this string
     /// is lexicographically less than, equal to, or greater than the \p RHS.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     int compare(StringRef RHS) const {
       // Check the prefix for a mismatch.
       if (int Res = compareMemory(Data, RHS.Data, std::min(Length, RHS.Length)))
@@ -262,7 +253,6 @@ namespace llvm {
 
     /// Check if this string starts with the given \p Prefix.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool startswith(StringRef Prefix) const {
       return Length >= Prefix.Length &&
              compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
@@ -274,7 +264,6 @@ namespace llvm {
 
     /// Check if this string ends with the given \p Suffix.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool endswith(StringRef Suffix) const {
       return Length >= Suffix.Length &&
         compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
@@ -293,7 +282,6 @@ namespace llvm {
     /// \returns The index of the first occurrence of \p C, or npos if not
     /// found.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     size_t find(char C, size_t From = 0) const {
       size_t FindBegin = std::min(From, Length);
       if (FindBegin < Length) { // Avoid calling memchr with nullptr.
@@ -316,7 +304,6 @@ namespace llvm {
     /// \returns The index of the first character satisfying \p F starting from
     /// \p From, or npos if not found.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     size_t find_if(function_ref<bool(char)> F, size_t From = 0) const {
       StringRef S = drop_front(From);
       while (!S.empty()) {
@@ -332,7 +319,6 @@ namespace llvm {
     /// \returns The index of the first character not satisfying \p F starting
     /// from \p From, or npos if not found.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     size_t find_if_not(function_ref<bool(char)> F, size_t From = 0) const {
       return find_if([F](char c) { return !F(c); }, From);
     }
@@ -443,19 +429,16 @@ namespace llvm {
     /// Return true if the given string is a substring of *this, and false
     /// otherwise.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool contains(StringRef Other) const { return find(Other) != npos; }
 
     /// Return true if the given character is contained in *this, and false
     /// otherwise.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool contains(char C) const { return find_first_of(C) != npos; }
 
     /// Return true if the given string is a substring of *this, and false
     /// otherwise.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool contains_lower(StringRef Other) const {
       return find_lower(Other) != npos;
     }
@@ -463,7 +446,6 @@ namespace llvm {
     /// Return true if the given character is contained in *this, and false
     /// otherwise.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool contains_lower(char C) const { return find_lower(C) != npos; }
 
     /// @}
@@ -593,7 +575,6 @@ namespace llvm {
     /// exceeds the number of characters remaining in the string, the string
     /// suffix (starting with \p Start) will be returned.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef substr(size_t Start, size_t N = npos) const {
       Start = std::min(Start, Length);
       return StringRef(Data + Start, std::min(N, Length - Start));
@@ -603,7 +584,6 @@ namespace llvm {
     /// elements remaining.  If \p N is greater than the length of the
     /// string, the entire string is returned.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef take_front(size_t N = 1) const {
       if (N >= size())
         return *this;
@@ -614,7 +594,6 @@ namespace llvm {
     /// elements remaining.  If \p N is greater than the length of the
     /// string, the entire string is returned.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef take_back(size_t N = 1) const {
       if (N >= size())
         return *this;
@@ -624,7 +603,6 @@ namespace llvm {
     /// Return the longest prefix of 'this' such that every character
     /// in the prefix satisfies the given predicate.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef take_while(function_ref<bool(char)> F) const {
       return substr(0, find_if_not(F));
     }
@@ -632,7 +610,6 @@ namespace llvm {
     /// Return the longest prefix of 'this' such that no character in
     /// the prefix satisfies the given predicate.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef take_until(function_ref<bool(char)> F) const {
       return substr(0, find_if(F));
     }
@@ -640,7 +617,6 @@ namespace llvm {
     /// Return a StringRef equal to 'this' but with the first \p N elements
     /// dropped.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef drop_front(size_t N = 1) const {
       assert(size() >= N && "Dropping more elements than exist");
       return substr(N);
@@ -649,7 +625,6 @@ namespace llvm {
     /// Return a StringRef equal to 'this' but with the last \p N elements
     /// dropped.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef drop_back(size_t N = 1) const {
       assert(size() >= N && "Dropping more elements than exist");
       return substr(0, size()-N);
@@ -658,7 +633,6 @@ namespace llvm {
     /// Return a StringRef equal to 'this', but with all characters satisfying
     /// the given predicate dropped from the beginning of the string.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef drop_while(function_ref<bool(char)> F) const {
       return substr(find_if_not(F));
     }
@@ -666,14 +640,12 @@ namespace llvm {
     /// Return a StringRef equal to 'this', but with all characters not
     /// satisfying the given predicate dropped from the beginning of the string.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef drop_until(function_ref<bool(char)> F) const {
       return substr(find_if(F));
     }
 
     /// Returns true if this StringRef has the given prefix and removes that
     /// prefix.
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool consume_front(StringRef Prefix) {
       if (!startswith(Prefix))
         return false;
@@ -684,7 +656,6 @@ namespace llvm {
 
     /// Returns true if this StringRef has the given suffix and removes that
     /// suffix.
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     bool consume_back(StringRef Suffix) {
       if (!endswith(Suffix))
         return false;
@@ -705,7 +676,6 @@ namespace llvm {
     /// will be returned. If this is less than \p Start, an empty string will
     /// be returned.
     LLVM_NODISCARD
-    LLVM_ATTRIBUTE_ALWAYS_INLINE
     StringRef slice(size_t Start, size_t End) const {
       Start = std::min(Start, Length);
       End = std::min(std::max(Start, End), Length);
@@ -893,12 +863,10 @@ namespace llvm {
   /// @name StringRef Comparison Operators
   /// @{
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   inline bool operator==(StringRef LHS, StringRef RHS) {
     return LHS.equals(RHS);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   inline bool operator!=(StringRef LHS, StringRef RHS) { return !(LHS == RHS); }
 
   inline bool operator<(StringRef LHS, StringRef RHS) {

Modified: llvm/trunk/include/llvm/ADT/StringSwitch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringSwitch.h?rev=351891&r1=351890&r2=351891&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringSwitch.h (original)
+++ llvm/trunk/include/llvm/ADT/StringSwitch.h Tue Jan 22 14:40:35 2019
@@ -48,7 +48,6 @@ class StringSwitch {
   Optional<T> Result;
 
 public:
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   explicit StringSwitch(StringRef S)
   : Str(S), Result() { }
 
@@ -65,7 +64,6 @@ public:
   ~StringSwitch() = default;
 
   // Case-sensitive case matchers
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Case(StringLiteral S, T Value) {
     if (!Result && Str == S) {
       Result = std::move(Value);
@@ -73,7 +71,6 @@ public:
     return *this;
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch& EndsWith(StringLiteral S, T Value) {
     if (!Result && Str.endswith(S)) {
       Result = std::move(Value);
@@ -81,7 +78,6 @@ public:
     return *this;
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch& StartsWith(StringLiteral S, T Value) {
     if (!Result && Str.startswith(S)) {
       Result = std::move(Value);
@@ -89,51 +85,43 @@ public:
     return *this;
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, T Value) {
     return Case(S0, Value).Case(S1, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       T Value) {
     return Case(S0, Value).Cases(S1, S2, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, T Value) {
     return Case(S0, Value).Cases(S1, S2, S3, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, T Value) {
     return Case(S0, Value).Cases(S1, S2, S3, S4, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, StringLiteral S5,
                       T Value) {
     return Case(S0, Value).Cases(S1, S2, S3, S4, S5, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, StringLiteral S5,
                       StringLiteral S6, T Value) {
     return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, StringLiteral S5,
                       StringLiteral S6, StringLiteral S7, T Value) {
     return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, S7, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, StringLiteral S5,
                       StringLiteral S6, StringLiteral S7, StringLiteral S8,
@@ -141,7 +129,6 @@ public:
     return Case(S0, Value).Cases(S1, S2, S3, S4, S5, S6, S7, S8, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, StringLiteral S5,
                       StringLiteral S6, StringLiteral S7, StringLiteral S8,
@@ -150,7 +137,6 @@ public:
   }
 
   // Case-insensitive case matchers.
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &CaseLower(StringLiteral S, T Value) {
     if (!Result && Str.equals_lower(S))
       Result = std::move(Value);
@@ -158,7 +144,6 @@ public:
     return *this;
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &EndsWithLower(StringLiteral S, T Value) {
     if (!Result && Str.endswith_lower(S))
       Result = Value;
@@ -166,7 +151,6 @@ public:
     return *this;
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &StartsWithLower(StringLiteral S, T Value) {
     if (!Result && Str.startswith_lower(S))
       Result = std::move(Value);
@@ -174,31 +158,26 @@ public:
     return *this;
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, T Value) {
     return CaseLower(S0, Value).CaseLower(S1, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                            T Value) {
     return CaseLower(S0, Value).CasesLower(S1, S2, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                            StringLiteral S3, T Value) {
     return CaseLower(S0, Value).CasesLower(S1, S2, S3, Value);
   }
 
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                            StringLiteral S3, StringLiteral S4, T Value) {
     return CaseLower(S0, Value).CasesLower(S1, S2, S3, S4, Value);
   }
 
   LLVM_NODISCARD
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   R Default(T Value) {
     if (Result)
       return std::move(*Result);
@@ -206,7 +185,6 @@ public:
   }
 
   LLVM_NODISCARD
-  LLVM_ATTRIBUTE_ALWAYS_INLINE
   operator R() {
     assert(Result && "Fell off the end of a string-switch");
     return std::move(*Result);




More information about the llvm-commits mailing list