Skip to content

Commit

Permalink
Rename WeakVH to WeakTrackingVH; NFC
Browse files Browse the repository at this point in the history
This relands r301424.

llvm-svn: 301812
  • Loading branch information
sanjoy committed May 1, 2017
1 parent 2fa3604 commit e6bca0e
Show file tree
Hide file tree
Showing 40 changed files with 201 additions and 207 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/AliasSetTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ class AliasSet : public ilist_node<AliasSet> {
AliasSet *Forward;

/// All instructions without a specific address in this alias set.
/// In rare cases this vector can have a null'ed out WeakVH
/// In rare cases this vector can have a null'ed out WeakTrackingVH
/// instances (can happen if some other loop pass deletes an
/// instruction in this list).
std::vector<WeakVH> UnknownInsts;
std::vector<WeakTrackingVH> UnknownInsts;

/// Number of nodes pointing to this AliasSet plus the number of AliasSets
/// forwarding to it.
Expand Down
14 changes: 7 additions & 7 deletions llvm/include/llvm/Analysis/AssumptionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AssumptionCache {

/// \brief Vector of weak value handles to calls of the @llvm.assume
/// intrinsic.
SmallVector<WeakVH, 4> AssumeHandles;
SmallVector<WeakTrackingVH, 4> AssumeHandles;

class AffectedValueCallbackVH final : public CallbackVH {
AssumptionCache *AC;
Expand All @@ -62,12 +62,12 @@ class AssumptionCache {
/// \brief A map of values about which an assumption might be providing
/// information to the relevant set of assumptions.
using AffectedValuesMap =
DenseMap<AffectedValueCallbackVH, SmallVector<WeakVH, 1>,
AffectedValueCallbackVH::DMI>;
DenseMap<AffectedValueCallbackVH, SmallVector<WeakTrackingVH, 1>,
AffectedValueCallbackVH::DMI>;
AffectedValuesMap AffectedValues;

/// Get the vector of assumptions which affect a value from the cache.
SmallVector<WeakVH, 1> &getOrInsertAffectedValues(Value *V);
SmallVector<WeakTrackingVH, 1> &getOrInsertAffectedValues(Value *V);

/// Copy affected values in the cache for OV to be affected values for NV.
void copyAffectedValuesInCache(Value *OV, Value *NV);
Expand Down Expand Up @@ -120,20 +120,20 @@ class AssumptionCache {
/// FIXME: We should replace this with pointee_iterator<filter_iterator<...>>
/// when we can write that to filter out the null values. Then caller code
/// will become simpler.
MutableArrayRef<WeakVH> assumptions() {
MutableArrayRef<WeakTrackingVH> assumptions() {
if (!Scanned)
scanFunction();
return AssumeHandles;
}

/// \brief Access the list of assumptions which affect this value.
MutableArrayRef<WeakVH> assumptionsFor(const Value *V) {
MutableArrayRef<WeakTrackingVH> assumptionsFor(const Value *V) {
if (!Scanned)
scanFunction();

auto AVI = AffectedValues.find_as(const_cast<Value *>(V));
if (AVI == AffectedValues.end())
return MutableArrayRef<WeakVH>();
return MutableArrayRef<WeakTrackingVH>();

return AVI->second;
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/include/llvm/Analysis/CGSCCPassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ class DevirtSCCRepeatedPass
LazyCallGraph::SCC *C = &InitialC;

// Collect value handles for all of the indirect call sites.
SmallVector<WeakVH, 8> CallHandles;
SmallVector<WeakTrackingVH, 8> CallHandles;

// Struct to track the counts of direct and indirect calls in each function
// of the SCC.
Expand All @@ -658,7 +658,7 @@ class DevirtSCCRepeatedPass
// Put value handles on all of the indirect calls and return the number of
// direct calls for each function in the SCC.
auto ScanSCC = [](LazyCallGraph::SCC &C,
SmallVectorImpl<WeakVH> &CallHandles) {
SmallVectorImpl<WeakTrackingVH> &CallHandles) {
assert(CallHandles.empty() && "Must start with a clear set of handles.");

SmallVector<CallCount, 4> CallCounts;
Expand All @@ -671,7 +671,7 @@ class DevirtSCCRepeatedPass
++Count.Direct;
} else {
++Count.Indirect;
CallHandles.push_back(WeakVH(&I));
CallHandles.push_back(WeakTrackingVH(&I));
}
}
}
Expand Down Expand Up @@ -699,7 +699,7 @@ class DevirtSCCRepeatedPass
"Cannot have changed the size of the SCC!");

// Check whether any of the handles were devirtualized.
auto IsDevirtualizedHandle = [&](WeakVH &CallH) {
auto IsDevirtualizedHandle = [&](WeakTrackingVH &CallH) {
if (!CallH)
return false;
auto CS = CallSite(CallH);
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class CallGraphNode {
public:
/// \brief A pair of the calling instruction (a call or invoke)
/// and the call graph node being called.
typedef std::pair<WeakVH, CallGraphNode *> CallRecord;
typedef std::pair<WeakTrackingVH, CallGraphNode *> CallRecord;

public:
typedef std::vector<CallRecord> CalledFunctionsVector;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/IVUsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class IVStrideUse final : public CallbackVH, public ilist_node<IVStrideUse> {

/// OperandValToReplace - The Value of the operand in the user instruction
/// that this IVStrideUse is representing.
WeakVH OperandValToReplace;
WeakTrackingVH OperandValToReplace;

/// PostIncLoops - The set of loops for which Expr has been adjusted to
/// use post-inc mode. This corresponds with SCEVExpander's post-inc concept.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/MemoryBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class ObjectSizeOffsetEvaluator
: public InstVisitor<ObjectSizeOffsetEvaluator, SizeOffsetEvalType> {

typedef IRBuilder<TargetFolder> BuilderTy;
typedef std::pair<WeakVH, WeakVH> WeakEvalType;
typedef std::pair<WeakTrackingVH, WeakTrackingVH> WeakEvalType;
typedef DenseMap<const Value*, WeakEvalType> CacheMapTy;
typedef SmallPtrSet<const Value*, 8> PtrSetTy;

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/ScalarEvolutionExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace llvm {
/// replace congruent phis with their most canonical representative. Return
/// the number of phis eliminated.
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakVH> &DeadInsts,
SmallVectorImpl<WeakTrackingVH> &DeadInsts,
const TargetTransformInfo *TTI = nullptr);

/// Insert code to directly compute the specified SCEV expression into the
Expand Down
38 changes: 19 additions & 19 deletions llvm/include/llvm/IR/ValueHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ class ValueHandleBase {
///
/// This is to avoid having a vtable for the light-weight handle pointers. The
/// fully general Callback version does have a vtable.
enum HandleBaseKind {
Assert,
Callback,
Weak
};
enum HandleBaseKind { Assert, Callback, WeakTracking };

ValueHandleBase(const ValueHandleBase &RHS)
: ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
Expand Down Expand Up @@ -145,14 +141,14 @@ class ValueHandleBase {
/// is useful for advisory sorts of information, but should not be used as the
/// key of a map (since the map would have to rearrange itself when the pointer
/// changes).
class WeakVH : public ValueHandleBase {
class WeakTrackingVH : public ValueHandleBase {
public:
WeakVH() : ValueHandleBase(Weak) {}
WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
WeakVH(const WeakVH &RHS)
: ValueHandleBase(Weak, RHS) {}
WeakTrackingVH() : ValueHandleBase(WeakTracking) {}
WeakTrackingVH(Value *P) : ValueHandleBase(WeakTracking, P) {}
WeakTrackingVH(const WeakTrackingVH &RHS)
: ValueHandleBase(WeakTracking, RHS) {}

WeakVH &operator=(const WeakVH &RHS) = default;
WeakTrackingVH &operator=(const WeakTrackingVH &RHS) = default;

Value *operator=(Value *RHS) {
return ValueHandleBase::operator=(RHS);
Expand All @@ -170,15 +166,17 @@ class WeakVH : public ValueHandleBase {
}
};

// Specialize simplify_type to allow WeakVH to participate in
// Specialize simplify_type to allow WeakTrackingVH to participate in
// dyn_cast, isa, etc.
template <> struct simplify_type<WeakVH> {
template <> struct simplify_type<WeakTrackingVH> {
typedef Value *SimpleType;
static SimpleType getSimplifiedValue(WeakVH &WVH) { return WVH; }
static SimpleType getSimplifiedValue(WeakTrackingVH &WVH) { return WVH; }
};
template <> struct simplify_type<const WeakVH> {
template <> struct simplify_type<const WeakTrackingVH> {
typedef Value *SimpleType;
static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
static SimpleType getSimplifiedValue(const WeakTrackingVH &WVH) {
return WVH;
}
};

/// \brief Value handle that asserts if the Value is deleted.
Expand Down Expand Up @@ -294,7 +292,7 @@ struct isPodLike<AssertingVH<T> > {
/// Assigning a value to a TrackingVH is always allowed, even if said TrackingVH
/// no longer points to a valid value.
template <typename ValueTy> class TrackingVH {
WeakVH InnerHandle;
WeakTrackingVH InnerHandle;

public:
ValueTy *getValPtr() const {
Expand Down Expand Up @@ -368,7 +366,8 @@ class CallbackVH : public ValueHandleBase {
///
/// Called when this->getValPtr() is destroyed, inside ~Value(), so you
/// may call any non-virtual Value method on getValPtr(), but no subclass
/// methods. If WeakVH were implemented as a CallbackVH, it would use this
/// methods. If WeakTrackingVH were implemented as a CallbackVH, it would use
/// this
/// method to call setValPtr(NULL). AssertingVH would use this method to
/// cause an assertion failure.
///
Expand All @@ -379,7 +378,8 @@ class CallbackVH : public ValueHandleBase {
/// \brief Callback for Value RAUW.
///
/// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
/// _before_ any of the uses have actually been replaced. If WeakVH were
/// _before_ any of the uses have actually been replaced. If WeakTrackingVH
/// were
/// implemented as a CallbackVH, it would use this method to call
/// setValPtr(new_value). AssertingVH would do nothing in this method.
virtual void allUsesReplacedWith(Value *) {}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Scalar/NaryReassociate.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class NaryReassociatePass : public PassInfoMixin<NaryReassociatePass> {
// foo(a + b);
// if (p2)
// bar(a + b);
DenseMap<const SCEV *, SmallVector<WeakVH, 2>> SeenExprs;
DenseMap<const SCEV *, SmallVector<WeakTrackingVH, 2>> SeenExprs;
};
} // namespace llvm

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Utils/Cloning.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct ClonedCodeInfo {
/// All cloned call sites that have operand bundles attached are appended to
/// this vector. This vector may contain nulls or undefs if some of the
/// originally inserted callsites were DCE'ed after they were cloned.
std::vector<WeakVH> OperandBundleCallSites;
std::vector<WeakTrackingVH> OperandBundleCallSites;

ClonedCodeInfo() = default;
};
Expand Down Expand Up @@ -192,7 +192,7 @@ class InlineFunctionInfo {

/// InlinedCalls - InlineFunction fills this in with callsites that were
/// inlined from the callee. This is only filled in if CG is non-null.
SmallVector<WeakVH, 8> InlinedCalls;
SmallVector<WeakTrackingVH, 8> InlinedCalls;

/// All of the new call sites inlined into the caller.
///
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Utils/SimplifyIndVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class IVVisitor {
/// simplifyUsersOfIV - Simplify instructions that use this induction variable
/// by using ScalarEvolution to analyze the IV's recurrence.
bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT,
LoopInfo *LI, SmallVectorImpl<WeakVH> &Dead,
LoopInfo *LI, SmallVectorImpl<WeakTrackingVH> &Dead,
IVVisitor *V = nullptr);

/// SimplifyLoopIVs - Simplify users of induction variables within this
/// loop. This does not actually change or add IVs.
bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
LoopInfo *LI, SmallVectorImpl<WeakVH> &Dead);
LoopInfo *LI, SmallVectorImpl<WeakTrackingVH> &Dead);

} // end namespace llvm

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils/ValueMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace llvm {

class Value;
class Instruction;
typedef ValueMap<const Value *, WeakVH> ValueToValueMapTy;
typedef ValueMap<const Value *, WeakTrackingVH> ValueToValueMapTy;

/// This is a class that can be implemented by clients to remap types when
/// cloning constants and instructions.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class BoUpSLP;
struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
typedef SmallVector<StoreInst *, 8> StoreList;
typedef MapVector<Value *, StoreList> StoreListMap;
typedef SmallVector<WeakVH, 8> WeakVHList;
typedef MapVector<Value *, WeakVHList> WeakVHListMap;
typedef SmallVector<WeakTrackingVH, 8> WeakTrackingVHList;
typedef MapVector<Value *, WeakTrackingVHList> WeakTrackingVHListMap;

ScalarEvolution *SE = nullptr;
TargetTransformInfo *TTI = nullptr;
Expand Down Expand Up @@ -111,7 +111,7 @@ struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
StoreListMap Stores;

/// The getelementptr instructions in a basic block organized by base pointer.
WeakVHListMap GEPs;
WeakTrackingVHListMap GEPs;
};
}

Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Analysis/AssumptionCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ static cl::opt<bool>
cl::desc("Enable verification of assumption cache"),
cl::init(false));

SmallVector<WeakVH, 1> &AssumptionCache::getOrInsertAffectedValues(Value *V) {
SmallVector<WeakTrackingVH, 1> &
AssumptionCache::getOrInsertAffectedValues(Value *V) {
// Try using find_as first to avoid creating extra value handles just for the
// purpose of doing the lookup.
auto AVI = AffectedValues.find_as(V);
if (AVI != AffectedValues.end())
return AVI->second;

auto AVIP = AffectedValues.insert({
AffectedValueCallbackVH(V, this), SmallVector<WeakVH, 1>()});
auto AVIP = AffectedValues.insert(
{AffectedValueCallbackVH(V, this), SmallVector<WeakTrackingVH, 1>()});
return AVIP.first->second;
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Analysis/CallGraphSCCPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,
// Get the set of call sites currently in the function.
for (CallGraphNode::iterator I = CGN->begin(), E = CGN->end(); I != E; ) {
// If this call site is null, then the function pass deleted the call
// entirely and the WeakVH nulled it out.
// entirely and the WeakTrackingVH nulled it out.
if (!I->first ||
// If we've already seen this call site, then the FunctionPass RAUW'd
// one call with another, which resulted in two "uses" in the edge
Expand Down Expand Up @@ -347,7 +347,8 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,
DevirtualizedCall = true;

// After scanning this function, if we still have entries in callsites, then
// they are dangling pointers. WeakVH should save us for this, so abort if
// they are dangling pointers. WeakTrackingVH should save us for this, so
// abort if
// this happens.
assert(CallSites.empty() && "Dangling pointers found in call sites map");

Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Analysis/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,9 +1772,10 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L,
///
/// This does not depend on any SCEVExpander state but should be used in
/// the same context that SCEVExpander is used.
unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakVH> &DeadInsts,
const TargetTransformInfo *TTI) {
unsigned
SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakTrackingVH> &DeadInsts,
const TargetTransformInfo *TTI) {
// Find integer phis in order of increasing width.
SmallVector<PHINode*, 8> Phis;
for (auto &I : *L->getHeader()) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Reader/ValueList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void BitcodeReaderValueList::assignValue(Value *V, unsigned Idx) {
if (Idx >= size())
resize(Idx + 1);

WeakVH &OldV = ValuePtrs[Idx];
WeakTrackingVH &OldV = ValuePtrs[Idx];
if (!OldV) {
OldV = V;
return;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Reader/ValueList.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace llvm {
class Constant;

class BitcodeReaderValueList {
std::vector<WeakVH> ValuePtrs;
std::vector<WeakTrackingVH> ValuePtrs;

/// As we resolve forward-referenced constants, we add information about them
/// to this vector. This allows us to resolve them in bulk instead of
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,10 +2226,11 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool& ModifiedDT) {
ConstantInt *RetVal =
lowerObjectSizeCall(II, *DL, TLInfo, /*MustSucceed=*/true);
// Substituting this can cause recursive simplifications, which can
// invalidate our iterator. Use a WeakVH to hold onto it in case this
// invalidate our iterator. Use a WeakTrackingVH to hold onto it in case
// this
// happens.
Value *CurValue = &*CurInstIterator;
WeakVH IterHandle(CurValue);
WeakTrackingVH IterHandle(CurValue);

replaceAndRecursivelySimplify(CI, RetVal, TLInfo, nullptr);

Expand Down Expand Up @@ -4442,9 +4443,9 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
// using it.
if (Repl->use_empty()) {
// This can cause recursive deletion, which can invalidate our iterator.
// Use a WeakVH to hold onto it in case this happens.
// Use a WeakTrackingVH to hold onto it in case this happens.
Value *CurValue = &*CurInstIterator;
WeakVH IterHandle(CurValue);
WeakTrackingVH IterHandle(CurValue);
BasicBlock *BB = CurInstIterator->getParent();

RecursivelyDeleteTriviallyDeadInstructions(Repl, TLInfo);
Expand Down
Loading

0 comments on commit e6bca0e

Please sign in to comment.