[llvm] Add the 'initializes' attribute langref and support (PR #84803)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 15:30:12 PDT 2024


================
@@ -191,6 +192,35 @@ Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
   return Attribute(PA);
 }
 
+Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
+                         ArrayRef<ConstantRange> Val) {
+  assert(Attribute::isConstantRangeListAttrKind(Kind) &&
+         "Not a ConstantRangeList attribute");
+  LLVMContextImpl *pImpl = Context.pImpl;
+  FoldingSetNodeID ID;
+  ID.AddInteger(Kind);
+  ID.AddInteger(Val.size());
+  for (auto &CR : Val) {
+    CR.getLower().Profile(ID);
+    CR.getUpper().Profile(ID);
+  }
+
+  void *InsertPoint;
+  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
+
+  if (!PA) {
+    // If we didn't find any existing attributes of the same shape then create a
+    // new one and insert it.
+    PA = new (pImpl->ConstantRangeListAttributeAlloc.Allocate(
+        ConstantRangeListAttributeImpl::totalSizeToAlloc(Val)))
----------------
aeubanks wrote:

if we have a variable number of `ConstantRange`s in a `ConstantRangeListAttributeImpl` and they need a destructor, I don't see a nice way of using trailing objects and bump allocators. I think we should go back to `ConstantRangeListAttributeImpl` containing a `ConstantRangeList` and using `SpecificBumpPtrAllocator<ConstantRangeListAttributeImpl>` so that we allocate the right amount of memory and properly call the destructor. most of the time we'll be in the non-allocating version of the `SmallVector<ConstantRange>` anyway

https://github.com/llvm/llvm-project/pull/84803


More information about the llvm-commits mailing list