Remove some unnecessary unreachables in favor of (sometimes implicit) assertions

Also simplify some else-after-return cases including some standard
algorithm convenience/use.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230094 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2015-02-20 23:44:24 +00:00
parent b2c6bf6776
commit 74c45a19e3
2 changed files with 36 additions and 53 deletions

View File

@@ -2166,6 +2166,8 @@ public:
return block_begin() + getNumOperands(); return block_begin() + getNumOperands();
} }
op_range incoming_values() { return operands(); }
/// getNumIncomingValues - Return the number of incoming edges /// getNumIncomingValues - Return the number of incoming edges
/// ///
unsigned getNumIncomingValues() const { return getNumOperands(); } unsigned getNumIncomingValues() const { return getNumOperands(); }

View File

@@ -150,17 +150,16 @@ static bool isLiveGCReferenceAt(Value &V, Instruction *loc, DominatorTree &DT,
static bool isAggWhichContainsGCPtrType(Type *Ty) { static bool isAggWhichContainsGCPtrType(Type *Ty) {
if (VectorType *VT = dyn_cast<VectorType>(Ty)) if (VectorType *VT = dyn_cast<VectorType>(Ty))
return isGCPointerType(VT->getScalarType()); return isGCPointerType(VT->getScalarType());
else if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) { if (ArrayType *AT = dyn_cast<ArrayType>(Ty))
return isGCPointerType(AT->getElementType()) || return isGCPointerType(AT->getElementType()) ||
isAggWhichContainsGCPtrType(AT->getElementType()); isAggWhichContainsGCPtrType(AT->getElementType());
} else if (StructType *ST = dyn_cast<StructType>(Ty)) { if (StructType *ST = dyn_cast<StructType>(Ty))
bool UnsupportedType = false; return std::any_of(ST->subtypes().begin(), ST->subtypes().end(),
for (Type *SubType : ST->subtypes()) [](Type *SubType) {
UnsupportedType |= return isGCPointerType(SubType) ||
isGCPointerType(SubType) || isAggWhichContainsGCPtrType(SubType); isAggWhichContainsGCPtrType(SubType);
return UnsupportedType; });
} else return false;
return false;
} }
#endif #endif
@@ -379,12 +378,9 @@ static Value *findBaseDefiningValue(Value *I) {
Value *def = CI->stripPointerCasts(); Value *def = CI->stripPointerCasts();
assert(def->getType()->isPointerTy() && assert(def->getType()->isPointerTy() &&
"Base for pointer must be another pointer"); "Base for pointer must be another pointer");
if (isa<CastInst>(def)) { // If we find a cast instruction here, it means we've found a cast which is
// If we find a cast instruction here, it means we've found a cast // not simply a pointer cast (i.e. an inttoptr). We don't know how to
// which is not simply a pointer cast (i.e. an inttoptr). We don't // handle int->ptr conversion.
// know how to handle int->ptr conversion.
llvm_unreachable("Can not find the base pointers for an inttoptr cast");
}
assert(!isa<CastInst>(def) && "shouldn't find another cast here"); assert(!isa<CastInst>(def) && "shouldn't find another cast here");
return findBaseDefiningValue(def); return findBaseDefiningValue(def);
} }
@@ -492,13 +488,8 @@ static Value *findBaseDefiningValue(Value *I) {
if (SelectInst *select = dyn_cast<SelectInst>(I)) { if (SelectInst *select = dyn_cast<SelectInst>(I)) {
return select; return select;
} }
if (PHINode *phi = dyn_cast<PHINode>(I)) {
return phi;
}
errs() << "unknown type: " << *I << "\n"; return cast<PHINode>(I);
llvm_unreachable("unknown type");
return nullptr;
} }
/// Returns the base defining value for this value. /// Returns the base defining value for this value.
@@ -635,18 +626,18 @@ private:
case PhiState::Base: case PhiState::Base:
assert(stateA.getBase() && "can't be null"); assert(stateA.getBase() && "can't be null");
if (stateB.isUnknown()) { if (stateB.isUnknown())
return stateA; return stateA;
} else if (stateB.isBase()) {
if (stateB.isBase()) {
if (stateA.getBase() == stateB.getBase()) { if (stateA.getBase() == stateB.getBase()) {
assert(stateA == stateB && "equality broken!"); assert(stateA == stateB && "equality broken!");
return stateA; return stateA;
} }
return PhiState(PhiState::Conflict); return PhiState(PhiState::Conflict);
} else {
assert(stateB.isConflict() && "only three states!");
return PhiState(PhiState::Conflict);
} }
assert(stateB.isConflict() && "only three states!");
return PhiState(PhiState::Conflict);
case PhiState::Conflict: case PhiState::Conflict:
return stateA; return stateA;
@@ -701,10 +692,9 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache,
Value *v = Pair.first; Value *v = Pair.first;
assert(!isKnownBaseResult(v) && "why did it get added?"); assert(!isKnownBaseResult(v) && "why did it get added?");
if (PHINode *phi = dyn_cast<PHINode>(v)) { if (PHINode *phi = dyn_cast<PHINode>(v)) {
unsigned NumPHIValues = phi->getNumIncomingValues(); assert(phi->getNumIncomingValues() > 0 &&
assert(NumPHIValues > 0 && "zero input phis are illegal"); "zero input phis are illegal");
for (unsigned i = 0; i != NumPHIValues; ++i) { for (Value *InVal : phi->incoming_values()) {
Value *InVal = phi->getIncomingValue(i);
Value *local = findBaseOrBDV(InVal, cache); Value *local = findBaseOrBDV(InVal, cache);
if (!isKnownBaseResult(local) && states.find(local) == states.end()) { if (!isKnownBaseResult(local) && states.find(local) == states.end()) {
states[local] = PhiState(); states[local] = PhiState();
@@ -748,18 +738,12 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache,
MeetPhiStates calculateMeet(states); MeetPhiStates calculateMeet(states);
Value *v = Pair.first; Value *v = Pair.first;
assert(!isKnownBaseResult(v) && "why did it get added?"); assert(!isKnownBaseResult(v) && "why did it get added?");
assert(isa<SelectInst>(v) || isa<PHINode>(v));
if (SelectInst *select = dyn_cast<SelectInst>(v)) { if (SelectInst *select = dyn_cast<SelectInst>(v)) {
calculateMeet.meetWith(findBaseOrBDV(select->getTrueValue(), cache)); calculateMeet.meetWith(findBaseOrBDV(select->getTrueValue(), cache));
calculateMeet.meetWith(findBaseOrBDV(select->getFalseValue(), cache)); calculateMeet.meetWith(findBaseOrBDV(select->getFalseValue(), cache));
} else if (PHINode *phi = dyn_cast<PHINode>(v)) { } else
for (unsigned i = 0; i < phi->getNumIncomingValues(); i++) { for (Value *Val : cast<PHINode>(v)->incoming_values())
calculateMeet.meetWith( calculateMeet.meetWith(findBaseOrBDV(Val, cache));
findBaseOrBDV(phi->getIncomingValue(i), cache));
}
} else {
llvm_unreachable("no such state expected");
}
PhiState oldState = states[v]; PhiState oldState = states[v];
PhiState newState = calculateMeet.getResult(); PhiState newState = calculateMeet.getResult();
@@ -989,13 +973,13 @@ static void findBasePointers(const StatepointLiveSetTy &live,
cast<Instruction>(ptr)->getParent())) && cast<Instruction>(ptr)->getParent())) &&
"The base we found better dominate the derived pointer"); "The base we found better dominate the derived pointer");
if (isNullConstant(base)) // If you see this trip and like to live really dangerously, the code should
// If you see this trip and like to live really dangerously, the code // be correct, just with idioms the verifier can't handle. You can try
// should be correct, just with idioms the verifier can't handle. You // disabling the verifier at your own substaintial risk.
// can try disabling the verifier at your own substaintial risk. assert(!isNullConstant(base) && "the relocation code needs adjustment to "
llvm_unreachable("the relocation code needs adjustment to handle the" "handle the relocation of a null pointer "
"relocation of a null pointer constant without causing" "constant without causing false positives "
"false positives in the safepoint ir verifier."); "in the safepoint ir verifier.");
} }
} }
@@ -1258,7 +1242,7 @@ makeStatepointExplicitImpl(const CallSite &CS, /* to replace */
Builder.SetInsertPoint(IP); Builder.SetInsertPoint(IP);
Builder.SetCurrentDebugLocation(IP->getDebugLoc()); Builder.SetCurrentDebugLocation(IP->getDebugLoc());
} else if (CS.isInvoke()) { } else {
InvokeInst *toReplace = cast<InvokeInst>(CS.getInstruction()); InvokeInst *toReplace = cast<InvokeInst>(CS.getInstruction());
// Insert the new invoke into the old block. We'll remove the old one in a // Insert the new invoke into the old block. We'll remove the old one in a
@@ -1309,8 +1293,6 @@ makeStatepointExplicitImpl(const CallSite &CS, /* to replace */
// gc relocates will be generated later as if it were regular call // gc relocates will be generated later as if it were regular call
// statepoint // statepoint
} else {
llvm_unreachable("unexpect type of CallSite");
} }
assert(token); assert(token);
@@ -1526,12 +1508,11 @@ static void relocationViaAlloca(
if (auto II = dyn_cast<InvokeInst>(Statepoint)) { if (auto II = dyn_cast<InvokeInst>(Statepoint)) {
InsertClobbersAt(II->getNormalDest()->getFirstInsertionPt()); InsertClobbersAt(II->getNormalDest()->getFirstInsertionPt());
InsertClobbersAt(II->getUnwindDest()->getFirstInsertionPt()); InsertClobbersAt(II->getUnwindDest()->getFirstInsertionPt());
} else if (auto CI = dyn_cast<CallInst>(Statepoint)) { } else {
BasicBlock::iterator Next(CI); BasicBlock::iterator Next(cast<CallInst>(Statepoint));
Next++; Next++;
InsertClobbersAt(Next); InsertClobbersAt(Next);
} else }
llvm_unreachable("illegal statepoint instruction type?");
#endif #endif
} }
// update use with load allocas and add store for gc_relocated // update use with load allocas and add store for gc_relocated