Use ranged for loops in TypeFinder.cpp, NFC

llvm-svn: 324628
This commit is contained in:
Vedant Kumar 2018-02-08 18:02:27 +00:00
parent ab689cb638
commit 4347227437
1 changed files with 20 additions and 30 deletions

View File

@ -33,18 +33,16 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
OnlyNamed = onlyNamed; OnlyNamed = onlyNamed;
// Get types from global variables. // Get types from global variables.
for (Module::const_global_iterator I = M.global_begin(), for (const auto &G : M.globals()) {
E = M.global_end(); I != E; ++I) { incorporateType(G.getType());
incorporateType(I->getType()); if (G.hasInitializer())
if (I->hasInitializer()) incorporateValue(G.getInitializer());
incorporateValue(I->getInitializer());
} }
// Get types from aliases. // Get types from aliases.
for (Module::const_alias_iterator I = M.alias_begin(), for (const auto &A : M.aliases()) {
E = M.alias_end(); I != E; ++I) { incorporateType(A.getType());
incorporateType(I->getType()); if (const Value *Aliasee = A.getAliasee())
if (const Value *Aliasee = I->getAliasee())
incorporateValue(Aliasee); incorporateValue(Aliasee);
} }
@ -57,9 +55,8 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
incorporateValue(U.get()); incorporateValue(U.get());
// First incorporate the arguments. // First incorporate the arguments.
for (Function::const_arg_iterator AI = FI.arg_begin(), AE = FI.arg_end(); for (const auto &A : FI.args())
AI != AE; ++AI) incorporateValue(&A);
incorporateValue(&*AI);
for (const BasicBlock &BB : FI) for (const BasicBlock &BB : FI)
for (const Instruction &I : BB) { for (const Instruction &I : BB) {
@ -68,26 +65,21 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
// Incorporate non-instruction operand types. (We are incorporating all // Incorporate non-instruction operand types. (We are incorporating all
// instructions with this loop.) // instructions with this loop.)
for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end(); for (const auto &O : I.operands())
OI != OE; ++OI) if (&*O && !isa<Instruction>(&*O))
if (*OI && !isa<Instruction>(OI)) incorporateValue(&*O);
incorporateValue(*OI);
// Incorporate types hiding in metadata. // Incorporate types hiding in metadata.
I.getAllMetadataOtherThanDebugLoc(MDForInst); I.getAllMetadataOtherThanDebugLoc(MDForInst);
for (unsigned i = 0, e = MDForInst.size(); i != e; ++i) for (const auto &MD : MDForInst)
incorporateMDNode(MDForInst[i].second); incorporateMDNode(MD.second);
MDForInst.clear(); MDForInst.clear();
} }
} }
for (Module::const_named_metadata_iterator I = M.named_metadata_begin(), for (const auto &NMD : M.named_metadata())
E = M.named_metadata_end(); I != E; ++I) { for (const auto &MDOp : NMD.operands())
const NamedMDNode *NMD = &*I; incorporateMDNode(MDOp);
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
incorporateMDNode(NMD->getOperand(i));
}
} }
void TypeFinder::clear() { void TypeFinder::clear() {
@ -150,9 +142,8 @@ void TypeFinder::incorporateValue(const Value *V) {
// Look in operands for types. // Look in operands for types.
const User *U = cast<User>(V); const User *U = cast<User>(V);
for (Constant::const_op_iterator I = U->op_begin(), for (const auto &I : U->operands())
E = U->op_end(); I != E;++I) incorporateValue(&*I);
incorporateValue(*I);
} }
/// incorporateMDNode - This method is used to walk the operands of an MDNode to /// incorporateMDNode - This method is used to walk the operands of an MDNode to
@ -163,8 +154,7 @@ void TypeFinder::incorporateMDNode(const MDNode *V) {
return; return;
// Look in operands for types. // Look in operands for types.
for (unsigned i = 0, e = V->getNumOperands(); i != e; ++i) { for (Metadata *Op : V->operands()) {
Metadata *Op = V->getOperand(i);
if (!Op) if (!Op)
continue; continue;
if (auto *N = dyn_cast<MDNode>(Op)) { if (auto *N = dyn_cast<MDNode>(Op)) {