Use foreach loop over constant operands. NFC.

A number of places had explicit loops over Constant::operands().
Just use foreach loops where possible.

llvm-svn: 240694
This commit is contained in:
Pete Cooper 2015-06-25 20:51:38 +00:00
parent e6fd0df168
commit c2ffa0891f
5 changed files with 9 additions and 14 deletions

View File

@ -1519,8 +1519,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
} else if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
isa<ConstantVector>(C)) {
Code = bitc::CST_CODE_AGGREGATE;
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
Record.push_back(VE.getValueID(C->getOperand(i)));
for (const Value *Op : C->operands())
Record.push_back(VE.getValueID(Op));
AbbrevToUse = AggregateAbbrev;
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
switch (CE->getOpcode()) {

View File

@ -691,9 +691,7 @@ void ValueEnumerator::EnumerateOperandType(const Value *V) {
// This constant may have operands, make sure to enumerate the types in
// them.
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
const Value *Op = C->getOperand(i);
for (const Value *Op : C->operands()) {
// Don't enumerate basic blocks here, this happens as operands to
// blockaddress.
if (isa<BasicBlock>(Op))

View File

@ -1678,9 +1678,8 @@ void CppWriter::printFunctionUses(const Function* F) {
consts.insert(GVar->getInitializer());
} else if (Constant* C = dyn_cast<Constant>(operand)) {
consts.insert(C);
for (unsigned j = 0; j < C->getNumOperands(); ++j) {
for (Value* operand : C->operands()) {
// If the operand references a GVal or Constant, make a note of it
Value* operand = C->getOperand(j);
printType(operand->getType());
if (GlobalValue* GV = dyn_cast<GlobalValue>(operand)) {
gvs.insert(GV);

View File

@ -1992,11 +1992,9 @@ isSimpleEnoughValueToCommitHelper(Constant *C,
// Aggregate values are safe if all their elements are.
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
isa<ConstantVector>(C)) {
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
Constant *Op = cast<Constant>(C->getOperand(i));
if (!isSimpleEnoughValueToCommit(Op, SimpleConstants, DL))
for (Value *Op : C->operands())
if (!isSimpleEnoughValueToCommit(cast<Constant>(Op), SimpleConstants, DL))
return false;
}
return true;
}

View File

@ -142,9 +142,9 @@ static bool OnlyUsedBy(Value *V, Value *Usr) {
static void RemoveDeadConstant(Constant *C) {
assert(C->use_empty() && "Constant is not dead!");
SmallPtrSet<Constant*, 4> Operands;
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
if (OnlyUsedBy(C->getOperand(i), C))
Operands.insert(cast<Constant>(C->getOperand(i)));
for (Value *Op : C->operands())
if (OnlyUsedBy(Op, C))
Operands.insert(cast<Constant>(Op));
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (!GV->hasLocalLinkage()) return; // Don't delete non-static globals.
GV->eraseFromParent();