[PATCH] D98190: [NFC] Use SmallString instead of std::string for the AttrBuilder

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 8 08:53:01 PST 2021


serge-sans-paille created this revision.
serge-sans-paille added reviewers: bkramer, void.
Herald added subscribers: dexonsmith, jdoerfert, hiraditya.
serge-sans-paille requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This avoids a few unnecessary conversion from StringRef to std::string, and a 
bunch of extra allocation thanks to the SmallString.


https://reviews.llvm.org/D98190

Files:
  llvm/include/llvm/IR/Attributes.h
  llvm/lib/IR/Attributes.cpp


Index: llvm/lib/IR/Attributes.cpp
===================================================================
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -1624,7 +1624,7 @@
 }
 
 AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) {
-  TargetDepAttrs[std::string(A)] = std::string(V);
+  TargetDepAttrs[A] = V;
   return *this;
 }
 
Index: llvm/include/llvm/IR/Attributes.h
===================================================================
--- llvm/include/llvm/IR/Attributes.h
+++ llvm/include/llvm/IR/Attributes.h
@@ -18,6 +18,7 @@
 #include "llvm-c/Types.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Config/llvm-config.h"
@@ -756,7 +757,7 @@
 /// equality, presence of attributes, etc.
 class AttrBuilder {
   std::bitset<Attribute::EndAttrKinds> Attrs;
-  std::map<std::string, std::string, std::less<>> TargetDepAttrs;
+  std::map<SmallString<32>, SmallString<32>, std::less<>> TargetDepAttrs;
   MaybeAlign Alignment;
   MaybeAlign StackAlignment;
   uint64_t DerefBytes = 0;
@@ -921,7 +922,7 @@
   bool empty() const { return Attrs.none(); }
 
   // Iterators for target-dependent attributes.
-  using td_type = std::pair<std::string, std::string>;
+  using td_type = decltype(TargetDepAttrs)::value_type;
   using td_iterator = decltype(TargetDepAttrs)::iterator;
   using td_const_iterator = decltype(TargetDepAttrs)::const_iterator;
   using td_range = iterator_range<td_iterator>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98190.329038.patch
Type: text/x-patch
Size: 1564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210308/ce3eb5e5/attachment.bin>


More information about the llvm-commits mailing list