[llvm] [ExecutionEngine] Use range-based for loops (NFC) (PR #98110)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 9 05:05:10 PDT 2024
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/98110
>From fccef82cd01780b194162663bbcfb4bcf0502f54 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 8 Jul 2024 18:45:55 -0700
Subject: [PATCH] [ExecutionEngine] Use range-based for loops (NFC)
---
llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 24 +++++++++----------
.../RuntimeDyld/RuntimeDyld.cpp | 3 +--
.../RuntimeDyld/RuntimeDyldELF.cpp | 3 +--
3 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index 28e4f96df828c..8297d15b1580e 100644
--- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -151,8 +151,8 @@ bool ExecutionEngine::removeModule(Module *M) {
}
Function *ExecutionEngine::FindFunctionNamed(StringRef FnName) {
- for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
- Function *F = Modules[i]->getFunction(FnName);
+ for (const auto &M : Modules) {
+ Function *F = M->getFunction(FnName);
if (F && !F->isDeclaration())
return F;
}
@@ -160,8 +160,8 @@ Function *ExecutionEngine::FindFunctionNamed(StringRef FnName) {
}
GlobalVariable *ExecutionEngine::FindGlobalVariableNamed(StringRef Name, bool AllowInternal) {
- for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
- GlobalVariable *GV = Modules[i]->getGlobalVariable(Name,AllowInternal);
+ for (const auto &M : Modules) {
+ GlobalVariable *GV = M->getGlobalVariable(Name, AllowInternal);
if (GV && !GV->isDeclaration())
return GV;
}
@@ -314,8 +314,8 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
if (I != EEState.getGlobalAddressReverseMap().end()) {
StringRef Name = I->second;
- for (unsigned i = 0, e = Modules.size(); i != e; ++i)
- if (GlobalValue *GV = Modules[i]->getNamedValue(Name))
+ for (const auto &M : Modules)
+ if (GlobalValue *GV = M->getNamedValue(Name))
return GV;
}
return nullptr;
@@ -1219,9 +1219,8 @@ void ExecutionEngine::emitGlobals() {
const GlobalValue*> LinkedGlobalsMap;
if (Modules.size() != 1) {
- for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
- Module &M = *Modules[m];
- for (const auto &GV : M.globals()) {
+ for (const auto &M : Modules) {
+ for (const auto &GV : M->globals()) {
if (GV.hasLocalLinkage() || GV.isDeclaration() ||
GV.hasAppendingLinkage() || !GV.hasName())
continue;// Ignore external globals and globals with internal linkage.
@@ -1249,9 +1248,8 @@ void ExecutionEngine::emitGlobals() {
}
std::vector<const GlobalValue*> NonCanonicalGlobals;
- for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
- Module &M = *Modules[m];
- for (const auto &GV : M.globals()) {
+ for (const auto &M : Modules) {
+ for (const auto &GV : M->globals()) {
// In the multi-module case, see what this global maps to.
if (!LinkedGlobalsMap.empty()) {
if (const GlobalValue *GVEntry = LinkedGlobalsMap[std::make_pair(
@@ -1293,7 +1291,7 @@ void ExecutionEngine::emitGlobals() {
// Now that all of the globals are set up in memory, loop through them all
// and initialize their contents.
- for (const auto &GV : M.globals()) {
+ for (const auto &GV : M->globals()) {
if (!GV.isDeclaration()) {
if (!LinkedGlobalsMap.empty()) {
if (const GlobalValue *GVEntry = LinkedGlobalsMap[std::make_pair(
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 79a190f447879..7eb7da0138c97 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -1097,8 +1097,7 @@ void RuntimeDyldImpl::reassignSectionAddress(unsigned SectionID,
void RuntimeDyldImpl::resolveRelocationList(const RelocationList &Relocs,
uint64_t Value) {
- for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
- const RelocationEntry &RE = Relocs[i];
+ for (const RelocationEntry &RE : Relocs) {
// Ignore relocations for sections that were not loaded
if (RE.SectionID != AbsoluteSymbolSection &&
Sections[RE.SectionID].getAddress() == nullptr)
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index f44a6a472cb63..736d9a3e056f1 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -220,8 +220,7 @@ RuntimeDyldELF::RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr,
RuntimeDyldELF::~RuntimeDyldELF() = default;
void RuntimeDyldELF::registerEHFrames() {
- for (int i = 0, e = UnregisteredEHFrameSections.size(); i != e; ++i) {
- SID EHFrameSID = UnregisteredEHFrameSections[i];
+ for (SID EHFrameSID : UnregisteredEHFrameSections) {
uint8_t *EHFrameAddr = Sections[EHFrameSID].getAddress();
uint64_t EHFrameLoadAddr = Sections[EHFrameSID].getLoadAddress();
size_t EHFrameSize = Sections[EHFrameSID].getSize();
More information about the llvm-commits
mailing list