forked from OSchip/llvm-project
[Transforms] Use range-based for loops (NFC)
This commit is contained in:
parent
94c350847a
commit
302313a264
|
@ -82,24 +82,23 @@ namespace {
|
|||
// be conservative and simple.
|
||||
|
||||
// Visit the GlobalVariables.
|
||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||
I != E; ++I) {
|
||||
bool Delete =
|
||||
deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration() &&
|
||||
(!I->isConstant() || !keepConstInit);
|
||||
for (GlobalVariable &GV : M.globals()) {
|
||||
bool Delete = deleteStuff == (bool)Named.count(&GV) &&
|
||||
!GV.isDeclaration() &&
|
||||
(!GV.isConstant() || !keepConstInit);
|
||||
if (!Delete) {
|
||||
if (I->hasAvailableExternallyLinkage())
|
||||
if (GV.hasAvailableExternallyLinkage())
|
||||
continue;
|
||||
if (I->getName() == "llvm.global_ctors")
|
||||
if (GV.getName() == "llvm.global_ctors")
|
||||
continue;
|
||||
}
|
||||
|
||||
makeVisible(*I, Delete);
|
||||
makeVisible(GV, Delete);
|
||||
|
||||
if (Delete) {
|
||||
// Make this a declaration and drop it's comdat.
|
||||
I->setInitializer(nullptr);
|
||||
I->setComdat(nullptr);
|
||||
GV.setInitializer(nullptr);
|
||||
GV.setComdat(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,11 +213,10 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
|
|||
findUsedValues(M.getGlobalVariable("llvm.used"), llvmUsedValues);
|
||||
findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues);
|
||||
|
||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||
I != E; ++I) {
|
||||
if (I->hasLocalLinkage() && llvmUsedValues.count(&*I) == 0)
|
||||
if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
|
||||
I->setName(""); // Internal symbols can't participate in linkage
|
||||
for (GlobalVariable &GV : M.globals()) {
|
||||
if (GV.hasLocalLinkage() && llvmUsedValues.count(&GV) == 0)
|
||||
if (!PreserveDbgInfo || !GV.getName().startswith("llvm.dbg"))
|
||||
GV.setName(""); // Internal symbols can't participate in linkage
|
||||
}
|
||||
|
||||
for (Function &I : M) {
|
||||
|
|
|
@ -661,13 +661,12 @@ bool InstCombinerImpl::simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I) {
|
|||
break;
|
||||
|
||||
// Replace uses of the select or its condition with the known values.
|
||||
for (Instruction::op_iterator I = BBI->op_begin(), E = BBI->op_end();
|
||||
I != E; ++I) {
|
||||
if (*I == SI) {
|
||||
replaceUse(*I, SI->getOperand(NonNullOperand));
|
||||
for (Use &Op : BBI->operands()) {
|
||||
if (Op == SI) {
|
||||
replaceUse(Op, SI->getOperand(NonNullOperand));
|
||||
Worklist.push(&*BBI);
|
||||
} else if (*I == SelectCond) {
|
||||
replaceUse(*I, NonNullOperand == 1 ? ConstantInt::getTrue(CondTy)
|
||||
} else if (Op == SelectCond) {
|
||||
replaceUse(Op, NonNullOperand == 1 ? ConstantInt::getTrue(CondTy)
|
||||
: ConstantInt::getFalse(CondTy));
|
||||
Worklist.push(&*BBI);
|
||||
}
|
||||
|
|
|
@ -479,8 +479,8 @@ LLVM_NODISCARD Optional<Negator::Result> Negator::run(Value *Root) {
|
|||
if (!Negated) {
|
||||
// We must cleanup newly-inserted instructions, to avoid any potential
|
||||
// endless combine looping.
|
||||
llvm::for_each(llvm::reverse(NewInstructions),
|
||||
[&](Instruction *I) { I->eraseFromParent(); });
|
||||
for (Instruction *I : llvm::reverse(NewInstructions))
|
||||
I->eraseFromParent();
|
||||
return llvm::None;
|
||||
}
|
||||
return std::make_pair(ArrayRef<Instruction *>(NewInstructions), Negated);
|
||||
|
@ -523,8 +523,8 @@ LLVM_NODISCARD Value *Negator::Negate(bool LHSIsZero, Value *Root,
|
|||
NegatorNumInstructionsNegatedSuccess += Res->first.size();
|
||||
|
||||
// They are in def-use order, so nothing fancy, just insert them in order.
|
||||
llvm::for_each(Res->first,
|
||||
[&](Instruction *I) { IC.Builder.Insert(I, I->getName()); });
|
||||
for (Instruction *I : Res->first)
|
||||
IC.Builder.Insert(I, I->getName());
|
||||
|
||||
// And return the new root.
|
||||
return Res->second;
|
||||
|
|
|
@ -3083,9 +3083,8 @@ Instruction *InstCombinerImpl::visitExtractValueInst(ExtractValueInst &EV) {
|
|||
SmallVector<Value*, 4> Indices;
|
||||
// Prefix an i32 0 since we need the first element.
|
||||
Indices.push_back(Builder.getInt32(0));
|
||||
for (ExtractValueInst::idx_iterator I = EV.idx_begin(), E = EV.idx_end();
|
||||
I != E; ++I)
|
||||
Indices.push_back(Builder.getInt32(*I));
|
||||
for (unsigned Idx : EV.indices())
|
||||
Indices.push_back(Builder.getInt32(Idx));
|
||||
|
||||
// We need to insert these at the location of the old load, not at that of
|
||||
// the extractvalue.
|
||||
|
|
|
@ -110,9 +110,8 @@ bool llvm::objcarc::CanUse(const Instruction *Inst, const Value *Ptr,
|
|||
}
|
||||
|
||||
// Check each operand for a match.
|
||||
for (User::const_op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
|
||||
OI != OE; ++OI) {
|
||||
const Value *Op = *OI;
|
||||
for (const Use &U : Inst->operands()) {
|
||||
const Value *Op = U;
|
||||
if (IsPotentialRetainableObjPtr(Op, *PA.getAA()) && PA.related(Ptr, Op))
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -289,9 +289,8 @@ GVN::Expression GVN::ValueTable::createExpr(Instruction *I) {
|
|||
Expression e;
|
||||
e.type = I->getType();
|
||||
e.opcode = I->getOpcode();
|
||||
for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
|
||||
OI != OE; ++OI)
|
||||
e.varargs.push_back(lookupOrAdd(*OI));
|
||||
for (Use &Op : I->operands())
|
||||
e.varargs.push_back(lookupOrAdd(Op));
|
||||
if (I->isCommutative()) {
|
||||
// Ensure that commutative instructions that only differ by a permutation
|
||||
// of their operands get the same value number by sorting the operand value
|
||||
|
@ -362,9 +361,8 @@ GVN::Expression GVN::ValueTable::createExtractvalueExpr(ExtractValueInst *EI) {
|
|||
// Not a recognised intrinsic. Fall back to producing an extract value
|
||||
// expression.
|
||||
e.opcode = EI->getOpcode();
|
||||
for (Instruction::op_iterator OI = EI->op_begin(), OE = EI->op_end();
|
||||
OI != OE; ++OI)
|
||||
e.varargs.push_back(lookupOrAdd(*OI));
|
||||
for (Use &Op : EI->operands())
|
||||
e.varargs.push_back(lookupOrAdd(Op));
|
||||
|
||||
append_range(e.varargs, EI->indices());
|
||||
|
||||
|
|
|
@ -1072,8 +1072,8 @@ static Instruction *getDebugLocFromInstOrOperands(Instruction *I) {
|
|||
if (I->getDebugLoc() != Empty)
|
||||
return I;
|
||||
|
||||
for (User::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) {
|
||||
if (Instruction *OpInst = dyn_cast<Instruction>(*OI))
|
||||
for (Use &Op : I->operands()) {
|
||||
if (Instruction *OpInst = dyn_cast<Instruction>(Op))
|
||||
if (OpInst->getDebugLoc() != Empty)
|
||||
return OpInst;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue