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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 07:38:19 PDT 2024


================
@@ -191,6 +192,44 @@ 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());
+  ID.AddInteger(Val[0].getBitWidth());
+  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.
+    // ConstantRange is a dynamically sized class and cannot use
+    // SpecificBumpPtrAllocator. Instead, we use normal Alloc for allocation
+    // for allocation and record the allocated pointer in
+    // `ConstantRangeListAttributes`. LLVMContext destructor will call the
+    // destuctor of the allocated pointer explicitly.
----------------
nikic wrote:

```suggestion
    // destructor of the allocated pointer explicitly.
```

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


More information about the llvm-commits mailing list