From e0f0c0e247b29b9ec57dbd710608fa7132f5b504 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 30 Apr 2016 18:15:34 +0000 Subject: [PATCH] CodeGen: convert to range based loops Convert to using some range based loops, avoid unnecessary variables for unchecked casts. NFC. llvm-svn: 268165 --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 56 ++++++++--------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index a462655..d540ea7d 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -490,10 +490,7 @@ emitModuleFlags(MCStreamer &Streamer, MDNode *LinkerOptions = nullptr; StringRef SectionVal; - for (ArrayRef::iterator - i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) { - const Module::ModuleFlagEntry &MFE = *i; - + for (const auto &MFE : ModuleFlags) { // Ignore flags with 'Require' behavior. if (MFE.Behavior == Module::Require) continue; @@ -518,16 +515,10 @@ emitModuleFlags(MCStreamer &Streamer, // Emit the linker options if present. if (LinkerOptions) { - for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { - MDNode *MDOptions = cast(LinkerOptions->getOperand(i)); + for (const auto &Option : LinkerOptions->operands()) { SmallVector StrOptions; - - // Convert to strings. - for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { - MDString *MDOption = cast(MDOptions->getOperand(ii)); - StrOptions.push_back(MDOption->getString()); - } - + for (const auto &Piece : cast(Option)->operands()) + StrOptions.push_back(cast(Piece)->getString()); Streamer.EmitLinkerOptions(StrOptions); } } @@ -1051,32 +1042,25 @@ emitModuleFlags(MCStreamer &Streamer, Mangler &Mang, const TargetMachine &TM) const { MDNode *LinkerOptions = nullptr; - // Look for the "Linker Options" flag, since it's the only one we support. - for (ArrayRef::iterator - i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) { - const Module::ModuleFlagEntry &MFE = *i; + for (const auto &MFE : ModuleFlags) { StringRef Key = MFE.Key->getString(); - Metadata *Val = MFE.Val; - if (Key == "Linker Options") { - LinkerOptions = cast(Val); - break; - } + if (Key == "Linker Options") + LinkerOptions = cast(MFE.Val); } - if (!LinkerOptions) - return; - // Emit the linker options to the linker .drectve section. According to the - // spec, this section is a space-separated string containing flags for linker. - MCSection *Sec = getDrectveSection(); - Streamer.SwitchSection(Sec); - for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { - MDNode *MDOptions = cast(LinkerOptions->getOperand(i)); - for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { - MDString *MDOption = cast(MDOptions->getOperand(ii)); - // Lead with a space for consistency with our dllexport implementation. - std::string Directive(" "); - Directive.append(MDOption->getString()); - Streamer.EmitBytes(Directive); + if (LinkerOptions) { + // Emit the linker options to the linker .drectve section. According to the + // spec, this section is a space-separated string containing flags for + // linker. + MCSection *Sec = getDrectveSection(); + Streamer.SwitchSection(Sec); + for (const auto &Option : LinkerOptions->operands()) { + for (const auto &Piece : cast(Option)->operands()) { + // Lead with a space for consistency with our dllexport implementation. + std::string Directive(" "); + Directive.append(cast(Piece)->getString()); + Streamer.EmitBytes(Directive); + } } } } -- 2.7.4