[PATCH] D114394: Compile-time computation of string attribute hashes

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 23 19:27:47 PST 2021


MaskRay added inline comments.


================
Comment at: llvm/lib/IR/AttributeImpl.h:214
 
-  DenseMap<StringRef, Attribute> StringAttrs;
+  std::unordered_map<AttributeKey, Attribute> StringAttrs;
 
----------------
std::unordered_map is inefficient. Why is this change?


================
Comment at: llvm/lib/IR/Attributes.cpp:862
+  auto Where = StringAttrs.find(Kind);
+  return Where != StringAttrs.end() ? Where->second : Attribute();
 }
----------------
`lookup`


================
Comment at: llvm/lib/IR/Attributes.cpp:2054
+  auto &AttributeKeys = pImpl->AttributeKeys;
+  auto Where = AttributeKeys.find(s);
+  if (Where == AttributeKeys.end()) {
----------------
If you change `AttributeKeys` to `DenseMap<CachedHashStringRef, ...>`, you can construct a `CachedHashStringRef` and avoid a hash computation in `AttributeKey Key(s);`


================
Comment at: llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:1531
 static StringRef getDeoptLowering(CallBase *Call) {
-  const char *DeoptLowering = "deopt-lowering";
+  const char DeoptLowering[] = "deopt-lowering";
   if (Call->hasFnAttr(DeoptLowering)) {
----------------
This can be committed separately.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114394/new/

https://reviews.llvm.org/D114394



More information about the cfe-commits mailing list