/// this method must be called.
void AddTrackedFunction(Function *F) {
// Add an entry, F -> undef.
- if (StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
+ if (auto *STy = dyn_cast<StructType>(F->getReturnType())) {
MRVFunctionsTracked.insert(F);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
TrackedMultipleRetVals.insert(std::make_pair(std::make_pair(F, i),
std::vector<LatticeVal> getStructLatticeValueFor(Value *V) const {
std::vector<LatticeVal> StructValues;
- StructType *STy = dyn_cast<StructType>(V->getType());
+ auto *STy = dyn_cast<StructType>(V->getType());
assert(STy && "getStructLatticeValueFor() can be called only on structs");
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
auto I = StructValueState.find(std::make_pair(V, i));
/// markAnythingOverdefined - Mark the specified value overdefined. This
/// works with both scalars and structs.
void markAnythingOverdefined(Value *V) {
- if (StructType *STy = dyn_cast<StructType>(V->getType()))
+ if (auto *STy = dyn_cast<StructType>(V->getType()))
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
markOverdefined(getStructValueState(V, i), V);
else
if (!IV.markOverdefined()) return;
DEBUG(dbgs() << "markOverdefined: ";
- if (Function *F = dyn_cast<Function>(V))
+ if (auto *F = dyn_cast<Function>(V))
dbgs() << "Function '" << F->getName() << "'\n";
else
dbgs() << *V << '\n');
if (!I.second)
return LV; // Common case, already in the map.
- if (Constant *C = dyn_cast<Constant>(V)) {
+ if (auto *C = dyn_cast<Constant>(V)) {
// Undef values remain unknown.
if (!isa<UndefValue>(V))
LV.markConstant(C); // Constants are constant
if (!I.second)
return LV; // Common case, already in the map.
- if (Constant *C = dyn_cast<Constant>(V)) {
+ if (auto *C = dyn_cast<Constant>(V)) {
Constant *Elt = C->getAggregateElement(i);
if (!Elt)
void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
SmallVectorImpl<bool> &Succs) {
Succs.resize(TI.getNumSuccessors());
- if (BranchInst *BI = dyn_cast<BranchInst>(&TI)) {
+ if (auto *BI = dyn_cast<BranchInst>(&TI)) {
if (BI->isUnconditional()) {
Succs[0] = true;
return;
return;
}
- if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
+ if (auto *SI = dyn_cast<SwitchInst>(&TI)) {
if (!SI->getNumCases()) {
Succs[0] = true;
return;
// Check to make sure this edge itself is actually feasible now.
TerminatorInst *TI = From->getTerminator();
- if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
+ if (auto *BI = dyn_cast<BranchInst>(TI)) {
if (BI->isUnconditional())
return true;
if (TI->isExceptional())
return true;
- if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+ if (auto *SI = dyn_cast<SwitchInst>(TI)) {
if (SI->getNumCases() < 1)
return true;
// Handle functions that return multiple values.
if (!TrackedMultipleRetVals.empty()) {
- if (StructType *STy = dyn_cast<StructType>(ResultOp->getType()))
+ if (auto *STy = dyn_cast<StructType>(ResultOp->getType()))
if (MRVFunctionsTracked.count(F))
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
mergeInValue(TrackedMultipleRetVals[std::make_pair(F, i)], F,
}
void SCCPSolver::visitInsertValueInst(InsertValueInst &IVI) {
- StructType *STy = dyn_cast<StructType>(IVI.getType());
+ auto *STy = dyn_cast<StructType>(IVI.getType());
if (!STy)
return markOverdefined(&IVI);
return;
// Transform load (constant global) into the value loaded.
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr)) {
+ if (auto *GV = dyn_cast<GlobalVariable>(Ptr)) {
if (!TrackedGlobals.empty()) {
// If we are tracking this global, merge in the known value for it.
DenseMap<GlobalVariable*, LatticeVal>::iterator It =
continue;
}
- if (StructType *STy = dyn_cast<StructType>(AI->getType())) {
+ if (auto *STy = dyn_cast<StructType>(AI->getType())) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
LatticeVal CallArg = getStructValueState(*CAI, i);
mergeInValue(getStructValueState(&*AI, i), &*AI, CallArg);
}
// If this is a single/zero retval case, see if we're tracking the function.
- if (StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
+ if (auto *STy = dyn_cast<StructType>(F->getReturnType())) {
if (!MRVFunctionsTracked.count(F))
goto CallOverdefined; // Not tracking this callee.
// Update all of the users of this instruction's value.
//
for (User *U : I->users())
- if (Instruction *UI = dyn_cast<Instruction>(U))
+ if (auto *UI = dyn_cast<Instruction>(U))
OperandChangedState(UI);
}
//
if (I->getType()->isStructTy() || !getValueState(I).isOverdefined())
for (User *U : I->users())
- if (Instruction *UI = dyn_cast<Instruction>(U))
+ if (auto *UI = dyn_cast<Instruction>(U))
OperandChangedState(UI);
}
// Look for instructions which produce undef values.
if (I.getType()->isVoidTy()) continue;
- if (StructType *STy = dyn_cast<StructType>(I.getType())) {
+ if (auto *STy = dyn_cast<StructType>(I.getType())) {
// Only a few things that can be structs matter for undef.
// Tracked calls must never be marked overdefined in ResolvedUndefsIn.
// we force the branch to go one way or the other to make the successor
// values live. It doesn't really matter which way we force it.
TerminatorInst *TI = BB.getTerminator();
- if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
+ if (auto *BI = dyn_cast<BranchInst>(TI)) {
if (!BI->isConditional()) continue;
if (!getValueState(BI->getCondition()).isUnknown())
continue;
return true;
}
- if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+ if (auto *SI = dyn_cast<SwitchInst>(TI)) {
if (!SI->getNumCases() || !getValueState(SI->getCondition()).isUnknown())
continue;
if (any_of(IVs, [](const LatticeVal &LV) { return LV.isOverdefined(); }))
return false;
std::vector<Constant *> ConstVals;
- StructType *ST = dyn_cast<StructType>(V->getType());
+ auto *ST = dyn_cast<StructType>(V->getType());
for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) {
LatticeVal V = IVs[i];
ConstVals.push_back(V.isConstant()
for (const Use &U : GV->uses()) {
const User *UR = U.getUser();
- if (const StoreInst *SI = dyn_cast<StoreInst>(UR)) {
+ if (const auto *SI = dyn_cast<StoreInst>(UR)) {
if (SI->getOperand(0) == GV || SI->isVolatile())
return true; // Storing addr of GV.
} else if (isa<InvokeInst>(UR) || isa<CallInst>(UR)) {
ImmutableCallSite CS(cast<Instruction>(UR));
if (!CS.isCallee(&U))
return true;
- } else if (const LoadInst *LI = dyn_cast<LoadInst>(UR)) {
+ } else if (const auto *LI = dyn_cast<LoadInst>(UR)) {
if (LI->isVolatile())
return true;
} else if (isa<BlockAddress>(UR)) {
return;
for (BasicBlock &BB : F)
- if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator()))
+ if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator()))
if (!isa<UndefValue>(RI->getOperand(0)))
ReturnsToZap.push_back(RI);
}
UI != UE;) {
// Grab the user and then increment the iterator early, as the user
// will be deleted. Step past all adjacent uses from the same user.
- Instruction *I = dyn_cast<Instruction>(*UI);
+ auto *I = dyn_cast<Instruction>(*UI);
do { ++UI; } while (UI != UE && *UI == I);
// Ignore blockaddress users; BasicBlock's dtor will handle them.
// if this is a branch or switch on undef. Fold it manually as a
// branch to the first successor.
#ifndef NDEBUG
- if (BranchInst *BI = dyn_cast<BranchInst>(I)) {
+ if (auto *BI = dyn_cast<BranchInst>(I)) {
assert(BI->isConditional() && isa<UndefValue>(BI->getCondition()) &&
"Branch should be foldable!");
- } else if (SwitchInst *SI = dyn_cast<SwitchInst>(I)) {
+ } else if (auto *SI = dyn_cast<SwitchInst>(I)) {
assert(isa<UndefValue>(SI->getCondition()) && "Switch should fold");
} else {
llvm_unreachable("Didn't fold away reference to block!");