From: Davide Italiano Date: Thu, 1 Dec 2016 08:36:12 +0000 (+0000) Subject: [SCCP] Prefer `auto` when the type is obvious. NFCI. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=236801ef989e90b133adc8366218af922bbc0b6e;p=llvm [SCCP] Prefer `auto` when the type is obvious. NFCI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288324 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 9de3059dadf..a6c28d50699 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -242,7 +242,7 @@ public: /// this method must be called. void AddTrackedFunction(Function *F) { // Add an entry, F -> undef. - if (StructType *STy = dyn_cast(F->getReturnType())) { + if (auto *STy = dyn_cast(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), @@ -272,7 +272,7 @@ public: std::vector getStructLatticeValueFor(Value *V) const { std::vector StructValues; - StructType *STy = dyn_cast(V->getType()); + auto *STy = dyn_cast(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)); @@ -315,7 +315,7 @@ public: /// markAnythingOverdefined - Mark the specified value overdefined. This /// works with both scalars and structs. void markAnythingOverdefined(Value *V) { - if (StructType *STy = dyn_cast(V->getType())) + if (auto *STy = dyn_cast(V->getType())) for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) markOverdefined(getStructValueState(V, i), V); else @@ -375,7 +375,7 @@ private: if (!IV.markOverdefined()) return; DEBUG(dbgs() << "markOverdefined: "; - if (Function *F = dyn_cast(V)) + if (auto *F = dyn_cast(V)) dbgs() << "Function '" << F->getName() << "'\n"; else dbgs() << *V << '\n'); @@ -414,7 +414,7 @@ private: if (!I.second) return LV; // Common case, already in the map. - if (Constant *C = dyn_cast(V)) { + if (auto *C = dyn_cast(V)) { // Undef values remain unknown. if (!isa(V)) LV.markConstant(C); // Constants are constant @@ -440,7 +440,7 @@ private: if (!I.second) return LV; // Common case, already in the map. - if (Constant *C = dyn_cast(V)) { + if (auto *C = dyn_cast(V)) { Constant *Elt = C->getAggregateElement(i); if (!Elt) @@ -563,7 +563,7 @@ private: void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI, SmallVectorImpl &Succs) { Succs.resize(TI.getNumSuccessors()); - if (BranchInst *BI = dyn_cast(&TI)) { + if (auto *BI = dyn_cast(&TI)) { if (BI->isUnconditional()) { Succs[0] = true; return; @@ -590,7 +590,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI, return; } - if (SwitchInst *SI = dyn_cast(&TI)) { + if (auto *SI = dyn_cast(&TI)) { if (!SI->getNumCases()) { Succs[0] = true; return; @@ -634,7 +634,7 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) { // Check to make sure this edge itself is actually feasible now. TerminatorInst *TI = From->getTerminator(); - if (BranchInst *BI = dyn_cast(TI)) { + if (auto *BI = dyn_cast(TI)) { if (BI->isUnconditional()) return true; @@ -654,7 +654,7 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) { if (TI->isExceptional()) return true; - if (SwitchInst *SI = dyn_cast(TI)) { + if (auto *SI = dyn_cast(TI)) { if (SI->getNumCases() < 1) return true; @@ -769,7 +769,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) { // Handle functions that return multiple values. if (!TrackedMultipleRetVals.empty()) { - if (StructType *STy = dyn_cast(ResultOp->getType())) + if (auto *STy = dyn_cast(ResultOp->getType())) if (MRVFunctionsTracked.count(F)) for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) mergeInValue(TrackedMultipleRetVals[std::make_pair(F, i)], F, @@ -828,7 +828,7 @@ void SCCPSolver::visitExtractValueInst(ExtractValueInst &EVI) { } void SCCPSolver::visitInsertValueInst(InsertValueInst &IVI) { - StructType *STy = dyn_cast(IVI.getType()); + auto *STy = dyn_cast(IVI.getType()); if (!STy) return markOverdefined(&IVI); @@ -1058,7 +1058,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) { return; // Transform load (constant global) into the value loaded. - if (GlobalVariable *GV = dyn_cast(Ptr)) { + if (auto *GV = dyn_cast(Ptr)) { if (!TrackedGlobals.empty()) { // If we are tracking this global, merge in the known value for it. DenseMap::iterator It = @@ -1146,7 +1146,7 @@ CallOverdefined: continue; } - if (StructType *STy = dyn_cast(AI->getType())) { + if (auto *STy = dyn_cast(AI->getType())) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { LatticeVal CallArg = getStructValueState(*CAI, i); mergeInValue(getStructValueState(&*AI, i), &*AI, CallArg); @@ -1158,7 +1158,7 @@ CallOverdefined: } // If this is a single/zero retval case, see if we're tracking the function. - if (StructType *STy = dyn_cast(F->getReturnType())) { + if (auto *STy = dyn_cast(F->getReturnType())) { if (!MRVFunctionsTracked.count(F)) goto CallOverdefined; // Not tracking this callee. @@ -1196,7 +1196,7 @@ void SCCPSolver::Solve() { // Update all of the users of this instruction's value. // for (User *U : I->users()) - if (Instruction *UI = dyn_cast(U)) + if (auto *UI = dyn_cast(U)) OperandChangedState(UI); } @@ -1215,7 +1215,7 @@ void SCCPSolver::Solve() { // if (I->getType()->isStructTy() || !getValueState(I).isOverdefined()) for (User *U : I->users()) - if (Instruction *UI = dyn_cast(U)) + if (auto *UI = dyn_cast(U)) OperandChangedState(UI); } @@ -1260,7 +1260,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // Look for instructions which produce undef values. if (I.getType()->isVoidTy()) continue; - if (StructType *STy = dyn_cast(I.getType())) { + if (auto *STy = dyn_cast(I.getType())) { // Only a few things that can be structs matter for undef. // Tracked calls must never be marked overdefined in ResolvedUndefsIn. @@ -1481,7 +1481,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // 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(TI)) { + if (auto *BI = dyn_cast(TI)) { if (!BI->isConditional()) continue; if (!getValueState(BI->getCondition()).isUnknown()) continue; @@ -1502,7 +1502,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { return true; } - if (SwitchInst *SI = dyn_cast(TI)) { + if (auto *SI = dyn_cast(TI)) { if (!SI->getNumCases() || !getValueState(SI->getCondition()).isUnknown()) continue; @@ -1529,7 +1529,7 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) { if (any_of(IVs, [](const LatticeVal &LV) { return LV.isOverdefined(); })) return false; std::vector ConstVals; - StructType *ST = dyn_cast(V->getType()); + auto *ST = dyn_cast(V->getType()); for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) { LatticeVal V = IVs[i]; ConstVals.push_back(V.isConstant() @@ -1670,7 +1670,7 @@ static bool AddressIsTaken(const GlobalValue *GV) { for (const Use &U : GV->uses()) { const User *UR = U.getUser(); - if (const StoreInst *SI = dyn_cast(UR)) { + if (const auto *SI = dyn_cast(UR)) { if (SI->getOperand(0) == GV || SI->isVolatile()) return true; // Storing addr of GV. } else if (isa(UR) || isa(UR)) { @@ -1678,7 +1678,7 @@ static bool AddressIsTaken(const GlobalValue *GV) { ImmutableCallSite CS(cast(UR)); if (!CS.isCallee(&U)) return true; - } else if (const LoadInst *LI = dyn_cast(UR)) { + } else if (const auto *LI = dyn_cast(UR)) { if (LI->isVolatile()) return true; } else if (isa(UR)) { @@ -1699,7 +1699,7 @@ static void findReturnsToZap(Function &F, return; for (BasicBlock &BB : F) - if (ReturnInst *RI = dyn_cast(BB.getTerminator())) + if (auto *RI = dyn_cast(BB.getTerminator())) if (!isa(RI->getOperand(0))) ReturnsToZap.push_back(RI); } @@ -1826,7 +1826,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, 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(*UI); + auto *I = dyn_cast(*UI); do { ++UI; } while (UI != UE && *UI == I); // Ignore blockaddress users; BasicBlock's dtor will handle them. @@ -1838,10 +1838,10 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // 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(I)) { + if (auto *BI = dyn_cast(I)) { assert(BI->isConditional() && isa(BI->getCondition()) && "Branch should be foldable!"); - } else if (SwitchInst *SI = dyn_cast(I)) { + } else if (auto *SI = dyn_cast(I)) { assert(isa(SI->getCondition()) && "Switch should fold"); } else { llvm_unreachable("Didn't fold away reference to block!");