[llvm-branch-commits] [llvm] Reapply "IR: Remove reference counts from ConstantData (#137314)" (PR #138962)

2025-05-07 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

### Merge activity

* **May 8, 1:53 AM EDT**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/138962).


https://github.com/llvm/llvm-project/pull/138962
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Reapply "IR: Remove reference counts from ConstantData (#137314)" (PR #138962)

2025-05-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/138962
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Reapply "IR: Remove reference counts from ConstantData (#137314)" (PR #138962)

2025-05-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)


Changes

This reverts commit 0274232b8719e5c985eca06df22bf140f6cb.

---
Full diff: https://github.com/llvm/llvm-project/pull/138962.diff


9 Files Affected:

- (modified) llvm/docs/ReleaseNotes.md (+3-1) 
- (modified) llvm/include/llvm/IR/Constants.h (+2-1) 
- (modified) llvm/include/llvm/IR/Use.h (+20-6) 
- (modified) llvm/include/llvm/IR/Value.h (+20-78) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+1-2) 
- (modified) llvm/lib/IR/Instruction.cpp (+1-3) 
- (modified) llvm/lib/IR/Value.cpp (+17-13) 
- (modified) llvm/unittests/IR/ConstantsTest.cpp (+38) 


``diff
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 504db733308c1..05318362b99c9 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -56,7 +56,9 @@ Makes programs 10x faster by doing Special New Thing.
 Changes to the LLVM IR
 --
 
-* It is no longer permitted to inspect the uses of ConstantData
+* It is no longer permitted to inspect the uses of ConstantData. Use
+  count APIs will behave as if they have no uses (i.e. use_empty() is
+  always true).
 
 * The `nocapture` attribute has been replaced by `captures(none)`.
 * The constant expression variants of the following instructions have been
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index ff51f59b6ec68..76efa9bd63522 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -51,7 +51,8 @@ template  struct ConstantAggrKeyType;
 /// Since they can be in use by unrelated modules (and are never based on
 /// GlobalValues), it never makes sense to RAUW them.
 ///
-/// These do not have use lists. It is illegal to inspect the uses.
+/// These do not have use lists. It is illegal to inspect the uses. These 
behave
+/// as if they have no uses (i.e. use_empty() is always true).
 class ConstantData : public Constant {
   constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
 
diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h
index bcd1fd6677497..0d5d878e4689f 100644
--- a/llvm/include/llvm/IR/Use.h
+++ b/llvm/include/llvm/IR/Use.h
@@ -23,7 +23,6 @@
 namespace llvm {
 
 template  struct simplify_type;
-class ConstantData;
 class User;
 class Value;
 
@@ -43,7 +42,7 @@ class Use {
 
 private:
   /// Destructor - Only for zap()
-  ~Use();
+  ~Use() { removeFromList(); }
 
   /// Constructor
   Use(User *Parent) : Parent(Parent) {}
@@ -85,10 +84,25 @@ class Use {
   Use **Prev = nullptr;
   User *Parent = nullptr;
 
-  inline void addToList(unsigned &Count);
-  inline void addToList(Use *&List);
-  inline void removeFromList(unsigned &Count);
-  inline void removeFromList(Use *&List);
+  void addToList(Use **List) {
+Next = *List;
+if (Next)
+  Next->Prev = &Next;
+Prev = List;
+*Prev = this;
+  }
+
+  void removeFromList() {
+if (Prev) {
+  *Prev = Next;
+  if (Next) {
+Next->Prev = Prev;
+Next = nullptr;
+  }
+
+  Prev = nullptr;
+}
+  }
 };
 
 /// Allow clients to treat uses just like values when using
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index 180b6238eda6c..241b9e2860c4c 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -116,10 +116,7 @@ class Value {
 
 private:
   Type *VTy;
-  union {
-Use *List = nullptr;
-unsigned Count;
-  } Uses;
+  Use *UseList = nullptr;
 
   friend class ValueAsMetadata; // Allow access to IsUsedByMD.
   friend class ValueHandleBase; // Allow access to HasValueHandle.
@@ -347,23 +344,21 @@ class Value {
 
   bool use_empty() const {
 assertModuleIsMaterialized();
-return hasUseList() ? Uses.List == nullptr : Uses.Count == 0;
+return UseList == nullptr;
   }
 
-  bool materialized_use_empty() const {
-return hasUseList() ? Uses.List == nullptr : !Uses.Count;
-  }
+  bool materialized_use_empty() const { return UseList == nullptr; }
 
   using use_iterator = use_iterator_impl;
   using const_use_iterator = use_iterator_impl;
 
   use_iterator materialized_use_begin() {
 assert(hasUseList());
-return use_iterator(Uses.List);
+return use_iterator(UseList);
   }
   const_use_iterator materialized_use_begin() const {
 assert(hasUseList());
-return const_use_iterator(Uses.List);
+return const_use_iterator(UseList);
   }
   use_iterator use_begin() {
 assertModuleIsMaterialized();
@@ -397,11 +392,11 @@ class Value {
 
   user_iterator materialized_user_begin() {
 assert(hasUseList());
-return user_iterator(Uses.List);
+return user_iterator(UseList);
   }
   const_user_iterator materialized_user_begin() const {
 assert(hasUseList());
-return const_user_iterator(Uses.List);
+return const_user_iterator(UseList);
   }
   user_iterator user_begin() {
 assertModuleIsMaterialized(

[llvm-branch-commits] [llvm] Reapply "IR: Remove reference counts from ConstantData (#137314)" (PR #138962)

2025-05-07 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/138962?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#138962** https://app.graphite.dev/github/pr/llvm/llvm-project/138962?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> ๐Ÿ‘ˆ https://app.graphite.dev/github/pr/llvm/llvm-project/138962?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#138961** https://app.graphite.dev/github/pr/llvm/llvm-project/138961?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#138960** https://app.graphite.dev/github/pr/llvm/llvm-project/138960?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/138962
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Reapply "IR: Remove reference counts from ConstantData (#137314)" (PR #138962)

2025-05-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/138962

This reverts commit 0274232b8719e5c985eca06df22bf140f6cb.



  



Rate limit ยท GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support โ€”
https://githubstatus.com";>GitHub Status โ€”
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits