Skip to content

Commit 8408ae8

Browse files
Use accessors for ValueHandleBase::V; NFC (microsoft#6660)
This PR pulls the upstream change, Use accessors for ValueHandleBase::V; NFC (llvm/llvm-project@6f08789), into DXC. Here's the summary of the change: > This changes code that touches ValueHandleBase::V to go through getValPtr and (newly added) setValPtr. This functionality will be used later, but also seemed like a generally good cleanup. > > I also renamed the field to Val, but that's just to make it obvious that I fixed all the uses. This is part 1 of the fix for microsoft#6659. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 978d362 commit 8408ae8

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

include/llvm/IR/ValueHandle.h

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,48 +56,56 @@ class ValueHandleBase {
5656
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
5757
ValueHandleBase *Next;
5858

59-
Value* V;
59+
Value *Val;
60+
61+
void setValPtr(Value *V) { Val = V; }
6062

6163
ValueHandleBase(const ValueHandleBase&) = delete;
6264
public:
6365
explicit ValueHandleBase(HandleBaseKind Kind)
64-
: PrevPair(nullptr, Kind), Next(nullptr), V(nullptr) {}
66+
: PrevPair(nullptr, Kind), Next(nullptr), Val(nullptr) {}
6567
ValueHandleBase(HandleBaseKind Kind, Value *V)
66-
: PrevPair(nullptr, Kind), Next(nullptr), V(V) {
67-
if (isValid(V))
68+
: PrevPair(nullptr, Kind), Next(nullptr), Val(V) {
69+
if (isValid(getValPtr()))
6870
AddToUseList();
6971
}
7072
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
71-
: PrevPair(nullptr, Kind), Next(nullptr), V(RHS.V) {
72-
if (isValid(V))
73+
: PrevPair(nullptr, Kind), Next(nullptr), Val(RHS.getValPtr()) {
74+
if (isValid(getValPtr()))
7375
AddToExistingUseList(RHS.getPrevPtr());
7476
}
7577
~ValueHandleBase() {
76-
if (isValid(V))
78+
if (isValid(getValPtr()))
7779
RemoveFromUseList();
7880
}
7981

8082
Value *operator=(Value *RHS) {
81-
if (V == RHS) return RHS;
82-
if (isValid(V)) RemoveFromUseList();
83-
V = RHS;
84-
if (isValid(V)) AddToUseList();
83+
if (getValPtr() == RHS)
84+
return RHS;
85+
if (isValid(getValPtr()))
86+
RemoveFromUseList();
87+
setValPtr(RHS);
88+
if (isValid(getValPtr()))
89+
AddToUseList();
8590
return RHS;
8691
}
8792

8893
Value *operator=(const ValueHandleBase &RHS) {
89-
if (V == RHS.V) return RHS.V;
90-
if (isValid(V)) RemoveFromUseList();
91-
V = RHS.V;
92-
if (isValid(V)) AddToExistingUseList(RHS.getPrevPtr());
93-
return V;
94+
if (getValPtr() == RHS.getValPtr())
95+
return RHS.getValPtr();
96+
if (isValid(getValPtr()))
97+
RemoveFromUseList();
98+
setValPtr(RHS.getValPtr());
99+
if (isValid(getValPtr()))
100+
AddToExistingUseList(RHS.getPrevPtr());
101+
return getValPtr();
94102
}
95103

96-
Value *operator->() const { return V; }
97-
Value &operator*() const { return *V; }
104+
Value *operator->() const { return getValPtr(); }
105+
Value &operator*() const { return *getValPtr(); }
98106

99107
protected:
100-
Value *getValPtr() const { return V; }
108+
Value *getValPtr() const { return Val; }
101109

102110
static bool isValid(Value *V) {
103111
return V &&

lib/IR/Value.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
559559
setPrevPtr(List);
560560
if (Next) {
561561
Next->setPrevPtr(&Next);
562-
assert(V == Next->V && "Added to wrong list?");
562+
assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
563563
}
564564
}
565565

@@ -574,14 +574,14 @@ void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
574574
}
575575

576576
void ValueHandleBase::AddToUseList() {
577-
assert(V && "Null pointer doesn't have a use list!");
577+
assert(getValPtr() && "Null pointer doesn't have a use list!");
578578

579-
LLVMContextImpl *pImpl = V->getContext().pImpl;
579+
LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
580580

581-
if (V->HasValueHandle) {
581+
if (getValPtr()->HasValueHandle) {
582582
// If this value already has a ValueHandle, then it must be in the
583583
// ValueHandles map already.
584-
ValueHandleBase *&Entry = pImpl->ValueHandles[V];
584+
ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
585585
assert(Entry && "Value doesn't have any handles?");
586586
AddToExistingUseList(&Entry);
587587
return;
@@ -595,10 +595,10 @@ void ValueHandleBase::AddToUseList() {
595595
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
596596
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
597597

598-
ValueHandleBase *&Entry = Handles[V];
598+
ValueHandleBase *&Entry = Handles[getValPtr()];
599599
assert(!Entry && "Value really did already have handles?");
600600
AddToExistingUseList(&Entry);
601-
V->HasValueHandle = true;
601+
getValPtr()->HasValueHandle = true;
602602

603603
// If reallocation didn't happen or if this was the first insertion, don't
604604
// walk the table.
@@ -610,16 +610,19 @@ void ValueHandleBase::AddToUseList() {
610610
// Okay, reallocation did happen. Fix the Prev Pointers.
611611
for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
612612
E = Handles.end(); I != E; ++I) {
613-
assert(I->second && I->first == I->second->V &&
613+
assert(I->second && I->first == I->second->getValPtr() &&
614614
"List invariant broken!");
615615
I->second->setPrevPtr(&I->second);
616616
}
617617
}
618618

619619
void ValueHandleBase::RemoveFromUseList() {
620-
assert(V && (std::current_exception() == nullptr || V->HasValueHandle) && // HLSL Change
620+
assert(getValPtr() &&
621+
(std::current_exception() == nullptr ||
622+
getValPtr()->HasValueHandle) && // HLSL Change
621623
"Pointer doesn't have a use list!");
622-
if (!V->HasValueHandle) return; // HLSL Change
624+
if (!getValPtr()->HasValueHandle)
625+
return; // HLSL Change
623626
// Unlink this from its use list.
624627
ValueHandleBase **PrevPtr = getPrevPtr();
625628
assert(*PrevPtr == this && "List invariant broken");
@@ -634,11 +637,11 @@ void ValueHandleBase::RemoveFromUseList() {
634637
// If the Next pointer was null, then it is possible that this was the last
635638
// ValueHandle watching VP. If so, delete its entry from the ValueHandles
636639
// map.
637-
LLVMContextImpl *pImpl = V->getContext().pImpl;
640+
LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
638641
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
639642
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
640-
Handles.erase(V);
641-
V->HasValueHandle = false;
643+
Handles.erase(getValPtr());
644+
getValPtr()->HasValueHandle = false;
642645
}
643646
}
644647

0 commit comments

Comments
 (0)