Skip to content

Commit 7294854

Browse files
committed
Refactor code
1 parent 489b11c commit 7294854

File tree

4 files changed

+62
-73
lines changed

4 files changed

+62
-73
lines changed

llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/LibraryScanner.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ struct SearchPathConfig {
232232
class SearchPathResolver {
233233
public:
234234
SearchPathResolver(const SearchPathConfig &Cfg,
235-
StringRef placeholderPrefix = "")
236-
: Kind(Cfg.type), placeholderPrefix(placeholderPrefix) {
235+
StringRef PlaceholderPrefix = "")
236+
: Kind(Cfg.type), PlaceholderPrefix(PlaceholderPrefix) {
237237
for (auto &path : Cfg.Paths)
238238
Paths.emplace_back(path.str());
239239
}
@@ -246,7 +246,7 @@ class SearchPathResolver {
246246
private:
247247
std::vector<std::string> Paths;
248248
SearchPathType Kind;
249-
std::string placeholderPrefix;
249+
std::string PlaceholderPrefix;
250250
};
251251

252252
class DylibResolverImpl {
@@ -256,8 +256,8 @@ class DylibResolverImpl {
256256
: Substitutor(std::move(Substitutor)), Validator(Validator),
257257
Resolvers(std::move(Resolvers)) {}
258258

259-
std::optional<std::string> resolve(StringRef stem,
260-
bool variateLibStem = false) const;
259+
std::optional<std::string> resolve(StringRef Stem,
260+
bool VariateLibStem = false) const;
261261

262262
private:
263263
std::optional<std::string> tryWithExtensions(StringRef libstem) const;
@@ -287,10 +287,10 @@ class DylibResolver {
287287
}
288288

289289
std::optional<std::string> resolve(StringRef libStem,
290-
bool variateLibStem = false) const {
290+
bool VariateLibStem = false) const {
291291
if (!impl_)
292292
return std::nullopt;
293-
return impl_->resolve(libStem, variateLibStem);
293+
return impl_->resolve(libStem, VariateLibStem);
294294
}
295295

296296
static std::string resolvelinkerFlag(StringRef libStem,

llvm/lib/ExecutionEngine/Orc/TargetProcess/LibraryResolver.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -202,35 +202,25 @@ void LibraryResolver::resolveSymbolsInLibrary(
202202
const SymbolEnumeratorOptions &Opts) {
203203
LLVM_DEBUG(dbgs() << "Checking unresolved symbols "
204204
<< " in library : " << Lib.getFileName() << "\n";);
205-
StringSet<> discoveredSymbols;
206-
bool hasEnumerated = false;
207-
208-
auto enumerateSymbolsIfNeeded = [&]() {
209-
if (hasEnumerated)
210-
return;
211-
212-
hasEnumerated = true;
213-
214-
LLVM_DEBUG(dbgs() << "Enumerating symbols in library: " << Lib.getFullPath()
215-
<< "\n";);
216-
SymbolEnumerator::enumerateSymbols(
217-
Lib.getFullPath(),
218-
[&](StringRef sym) {
219-
discoveredSymbols.insert(sym);
220-
return EnumerateResult::Continue;
221-
},
222-
Opts);
223-
};
205+
StringSet<> DiscoveredSymbols;
224206

225207
if (!UnresolvedSymbols.hasUnresolved()) {
226208
LLVM_DEBUG(dbgs() << "Skipping library: " << Lib.getFullPath()
227209
<< " — unresolved symbols exist.\n";);
228210
return;
229211
}
230212

231-
enumerateSymbolsIfNeeded();
213+
LLVM_DEBUG(dbgs() << "Enumerating symbols in library: " << Lib.getFullPath()
214+
<< "\n";);
215+
SymbolEnumerator::enumerateSymbols(
216+
Lib.getFullPath(),
217+
[&](StringRef sym) {
218+
DiscoveredSymbols.insert(sym);
219+
return EnumerateResult::Continue;
220+
},
221+
Opts);
232222

233-
if (discoveredSymbols.empty()) {
223+
if (DiscoveredSymbols.empty()) {
234224
LLVM_DEBUG(dbgs() << " No symbols and remove library : "
235225
<< Lib.getFullPath() << "\n";);
236226
LibMgr.removeLibrary(Lib.getFullPath());
@@ -242,37 +232,37 @@ void LibraryResolver::resolveSymbolsInLibrary(
242232
<< "\n";);
243233

244234
SmallVector<StringRef> SymbolVec;
245-
SymbolVec.reserve(discoveredSymbols.size());
246-
for (const auto &KV : discoveredSymbols)
235+
SymbolVec.reserve(DiscoveredSymbols.size());
236+
for (const auto &KV : DiscoveredSymbols)
247237
SymbolVec.push_back(KV.first());
248238

249239
Lib.ensureFilterBuilt(FB, SymbolVec);
250240
LLVM_DEBUG({
251-
dbgs() << "discoveredSymbols : " << discoveredSymbols.size() << "\n";
252-
for (const auto &KV : discoveredSymbols)
253-
dbgs() << "discoveredSymbols : " << KV.first() << "\n";
241+
dbgs() << "DiscoveredSymbols : " << DiscoveredSymbols.size() << "\n";
242+
for (const auto &KV : DiscoveredSymbols)
243+
dbgs() << "DiscoveredSymbols : " << KV.first() << "\n";
254244
});
255245
}
256246

257247
const auto &Unresolved = UnresolvedSymbols.getUnresolvedSymbols();
258-
bool hadAnySym = false;
248+
bool HadAnySym = false;
259249
LLVM_DEBUG(dbgs() << "Total unresolved symbols : " << Unresolved.size()
260250
<< "\n";);
261251
for (const auto &Sym : Unresolved) {
262252
if (Lib.mayContain(Sym)) {
263253
LLVM_DEBUG(dbgs() << "Checking symbol '" << Sym
264254
<< "' in library: " << Lib.getFullPath() << "\n";);
265-
if (discoveredSymbols.count(Sym) > 0) {
255+
if (DiscoveredSymbols.count(Sym) > 0) {
266256
LLVM_DEBUG(dbgs() << " Resolved symbol: " << Sym
267257
<< " in library: " << Lib.getFullPath() << "\n";);
268258
UnresolvedSymbols.resolve(Sym, Lib.getFullPath());
269-
hadAnySym = true;
259+
HadAnySym = true;
270260
}
271261
}
272262
}
273263

274264
using LibraryState = LibraryManager::LibState;
275-
if (hadAnySym && Lib.getState() != LibraryState::Loaded)
265+
if (HadAnySym && Lib.getState() != LibraryState::Loaded)
276266
Lib.setState(LibraryState::Queried);
277267
}
278268

llvm/lib/ExecutionEngine/Orc/TargetProcess/LibraryScanner.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ bool DylibPathValidator::isSharedLibrary(StringRef Path) {
219219
LLVM_DEBUG(dbgs() << "Checking if path is a shared library: " << Path
220220
<< "\n";);
221221

222-
auto filetype = sys::fs::get_file_type(Path, /*Follow*/ true);
223-
if (filetype != sys::fs::file_type::regular_file) {
222+
auto FileType = sys::fs::get_file_type(Path, /*Follow*/ true);
223+
if (FileType != sys::fs::file_type::regular_file) {
224224
LLVM_DEBUG(dbgs() << "File type is not a regular file for path: " << Path
225225
<< "\n";);
226226
return false;
@@ -303,13 +303,13 @@ void DylibSubstitutor::configure(StringRef LoaderPath) {
303303
std::optional<std::string>
304304
SearchPathResolver::resolve(StringRef Stem, const DylibSubstitutor &Subst,
305305
DylibPathValidator &Validator) const {
306-
for (const auto &searchPath : Paths) {
307-
std::string Base = Subst.substitute(searchPath);
306+
for (const auto &SP : Paths) {
307+
std::string Base = Subst.substitute(SP);
308308

309309
SmallString<512> FullPath(Base);
310-
if (!placeholderPrefix.empty() &&
311-
Stem.starts_with_insensitive(placeholderPrefix))
312-
FullPath.append(Stem.drop_front(placeholderPrefix.size()));
310+
if (!PlaceholderPrefix.empty() &&
311+
Stem.starts_with_insensitive(PlaceholderPrefix))
312+
FullPath.append(Stem.drop_front(PlaceholderPrefix.size()));
313313
else
314314
sys::path::append(FullPath, Stem);
315315

@@ -341,24 +341,24 @@ DylibResolverImpl::tryWithExtensions(StringRef LibStem) const {
341341
#endif
342342

343343
// Optionally try "lib" prefix if not already there
344-
StringRef filename = sys::path::filename(LibStem);
344+
StringRef FileName = sys::path::filename(LibStem);
345345
StringRef Base = sys::path::parent_path(LibStem);
346-
if (!filename.starts_with("lib")) {
347-
SmallString<256> withPrefix(Base);
348-
if (!withPrefix.empty())
349-
sys::path::append(withPrefix, ""); // ensure separator if needed
350-
withPrefix += "lib";
351-
withPrefix += filename;
346+
if (!FileName.starts_with("lib")) {
347+
SmallString<256> WithPrefix(Base);
348+
if (!WithPrefix.empty())
349+
sys::path::append(WithPrefix, ""); // ensure separator if needed
350+
WithPrefix += "lib";
351+
WithPrefix += FileName;
352352

353353
#if defined(__APPLE__)
354-
withPrefix += ".dylib";
354+
WithPrefix += ".dylib";
355355
#elif defined(_WIN32)
356-
withPrefix += ".dll";
356+
WithPrefix += ".dll";
357357
#else
358-
withPrefix += ".so";
358+
WithPrefix += ".so";
359359
#endif
360360

361-
Candidates.push_back(std::move(withPrefix));
361+
Candidates.push_back(std::move(WithPrefix));
362362
}
363363

364364
LLVM_DEBUG({
@@ -373,8 +373,8 @@ DylibResolverImpl::tryWithExtensions(StringRef LibStem) const {
373373
LLVM_DEBUG(dbgs() << " Trying candidate: " << Name << "\n";);
374374

375375
for (const auto &R : Resolvers) {
376-
if (auto result = R.resolve(Name, Substitutor, Validator))
377-
return result;
376+
if (auto Res = R.resolve(Name, Substitutor, Validator))
377+
return Res;
378378
}
379379
}
380380

@@ -384,7 +384,7 @@ DylibResolverImpl::tryWithExtensions(StringRef LibStem) const {
384384
}
385385

386386
std::optional<std::string>
387-
DylibResolverImpl::resolve(StringRef LibStem, bool variateLibStem) const {
387+
DylibResolverImpl::resolve(StringRef LibStem, bool VariateLibStem) const {
388388
LLVM_DEBUG(dbgs() << "Resolving library stem: " << LibStem << "\n";);
389389

390390
// If it is an absolute path, don't try iterate over the paths.
@@ -404,24 +404,24 @@ DylibResolverImpl::resolve(StringRef LibStem, bool variateLibStem) const {
404404

405405
for (const auto &R : Resolvers) {
406406
LLVM_DEBUG(dbgs() << " -> Resolving via search path ... \n";);
407-
if (auto result = R.resolve(LibStem, Substitutor, Validator)) {
408-
LLVM_DEBUG(dbgs() << " -> Resolved via search path: " << *result
407+
if (auto Result = R.resolve(LibStem, Substitutor, Validator)) {
408+
LLVM_DEBUG(dbgs() << " -> Resolved via search path: " << *Result
409409
<< "\n";);
410410

411-
return result;
411+
return Result;
412412
}
413413
}
414414

415415
// Expand libStem with paths, extensions, etc.
416416
// std::string foundName;
417-
if (variateLibStem) {
417+
if (VariateLibStem) {
418418
LLVM_DEBUG(dbgs() << " -> Trying with extensions...\n";);
419419

420-
if (auto norm = tryWithExtensions(LibStem)) {
421-
LLVM_DEBUG(dbgs() << " -> Resolved via tryWithExtensions: " << *norm
420+
if (auto Norm = tryWithExtensions(LibStem)) {
421+
LLVM_DEBUG(dbgs() << " -> Resolved via tryWithExtensions: " << *Norm
422422
<< "\n";);
423423

424-
return norm;
424+
return Norm;
425425
}
426426
}
427427

@@ -433,8 +433,8 @@ DylibResolverImpl::resolve(StringRef LibStem, bool variateLibStem) const {
433433
#ifndef _WIN32
434434
mode_t PathResolver::lstatCached(StringRef Path) {
435435
// If already cached - retun cached result
436-
if (auto cache = LibPathCache->read_lstat(Path))
437-
return *cache;
436+
if (auto Cache = LibPathCache->read_lstat(Path))
437+
return *Cache;
438438

439439
// Not cached: perform lstat and store
440440
struct stat buf{};
@@ -447,8 +447,8 @@ mode_t PathResolver::lstatCached(StringRef Path) {
447447

448448
std::optional<std::string> PathResolver::readlinkCached(StringRef Path) {
449449
// If already cached - retun cached result
450-
if (auto cache = LibPathCache->read_link(Path))
451-
return cache;
450+
if (auto Cache = LibPathCache->read_link(Path))
451+
return Cache;
452452

453453
// If result not in cache - call system function and cache result
454454
char buf[PATH_MAX];
@@ -767,8 +767,8 @@ std::string LibraryScanHelper::resolveCanonical(StringRef Path,
767767

768768
PathType LibraryScanHelper::classifyKind(StringRef Path) const {
769769
// Detect home directory
770-
const char *home = getenv("HOME");
771-
if (home && Path.find(home) == 0)
770+
const char *Home = getenv("HOME");
771+
if (Home && Path.find(Home) == 0)
772772
return PathType::User;
773773

774774
static const std::array<std::string, 5> UserPrefixes = {

llvm/unittests/ExecutionEngine/Orc/LibraryResolverTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ Triple getTargetTriple() {
5353

5454
static bool CheckHostSupport() {
5555
auto Triple = getTargetTriple();
56-
if (!Triple.isOSBinFormatMachO() &&
57-
(!Triple.isOSBinFormatELF() || (!Triple.isX86() && !Triple.isAArch64())))
56+
if (!Triple.isOSBinFormatMachO())
5857
return false;
5958

6059
return true;

0 commit comments

Comments
 (0)