Skip to content

Commit

Permalink
Reverts commit r301424, r301425 and r301426
Browse files Browse the repository at this point in the history
Commits were:

"Use WeakVH instead of WeakTrackingVH in AliasSetTracker's UnkownInsts"
"Add a new WeakVH value handle; NFC"
"Rename WeakVH to WeakTrackingVH; NFC"

The changes assumed pointers are 8 byte aligned on all architectures.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301429 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
sanjoy committed Apr 26, 2017
1 parent 8619795 commit 263da12
Show file tree
Hide file tree
Showing 40 changed files with 207 additions and 276 deletions.
6 changes: 3 additions & 3 deletions docs/ProgrammersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2156,9 +2156,9 @@ llvm/IR/ValueMap.h
ValueMap is a wrapper around a :ref:`DenseMap <dss_densemap>` mapping
``Value*``\ s (or subclasses) to another type. When a Value is deleted or
RAUW'ed, ValueMap will update itself so the new version of the key is mapped to
the same value, just as if the key were a WeakTrackingVH. You can configure
exactly how this happens, and what else happens on these two events, by passing
a ``Config`` parameter to the ValueMap template.
the same value, just as if the key were a WeakVH. You can configure exactly how
this happens, and what else happens on these two events, by passing a ``Config``
parameter to the ValueMap template.

.. _dss_intervalmap:

Expand Down
14 changes: 7 additions & 7 deletions 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<WeakTrackingVH, 4> AssumeHandles;
SmallVector<WeakVH, 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<WeakTrackingVH, 1>,
AffectedValueCallbackVH::DMI>;
DenseMap<AffectedValueCallbackVH, SmallVector<WeakVH, 1>,
AffectedValueCallbackVH::DMI>;
AffectedValuesMap AffectedValues;

/// Get the vector of assumptions which affect a value from the cache.
SmallVector<WeakTrackingVH, 1> &getOrInsertAffectedValues(Value *V);
SmallVector<WeakVH, 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<WeakTrackingVH> assumptions() {
MutableArrayRef<WeakVH> assumptions() {
if (!Scanned)
scanFunction();
return AssumeHandles;
}

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

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

return AVI->second;
}
Expand Down
8 changes: 4 additions & 4 deletions 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<WeakTrackingVH, 8> CallHandles;
SmallVector<WeakVH, 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<WeakTrackingVH> &CallHandles) {
SmallVectorImpl<WeakVH> &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(WeakTrackingVH(&I));
CallHandles.push_back(WeakVH(&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 = [&](WeakTrackingVH &CallH) {
auto IsDevirtualizedHandle = [&](WeakVH &CallH) {
if (!CallH)
return false;
auto CS = CallSite(CallH);
Expand Down
2 changes: 1 addition & 1 deletion 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<WeakTrackingVH, CallGraphNode *> CallRecord;
typedef std::pair<WeakVH, CallGraphNode *> CallRecord;

public:
typedef std::vector<CallRecord> CalledFunctionsVector;
Expand Down
2 changes: 1 addition & 1 deletion 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.
WeakTrackingVH OperandValToReplace;
WeakVH 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 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<WeakTrackingVH, WeakTrackingVH> WeakEvalType;
typedef std::pair<WeakVH, WeakVH> WeakEvalType;
typedef DenseMap<const Value*, WeakEvalType> CacheMapTy;
typedef SmallPtrSet<const Value*, 8> PtrSetTy;

Expand Down
2 changes: 1 addition & 1 deletion 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<WeakTrackingVH> &DeadInsts,
SmallVectorImpl<WeakVH> &DeadInsts,
const TargetTransformInfo *TTI = nullptr);

/// Insert code to directly compute the specified SCEV expression into the
Expand Down
69 changes: 18 additions & 51 deletions include/llvm/IR/ValueHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ 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, Tracking, Weak, WeakTracking };
enum HandleBaseKind {
Assert,
Callback,
Tracking,
Weak
};

ValueHandleBase(const ValueHandleBase &RHS)
: ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
Expand All @@ -46,7 +51,7 @@ class ValueHandleBase {
}

private:
PointerIntPair<ValueHandleBase**, 3, HandleBaseKind> PrevPair;
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
ValueHandleBase *Next;

Value* V;
Expand Down Expand Up @@ -126,16 +131,19 @@ class ValueHandleBase {
void AddToUseList();
};

/// \brief A nullable Value handle that is nullable.
/// \brief Value handle that is nullable, but tries to track the Value.
///
/// This is a value handle that points to a value, and nulls itself
/// out if that value is deleted.
/// This is a value handle that tries hard to point to a Value, even across
/// RAUW operations, but will null itself out if the value is destroyed. this
/// 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 {
public:
WeakVH() : ValueHandleBase(Weak) {}
WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
WeakVH(const WeakVH &RHS)
: ValueHandleBase(Weak, RHS) {}
: ValueHandleBase(Weak, RHS) {}

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

Expand All @@ -162,47 +170,6 @@ template <> struct simplify_type<const WeakVH> {
static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
};

/// \brief Value handle that is nullable, but tries to track the Value.
///
/// This is a value handle that tries hard to point to a Value, even across
/// RAUW operations, but will null itself out if the value is destroyed. this
/// 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 WeakTrackingVH : public ValueHandleBase {
public:
WeakTrackingVH() : ValueHandleBase(WeakTracking) {}
WeakTrackingVH(Value *P) : ValueHandleBase(WeakTracking, P) {}
WeakTrackingVH(const WeakTrackingVH &RHS)
: ValueHandleBase(WeakTracking, RHS) {}

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

Value *operator=(Value *RHS) {
return ValueHandleBase::operator=(RHS);
}
Value *operator=(const ValueHandleBase &RHS) {
return ValueHandleBase::operator=(RHS);
}

operator Value*() const {
return getValPtr();
}
};

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

/// \brief Value handle that asserts if the Value is deleted.
///
/// This is a Value Handle that points to a value and asserts out if the value
Expand Down Expand Up @@ -392,8 +359,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 WeakTrackingVH were implemented as a CallbackVH, it would use
/// this method to call setValPtr(NULL). AssertingVH would use this method to
/// methods. If WeakVH were implemented as a CallbackVH, it would use this
/// method to call setValPtr(NULL). AssertingVH would use this method to
/// cause an assertion failure.
///
/// All implementations must remove the reference from this object to the
Expand All @@ -403,8 +370,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 WeakTrackingVH
/// were implemented as a CallbackVH, it would use this method to call
/// _before_ any of the uses have actually been replaced. If WeakVH 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 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<WeakTrackingVH, 2>> SeenExprs;
DenseMap<const SCEV *, SmallVector<WeakVH, 2>> SeenExprs;
};
} // namespace llvm

Expand Down
4 changes: 2 additions & 2 deletions 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<WeakTrackingVH> OperandBundleCallSites;
std::vector<WeakVH> 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<WeakTrackingVH, 8> InlinedCalls;
SmallVector<WeakVH, 8> InlinedCalls;

/// All of the new call sites inlined into the caller.
///
Expand Down
4 changes: 2 additions & 2 deletions 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<WeakTrackingVH> &Dead,
LoopInfo *LI, SmallVectorImpl<WeakVH> &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<WeakTrackingVH> &Dead);
LoopInfo *LI, SmallVectorImpl<WeakVH> &Dead);

} // end namespace llvm

Expand Down
2 changes: 1 addition & 1 deletion 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 *, WeakTrackingVH> ValueToValueMapTy;
typedef ValueMap<const Value *, WeakVH> 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 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<WeakTrackingVH, 8> WeakTrackingVHList;
typedef MapVector<Value *, WeakTrackingVHList> WeakTrackingVHListMap;
typedef SmallVector<WeakVH, 8> WeakVHList;
typedef MapVector<Value *, WeakVHList> WeakVHListMap;

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.
WeakTrackingVHListMap GEPs;
WeakVHListMap GEPs;
};
}

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

SmallVector<WeakTrackingVH, 1> &
AssumptionCache::getOrInsertAffectedValues(Value *V) {
SmallVector<WeakVH, 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<WeakTrackingVH, 1>()});
auto AVIP = AffectedValues.insert({
AffectedValueCallbackVH(V, this), SmallVector<WeakVH, 1>()});
return AVIP.first->second;
}

Expand Down
8 changes: 4 additions & 4 deletions 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 WeakTrackingVH nulled it out.
// entirely and the WeakVH 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 @@ -345,10 +345,10 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,
if (NumIndirectRemoved > NumIndirectAdded &&
NumDirectRemoved < NumDirectAdded)
DevirtualizedCall = true;

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

// Periodically do an explicit clear to remove tombstones when processing
Expand Down
7 changes: 3 additions & 4 deletions lib/Analysis/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,10 +1772,9 @@ 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<WeakTrackingVH> &DeadInsts,
const TargetTransformInfo *TTI) {
unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakVH> &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 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);

WeakTrackingVH &OldV = ValuePtrs[Idx];
WeakVH &OldV = ValuePtrs[Idx];
if (!OldV) {
OldV = V;
return;
Expand Down
2 changes: 1 addition & 1 deletion 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<WeakTrackingVH> ValuePtrs;
std::vector<WeakVH> 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
Loading

0 comments on commit 263da12

Please sign in to comment.