Skip to content

Commit

Permalink
SIL: remove SILValue::getDef and add a cast operator to ValueBase * a…
Browse files Browse the repository at this point in the history
…s a repelacement. NFC.
  • Loading branch information
eeckstein committed Jan 25, 2016
1 parent aef0a11 commit 74d44b7
Show file tree
Hide file tree
Showing 63 changed files with 255 additions and 262 deletions.
10 changes: 5 additions & 5 deletions include/swift/SIL/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ struct BinaryOp_match {
if (!I || I->getNumOperands() != 2)
return false;

return L.match(I->getOperand(0).getDef()) &&
R.match(I->getOperand(1).getDef());
return L.match((ValueBase *)I->getOperand(0)) &&
R.match((ValueBase *)I->getOperand(1));
}
};

Expand All @@ -431,7 +431,7 @@ struct tupleextract_ty {
if (!TEI)
return false;

return TEI->getFieldNo() == index && L.match(TEI->getOperand().getDef());
return TEI->getFieldNo() == index && L.match((ValueBase *)TEI->getOperand());
}
};

Expand Down Expand Up @@ -522,10 +522,10 @@ struct Argument_match {
template <typename ITy>
bool match(ITy *V) {
if (auto *Apply = dyn_cast<ApplyInst>(V)) {
return Val.match(Apply->getArgument(OpI).getDef());
return Val.match((ValueBase *)Apply->getArgument(OpI));
}
if (auto *Builtin = dyn_cast<BuiltinInst>(V)) {
return Val.match(Builtin->getArguments()[OpI].getDef());
return Val.match((ValueBase *)Builtin->getArguments()[OpI]);
}
return false;
}
Expand Down
22 changes: 11 additions & 11 deletions include/swift/SIL/SILValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,23 @@ class SILValue {
SILValue(const ValueBase *V = nullptr)
: Value((ValueBase *)V) { }

ValueBase *getDef() const { return Value; }
ValueBase *operator->() const { return getDef(); }
ValueBase &operator*() const { return *getDef(); }
ValueBase *operator->() const { return Value; }
ValueBase &operator*() const { return *Value; }
operator ValueBase *() const { return Value; }

// Comparison.
bool operator==(SILValue RHS) const {
return Value == RHS.Value;
}
bool operator==(SILValue RHS) const { return Value == RHS.Value; }
bool operator==(ValueBase *RHS) const { return Value == RHS; }
bool operator!=(SILValue RHS) const { return !(*this == RHS); }
bool operator!=(ValueBase *RHS) const { return Value != RHS; }
// Ordering (for std::map).
bool operator<(SILValue RHS) const {
return Value < RHS.Value;
}

/// Return true if underlying ValueBase of this SILValue is non-null. Return
/// false otherwise.
explicit operator bool() const { return getDef() != nullptr; }
explicit operator bool() const { return Value != nullptr; }

/// Convert this SILValue into an opaque pointer like type. For use with
/// PointerLikeTypeTraits.
Expand Down Expand Up @@ -234,7 +234,7 @@ class Operand {
// It's probably not worth optimizing for the case of switching
// operands on a single value.
removeFromCurrent();
assert(reinterpret_cast<ValueBase *>(Owner) != newValue.getDef() &&
assert(reinterpret_cast<ValueBase *>(Owner) != newValue &&
"Cannot add a value as an operand of the instruction that defines it!");
TheValue = newValue;
insertIntoCurrent();
Expand Down Expand Up @@ -577,7 +577,7 @@ template<> class TailAllocatedOperandList<0> {

/// SILValue hashes just like a pointer.
static inline llvm::hash_code hash_value(SILValue V) {
return llvm::hash_value(V.getDef());
return llvm::hash_value((ValueBase *)V);
}

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SILValue V) {
Expand All @@ -593,7 +593,7 @@ namespace llvm {
template<> struct simplify_type<const ::swift::SILValue> {
typedef ::swift::ValueBase *SimpleType;
static SimpleType getSimplifiedValue(::swift::SILValue Val) {
return Val.getDef();
return Val;
}
};
template<> struct simplify_type< ::swift::SILValue>
Expand All @@ -610,7 +610,7 @@ namespace llvm {
llvm::DenseMapInfo<void*>::getTombstoneKey());
}
static unsigned getHashValue(swift::SILValue V) {
return DenseMapInfo<swift::ValueBase *>::getHashValue(V.getDef());
return DenseMapInfo<swift::ValueBase *>::getHashValue(V);
}
static bool isEqual(swift::SILValue LHS, swift::SILValue RHS) {
return LHS == RHS;
Expand Down
6 changes: 3 additions & 3 deletions include/swift/SIL/SILValueProjection.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class SILValueProjection {
/// Returns the hashcode for the location.
llvm::hash_code getHashCode() const {
llvm::hash_code HC = llvm::hash_combine(
Base.getDef(), Base->getType());
Base, Base->getType());
if (!Path.hasValue())
return HC;
HC = llvm::hash_combine(HC, hash_value(Path.getValue()));
Expand Down Expand Up @@ -381,7 +381,7 @@ class LSValue : public SILValueProjection {
static inline llvm::hash_code hash_value(const LSValue &V) {
if (V.isCoveringValue())
return llvm::hash_combine(V.isCoveringValue());
return llvm::hash_combine(V.getBase().getDef(), V.getBase()->getType());
return llvm::hash_combine(V.getBase(), V.getBase()->getType());
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -506,7 +506,7 @@ class LSLocation : public SILValueProjection {
};

static inline llvm::hash_code hash_value(const LSLocation &L) {
return llvm::hash_combine(L.getBase().getDef(), L.getBase()->getType());
return llvm::hash_combine(L.getBase(), L.getBase()->getType());
}

} // end swift namespace
Expand Down
4 changes: 0 additions & 4 deletions include/swift/SIL/SILVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class SILVisitor {
llvm_unreachable("Not reachable, all cases handled");
}

ValueRetTy visit(SILValue V) {
return asImpl().visit(V.getDef());
}

// Define default dispatcher implementations chain to parent nodes.
#define VALUE(CLASS, PARENT) \
ValueRetTy visit##CLASS(CLASS *I) { \
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/Analysis/EscapeAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class EscapeAnalysis : public BottomUpIPAnalysis {

/// Gets or creates a node for a SILValue (same as above).
CGNode *getNode(SILValue V, EscapeAnalysis *EA) {
return getNode(V.getDef(), EA, true);
return getNode(V, EA, true);
}

/// Gets or creates a content node to which \a AddrNode points to.
Expand Down Expand Up @@ -541,7 +541,7 @@ class EscapeAnalysis : public BottomUpIPAnalysis {

/// Gets or creates a node for a SILValue (same as above).
CGNode *getNodeOrNull(SILValue V, EscapeAnalysis *EA) {
return getNode(V.getDef(), EA, false);
return getNode(V, EA, false);
}

/// Returns the number of use-points of a node.
Expand Down
12 changes: 6 additions & 6 deletions include/swift/SILOptimizer/Utils/SCCVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ class SCCVisitor {
llvm::SmallVectorImpl<ValueBase *> &Operands) {
switch (Term->getTermKind()) {
case TermKind::BranchInst:
return Operands.push_back(cast<BranchInst>(Term)->getArg(Index).getDef());
return Operands.push_back(cast<BranchInst>(Term)->getArg(Index));

case TermKind::CondBranchInst: {
auto *CBI = cast<CondBranchInst>(Term);
if (SuccBB == CBI->getTrueBB())
return Operands.push_back(CBI->getTrueArgs()[Index].getDef());
return Operands.push_back(CBI->getTrueArgs()[Index]);
assert(SuccBB == CBI->getFalseBB() &&
"Block is not a successor of terminator!");
Operands.push_back(CBI->getFalseArgs()[Index].getDef());
Operands.push_back(CBI->getFalseArgs()[Index]);
return;
}

Expand All @@ -127,7 +127,7 @@ class SCCVisitor {
case TermKind::CheckedCastAddrBranchInst:
case TermKind::DynamicMethodBranchInst:
assert(Index == 0 && "Expected argument index to always be zero!");
return Operands.push_back(Term->getOperand(0).getDef());
return Operands.push_back(Term->getOperand(0));

case TermKind::UnreachableInst:
case TermKind::ReturnInst:
Expand All @@ -137,7 +137,7 @@ class SCCVisitor {

case TermKind::TryApplyInst:
for (auto &O : cast<TryApplyInst>(Term)->getAllOperands())
Operands.push_back(O.get().getDef());
Operands.push_back(O.get());
return;
}
}
Expand All @@ -146,7 +146,7 @@ class SCCVisitor {
llvm::SmallVectorImpl<ValueBase *> &Operands) {
if (auto *I = dyn_cast<SILInstruction>(User)) {
for (auto &O : I->getAllOperands())
Operands.push_back(O.get().getDef());
Operands.push_back(O.get());
return;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ mapTriviallyToInt(IRGenSILFunction &IGF, const EnumImplStrategy &EIS, SelectEnum
if (index < 0)
return nullptr;

IntegerLiteralInst *intLit = dyn_cast<IntegerLiteralInst>(casePair.second.getDef());
IntegerLiteralInst *intLit = dyn_cast<IntegerLiteralInst>(casePair.second);
if (!intLit)
return nullptr;

Expand Down Expand Up @@ -3386,7 +3386,7 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
return false;

// Destination must be the allocation.
if (copy->getDest().getDef() != allocInst)
if (copy->getDest() != SILValue(allocInst))
return false;

// Copy must be an initialization.
Expand Down
8 changes: 4 additions & 4 deletions lib/SIL/InstructionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ SILValue swift::stripCasts(SILValue V) {
if (isRCIdentityPreservingCast(K)
|| K == ValueKind::UncheckedTrivialBitCastInst
|| K == ValueKind::MarkDependenceInst) {
V = cast<SILInstruction>(V.getDef())->getOperand(0);
V = cast<SILInstruction>(V)->getOperand(0);
continue;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ SILValue swift::stripAddressProjections(SILValue V) {
V = stripSinglePredecessorArgs(V);
if (!NewProjection::isAddressProjection(V))
return V;
V = cast<SILInstruction>(V.getDef())->getOperand(0);
V = cast<SILInstruction>(V)->getOperand(0);
}
}

Expand All @@ -146,13 +146,13 @@ SILValue swift::stripValueProjections(SILValue V) {
V = stripSinglePredecessorArgs(V);
if (!NewProjection::isObjectProjection(V))
return V;
V = cast<SILInstruction>(V.getDef())->getOperand(0);
V = cast<SILInstruction>(V)->getOperand(0);
}
}

SILValue swift::stripIndexingInsts(SILValue V) {
while (true) {
if (!isa<IndexingInst>(V.getDef()))
if (!isa<IndexingInst>(V))
return V;
V = cast<IndexingInst>(V)->getBase();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ class ProjectionTreeNode::AggregateBuilder {
/// If all SILValues have been set, we are complete.
bool isComplete() const {
return std::all_of(Values.begin(), Values.end(), [](SILValue V) -> bool {
return V.getDef();
return V;
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/SILGlobalVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ static bool analyzeStaticInitializer(SILFunction *F, SILInstruction *&Val,
SGA = sga;
GVar = SGA->getReferencedGlobal();
} else if (auto *SI = dyn_cast<StoreInst>(&I)) {
if (HasStore || SI->getDest().getDef() != SGA)
if (HasStore || SI->getDest() != SGA)
return false;
HasStore = true;
Val = dyn_cast<SILInstruction>(SI->getSrc().getDef());
Val = dyn_cast<SILInstruction>(SI->getSrc());

// We only handle StructInst and TupleInst being stored to a
// global variable for now.
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ ID SILPrinter::getID(SILValue V) {
V->getParentBB()->getParent()->numberValues(ValueToIDMap);
}

ID R = { ID::SSAValue, ValueToIDMap[V.getDef()] };
ID R = { ID::SSAValue, ValueToIDMap[V] };
return R;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {

// Make sure that if operand is generic that its primary archetypes match
// the function context.
checkLegalType(I->getFunction(), operand.get().getDef());
checkLegalType(I->getFunction(), operand.get());
}
}

Expand Down Expand Up @@ -618,11 +618,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
bool Allocated = true;
for (auto Inst = AI->getIterator(), E = SBB->end(); Inst != E; ++Inst) {
if (LoadInst *LI = dyn_cast<LoadInst>(Inst))
if (LI->getOperand().getDef() == AI)
if (LI->getOperand() == AI)
require(Allocated, "AllocStack used by Load outside its lifetime");

if (StoreInst *SI = dyn_cast<StoreInst>(Inst))
if (SI->getDest().getDef() == AI)
if (SI->getDest() == AI)
require(Allocated, "AllocStack used by Store outside its lifetime");

if (DeallocStackInst *DSI = dyn_cast<DeallocStackInst>(Inst))
Expand Down Expand Up @@ -2875,7 +2875,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
SILValue op = i.getOperand(0);
require(!stack.empty(),
"stack dealloc with empty stack");
require(op.getDef() == stack.back(),
require(op == stack.back(),
"stack dealloc does not match most recent stack alloc");
stack.pop_back();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenEpilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SILGenFunction::emitEpilogBB(SILLocation TopLevel) {
if (needsArg) {
returnValue = predBranch->getArgs()[0];
// RAUW the old BB argument (if any) with the new value.
(*epilogBB->bbarg_begin())->replaceAllUsesWith(returnValue.getDef());
(*epilogBB->bbarg_begin())->replaceAllUsesWith(returnValue);
}

// If we are optimizing, we should use the return location from the single,
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Analysis/ARCAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {
if (!Params[i].isGuaranteed())
continue;
SILValue Op = FAS.getArgument(i);
if (!AA->isNoAlias(Op, Ptr.getDef()))
if (!AA->isNoAlias(Op, Ptr))
return true;
}

Expand Down Expand Up @@ -561,7 +561,7 @@ static bool addLastUse(SILValue V, SILBasicBlock *BB,
ReleaseTracker &Tracker) {
for (auto I = BB->rbegin(); I != BB->rend(); ++I) {
for (auto &Op : I->getAllOperands())
if (Op.get().getDef() == V.getDef()) {
if (Op.get() == V) {
Tracker.trackLastRelease(&*I);
return true;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/SILOptimizer/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
if (isSameValueOrGlobal(V1, V2))
return AliasResult::MustAlias;

DEBUG(llvm::dbgs() << "ALIAS ANALYSIS:\n V1: " << *V1.getDef()
<< " V2: " << *V2.getDef());
DEBUG(llvm::dbgs() << "ALIAS ANALYSIS:\n V1: " << *V1
<< " V2: " << *V2);

// Pass in both the TBAA types so we can perform typed access TBAA and the
// actual types of V1, V2 so we can perform class based TBAA.
Expand All @@ -579,15 +579,15 @@ AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
// Strip off any casts on V1, V2.
V1 = stripCasts(V1);
V2 = stripCasts(V2);
DEBUG(llvm::dbgs() << " After Cast Stripping V1:" << *V1.getDef());
DEBUG(llvm::dbgs() << " After Cast Stripping V2:" << *V2.getDef());
DEBUG(llvm::dbgs() << " After Cast Stripping V1:" << *V1);
DEBUG(llvm::dbgs() << " After Cast Stripping V2:" << *V2);

// Ok, we need to actually compute an Alias Analysis result for V1, V2. Begin
// by finding the "base" of V1, V2 by stripping off all casts and GEPs.
SILValue O1 = getUnderlyingObject(V1);
SILValue O2 = getUnderlyingObject(V2);
DEBUG(llvm::dbgs() << " Underlying V1:" << *O1.getDef());
DEBUG(llvm::dbgs() << " Underlying V2:" << *O2.getDef());
DEBUG(llvm::dbgs() << " Underlying V1:" << *O1);
DEBUG(llvm::dbgs() << " Underlying V2:" << *O2);

// If O1 and O2 do not equal, see if we can prove that they cannot be the
// same object. If we can, return No Alias.
Expand Down Expand Up @@ -711,10 +711,10 @@ SILAnalysis *swift::createAliasAnalysis(SILModule *M) {

AliasKeyTy AliasAnalysis::toAliasKey(SILValue V1, SILValue V2,
SILType Type1, SILType Type2) {
size_t idx1 = AliasValueBaseToIndex.getIndex(V1.getDef());
size_t idx1 = AliasValueBaseToIndex.getIndex(V1);
assert(idx1 != std::numeric_limits<size_t>::max() &&
"~0 index reserved for empty/tombstone keys");
size_t idx2 = AliasValueBaseToIndex.getIndex(V2.getDef());
size_t idx2 = AliasValueBaseToIndex.getIndex(V2);
assert(idx2 != std::numeric_limits<size_t>::max() &&
"~0 index reserved for empty/tombstone keys");
void *t1 = Type1.getOpaqueValue();
Expand Down
Loading

0 comments on commit 74d44b7

Please sign in to comment.