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(