r208354 - [Driver] Range-based loop simplification.
Simon Atanasyan
simon at atanasyan.com
Thu May 8 12:32:46 PDT 2014
Author: atanasyan
Date: Thu May 8 14:32:46 2014
New Revision: 208354
URL: http://llvm.org/viewvc/llvm-project?rev=208354&view=rev
Log:
[Driver] Range-based loop simplification.
Modified:
cfe/trunk/lib/Driver/Multilib.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
Modified: cfe/trunk/lib/Driver/Multilib.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Multilib.cpp?rev=208354&r1=208353&r2=208354&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Multilib.cpp (original)
+++ cfe/trunk/lib/Driver/Multilib.cpp Thu May 8 14:32:46 2014
@@ -90,10 +90,9 @@ void Multilib::print(raw_ostream &OS) co
OS << StringRef(GCCSuffix).drop_front();
}
OS << ";";
- for (flags_list::const_iterator I = Flags.begin(), E = Flags.end(); I != E;
- ++I) {
- if (StringRef(*I).front() == '+')
- OS << "@" << I->substr(1);
+ for (StringRef Flag : Flags) {
+ if (Flag.front() == '+')
+ OS << "@" << Flag.substr(1);
}
}
@@ -117,16 +116,12 @@ bool Multilib::operator==(const Multilib
// Check whether the flags sets match
// allowing for the match to be order invariant
llvm::StringSet<> MyFlags;
- for (flags_list::const_iterator I = Flags.begin(), E = Flags.end(); I != E;
- ++I) {
- MyFlags.insert(*I);
- }
- for (flags_list::const_iterator I = Other.Flags.begin(),
- E = Other.Flags.end();
- I != E; ++I) {
- if (MyFlags.find(*I) == MyFlags.end())
+ for (const auto &Flag : Flags)
+ MyFlags.insert(Flag);
+
+ for (const auto &Flag : Other.Flags)
+ if (MyFlags.find(Flag) == MyFlags.end())
return false;
- }
if (osSuffix() != Other.osSuffix())
return false;
@@ -148,10 +143,7 @@ raw_ostream &clang::driver::operator<<(r
MultilibSet &MultilibSet::Maybe(const Multilib &M) {
Multilib Opposite;
// Negate any '+' flags
- for (Multilib::flags_list::const_iterator I = M.flags().begin(),
- E = M.flags().end();
- I != E; ++I) {
- StringRef Flag(*I);
+ for (StringRef Flag : M.flags()) {
if (Flag.front() == '+')
Opposite.flags().push_back(("-" + Flag.substr(1)).str());
}
@@ -223,12 +215,9 @@ MultilibSet::Either(const std::vector<Mu
Multilibs.insert(Multilibs.end(), MultilibSegments.begin(),
MultilibSegments.end());
else {
- for (std::vector<Multilib>::const_iterator NewI = MultilibSegments.begin(),
- NewE = MultilibSegments.end();
- NewI != NewE; ++NewI) {
- for (const_iterator BaseI = begin(), BaseE = end(); BaseI != BaseE;
- ++BaseI) {
- Multilib MO = compose(*BaseI, *NewI);
+ for (const Multilib &New : MultilibSegments) {
+ for (const Multilib &Base : *this) {
+ Multilib MO = compose(Base, New);
if (MO.isValid())
Composed.push_back(MO);
}
@@ -282,20 +271,14 @@ bool MultilibSet::select(const Multilib:
// Stuff all of the flags into the FlagSet such that a true mappend
// indicates the flag was enabled, and a false mappend indicates the
// flag was disabled
- for (Multilib::flags_list::const_iterator I = Flags.begin(),
- E = Flags.end();
- I != E; ++I) {
- FlagSet[StringRef(*I).substr(1)] = isFlagEnabled(*I);
- }
+ for (StringRef Flag : Flags)
+ FlagSet[Flag.substr(1)] = isFlagEnabled(Flag);
}
bool operator()(const Multilib &M) const override {
- for (Multilib::flags_list::const_iterator I = M.flags().begin(),
- E = M.flags().end();
- I != E; ++I) {
- StringRef Flag(*I);
+ for (StringRef Flag : M.flags()) {
llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
if (SI != FlagSet.end())
- if ((*SI).getValue() != isFlagEnabled(Flag))
+ if (SI->getValue() != isFlagEnabled(Flag))
return true;
}
return false;
@@ -326,8 +309,8 @@ bool MultilibSet::select(const Multilib:
}
void MultilibSet::print(raw_ostream &OS) const {
- for (const_iterator I = begin(), E = end(); I != E; ++I)
- OS << *I << "\n";
+ for (const Multilib &M : *this)
+ OS << M << "\n";
}
MultilibSet::multilib_list
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=208354&r1=208353&r2=208354&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu May 8 14:32:46 2014
@@ -680,10 +680,7 @@ DerivedArgList *MachO::TranslateArgs(con
// have something that works, we should reevaluate each translation
// and try to push it down into tool specific logic.
- for (ArgList::const_iterator it = Args.begin(),
- ie = Args.end(); it != ie; ++it) {
- Arg *A = *it;
-
+ for (Arg *A : Args) {
if (A->getOption().matches(options::OPT_Xarch__)) {
// Skip this argument unless the architecture matches either the toolchain
// triple arch, or the arch being bound.
@@ -1285,19 +1282,14 @@ Generic_GCC::GCCInstallationDetector::in
}
void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const {
- for (std::set<std::string>::const_iterator
- I = CandidateGCCInstallPaths.begin(),
- E = CandidateGCCInstallPaths.end();
- I != E; ++I)
- OS << "Found candidate GCC installation: " << *I << "\n";
+ for (const auto &InstallPath : CandidateGCCInstallPaths)
+ OS << "Found candidate GCC installation: " << InstallPath << "\n";
if (!GCCInstallPath.empty())
OS << "Selected GCC installation: " << GCCInstallPath << "\n";
- for (MultilibSet::const_iterator I = Multilibs.begin(), E = Multilibs.end();
- I != E; ++I) {
- OS << "Candidate multilib: " << *I << "\n";
- }
+ for (const auto &Multilib : Multilibs)
+ OS << "Candidate multilib: " << Multilib << "\n";
if (Multilibs.size() != 0 || !SelectedMultilib.isDefault())
OS << "Selected multilib: " << SelectedMultilib << "\n";
@@ -3188,10 +3180,9 @@ void Linux::AddClangSystemIncludeArgs(co
if (CIncludeDirs != "") {
SmallVector<StringRef, 5> dirs;
CIncludeDirs.split(dirs, ":");
- for (SmallVectorImpl<StringRef>::iterator I = dirs.begin(), E = dirs.end();
- I != E; ++I) {
- StringRef Prefix = llvm::sys::path::is_absolute(*I) ? SysRoot : "";
- addExternCSystemInclude(DriverArgs, CC1Args, Prefix + *I);
+ for (StringRef dir : dirs) {
+ StringRef Prefix = llvm::sys::path::is_absolute(dir) ? SysRoot : "";
+ addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
}
return;
}
@@ -3278,11 +3269,9 @@ void Linux::AddClangSystemIncludeArgs(co
} else if (getTriple().getArch() == llvm::Triple::ppc64) {
MultiarchIncludeDirs = PPC64MultiarchIncludeDirs;
}
- for (ArrayRef<StringRef>::iterator I = MultiarchIncludeDirs.begin(),
- E = MultiarchIncludeDirs.end();
- I != E; ++I) {
- if (llvm::sys::fs::exists(SysRoot + *I)) {
- addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + *I);
+ for (StringRef Dir : MultiarchIncludeDirs) {
+ if (llvm::sys::fs::exists(SysRoot + Dir)) {
+ addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir);
break;
}
}
@@ -3345,12 +3334,11 @@ void Linux::AddClangCXXStdlibIncludeArgs
// FIXME: We should really remove this. It doesn't make any sense.
getDriver().SysRoot + "/usr/include/c++/v1"
};
- for (unsigned i = 0; i < llvm::array_lengthof(LibCXXIncludePathCandidates);
- ++i) {
- if (!llvm::sys::fs::exists(LibCXXIncludePathCandidates[i]))
+ for (const auto &IncludePath : LibCXXIncludePathCandidates) {
+ if (!llvm::sys::fs::exists(IncludePath))
continue;
// Add the first candidate that exists.
- addSystemInclude(DriverArgs, CC1Args, LibCXXIncludePathCandidates[i]);
+ addSystemInclude(DriverArgs, CC1Args, IncludePath);
break;
}
return;
@@ -3388,9 +3376,8 @@ void Linux::AddClangCXXStdlibIncludeArgs
LibDir.str() + "/../include/c++",
};
- for (unsigned i = 0; i < llvm::array_lengthof(LibStdCXXIncludePathCandidates);
- ++i) {
- if (addLibStdCXXIncludePaths(LibStdCXXIncludePathCandidates[i],
+ for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
+ if (addLibStdCXXIncludePaths(IncludePath,
TripleStr + Multilib.includeSuffix(),
DriverArgs, CC1Args))
break;
More information about the cfe-commits
mailing list