Iterate over StringMaps using structured bindings. NFCI.

This commit is contained in:
Benjamin Kramer 2022-12-04 18:36:41 +01:00
parent 02c75e8465
commit fcf4e360ba
8 changed files with 25 additions and 28 deletions

View File

@ -815,10 +815,8 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
IdentifierIndexWriterTrait Trait; IdentifierIndexWriterTrait Trait;
// Populate the hash table. // Populate the hash table.
for (InterestingIdentifierMap::iterator I = InterestingIdentifiers.begin(), for (auto &[Identifier, IDs] : InterestingIdentifiers) {
IEnd = InterestingIdentifiers.end(); Generator.insert(Identifier, IDs, Trait);
I != IEnd; ++I) {
Generator.insert(I->first(), I->second, Trait);
} }
// Create the on-disk hash table in a buffer. // Create the on-disk hash table in a buffer.

View File

@ -405,8 +405,8 @@ public:
/// Sort call targets in descending order of call frequency. /// Sort call targets in descending order of call frequency.
static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets) { static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets) {
SortedCallTargetSet SortedTargets; SortedCallTargetSet SortedTargets;
for (const auto &I : Targets) { for (const auto &[Target, Frequency] : Targets) {
SortedTargets.emplace(I.first(), I.second); SortedTargets.emplace(Target, Frequency);
} }
return SortedTargets; return SortedTargets;
} }
@ -415,8 +415,8 @@ public:
static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets, static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets,
float DistributionFactor) { float DistributionFactor) {
CallTargetMap AdjustedTargets; CallTargetMap AdjustedTargets;
for (const auto &I : Targets) { for (const auto &[Target, Frequency] : Targets) {
AdjustedTargets[I.first()] = I.second * DistributionFactor; AdjustedTargets[Target] = Frequency * DistributionFactor;
} }
return AdjustedTargets; return AdjustedTargets;
} }

View File

@ -159,9 +159,9 @@ private:
addProfiledFunction(Samples.getFuncName()); addProfiledFunction(Samples.getFuncName());
for (const auto &Sample : Samples.getBodySamples()) { for (const auto &Sample : Samples.getBodySamples()) {
for (const auto &Target : Sample.second.getCallTargets()) { for (const auto &[Target, Frequency] : Sample.second.getCallTargets()) {
addProfiledFunction(Target.first()); addProfiledFunction(Target);
addProfiledCall(Samples.getFuncName(), Target.first(), Target.second); addProfiledCall(Samples.getFuncName(), Target, Frequency);
} }
} }

View File

@ -592,8 +592,8 @@ std::string codegen::getFeaturesStr() {
if (getMCPU() == "native") { if (getMCPU() == "native") {
StringMap<bool> HostFeatures; StringMap<bool> HostFeatures;
if (sys::getHostCPUFeatures(HostFeatures)) if (sys::getHostCPUFeatures(HostFeatures))
for (auto &F : HostFeatures) for (const auto &[Feature, IsEnabled] : HostFeatures)
Features.AddFeature(F.first(), F.second); Features.AddFeature(Feature, IsEnabled);
} }
for (auto const &MAttr : getMAttrs()) for (auto const &MAttr : getMAttrs())
@ -612,8 +612,8 @@ std::vector<std::string> codegen::getFeatureList() {
if (getMCPU() == "native") { if (getMCPU() == "native") {
StringMap<bool> HostFeatures; StringMap<bool> HostFeatures;
if (sys::getHostCPUFeatures(HostFeatures)) if (sys::getHostCPUFeatures(HostFeatures))
for (auto &F : HostFeatures) for (const auto &[Feature, IsEnabled] : HostFeatures)
Features.AddFeature(F.first(), F.second); Features.AddFeature(Feature, IsEnabled);
} }
for (auto const &MAttr : getMAttrs()) for (auto const &MAttr : getMAttrs())

View File

@ -1059,8 +1059,8 @@ int SlotTracker::processIndex() {
// assigned consecutively. Since the StringMap iteration order isn't // assigned consecutively. Since the StringMap iteration order isn't
// guaranteed, use a std::map to order by module ID before assigning slots. // guaranteed, use a std::map to order by module ID before assigning slots.
std::map<uint64_t, StringRef> ModuleIdToPathMap; std::map<uint64_t, StringRef> ModuleIdToPathMap;
for (auto &ModPath : TheIndex->modulePaths()) for (auto &[ModPath, ModId] : TheIndex->modulePaths())
ModuleIdToPathMap[ModPath.second.first] = ModPath.first(); ModuleIdToPathMap[ModId.first] = ModPath;
for (auto &ModPair : ModuleIdToPathMap) for (auto &ModPair : ModuleIdToPathMap)
CreateModulePathSlot(ModPair.second); CreateModulePathSlot(ModPair.second);
@ -2875,13 +2875,12 @@ void AssemblyWriter::printModuleSummaryIndex() {
std::string RegularLTOModuleName = std::string RegularLTOModuleName =
ModuleSummaryIndex::getRegularLTOModuleName(); ModuleSummaryIndex::getRegularLTOModuleName();
moduleVec.resize(TheIndex->modulePaths().size()); moduleVec.resize(TheIndex->modulePaths().size());
for (auto &ModPath : TheIndex->modulePaths()) for (auto &[ModPath, ModId] : TheIndex->modulePaths())
moduleVec[Machine.getModulePathSlot(ModPath.first())] = std::make_pair( moduleVec[Machine.getModulePathSlot(ModPath)] = std::make_pair(
// A module id of -1 is a special entry for a regular LTO module created // A module id of -1 is a special entry for a regular LTO module created
// during the thin link. // during the thin link.
ModPath.second.first == -1u ? RegularLTOModuleName ModId.first == -1u ? RegularLTOModuleName : std::string(ModPath),
: (std::string)std::string(ModPath.first()), ModId.second);
ModPath.second.second);
unsigned i = 0; unsigned i = 0;
for (auto &ModPair : moduleVec) { for (auto &ModPair : moduleVec) {

View File

@ -258,8 +258,8 @@ char *LLVMGetHostCPUFeatures(void) {
StringMap<bool> HostFeatures; StringMap<bool> HostFeatures;
if (sys::getHostCPUFeatures(HostFeatures)) if (sys::getHostCPUFeatures(HostFeatures))
for (auto &F : HostFeatures) for (const auto &[Feature, IsEnabled] : HostFeatures)
Features.AddFeature(F.first(), F.second); Features.AddFeature(Feature, IsEnabled);
return strdup(Features.getString().c_str()); return strdup(Features.getString().c_str());
} }

View File

@ -88,8 +88,8 @@ LogicalResult PatternApplicatorExtension::findAllMatches(
// also used by the following operations. // also used by the following operations.
auto *dialect = auto *dialect =
root->getContext()->getLoadedDialect<transform::TransformDialect>(); root->getContext()->getLoadedDialect<transform::TransformDialect>();
for (const auto &pair : dialect->getPDLConstraintHooks()) for (const auto &[name, constraintFn] : dialect->getPDLConstraintHooks())
patternModule.registerConstraintFunction(pair.first(), pair.second); patternModule.registerConstraintFunction(name, constraintFn);
// Register a noop rewriter because PDL requires patterns to end with some // Register a noop rewriter because PDL requires patterns to end with some
// rewrite call. // rewrite call.

View File

@ -145,8 +145,8 @@ bool ExecutionEngine::setupTargetTriple(Module *llvmModule) {
llvm::StringMap<bool> hostFeatures; llvm::StringMap<bool> hostFeatures;
if (llvm::sys::getHostCPUFeatures(hostFeatures)) if (llvm::sys::getHostCPUFeatures(hostFeatures))
for (auto &f : hostFeatures) for (const auto &[feature, isEnabled] : hostFeatures)
features.AddFeature(f.first(), f.second); features.AddFeature(feature, isEnabled);
std::unique_ptr<llvm::TargetMachine> machine(target->createTargetMachine( std::unique_ptr<llvm::TargetMachine> machine(target->createTargetMachine(
targetTriple, cpu, features.getString(), {}, {})); targetTriple, cpu, features.getString(), {}, {}));