2017-11-11 08:08:50 +08:00
|
|
|
//===- ModuleManager.cpp - Module Manager ---------------------------------===//
|
2011-08-26 04:47:51 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-08-26 04:47:51 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the ModuleManager class, which manages a set of loaded
|
|
|
|
// modules for the ASTReader.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-11-11 08:08:50 +08:00
|
|
|
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "clang/Serialization/ModuleManager.h"
|
2017-11-11 08:08:50 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/LLVM.h"
|
2014-04-15 02:00:01 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2013-03-19 08:28:20 +08:00
|
|
|
#include "clang/Lex/ModuleMap.h"
|
2013-01-26 07:32:03 +08:00
|
|
|
#include "clang/Serialization/GlobalModuleIndex.h"
|
2019-03-10 01:33:56 +08:00
|
|
|
#include "clang/Serialization/InMemoryModuleCache.h"
|
2019-11-22 10:49:05 +08:00
|
|
|
#include "clang/Serialization/ModuleFile.h"
|
2018-12-12 10:53:59 +08:00
|
|
|
#include "clang/Serialization/PCHContainerOperations.h"
|
2017-11-11 08:08:50 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/iterator.h"
|
|
|
|
#include "llvm/Support/Chrono.h"
|
|
|
|
#include "llvm/Support/DOTGraphTraits.h"
|
|
|
|
#include "llvm/Support/ErrorOr.h"
|
|
|
|
#include "llvm/Support/GraphWriter.h"
|
2011-08-26 04:47:51 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2018-10-10 21:27:25 +08:00
|
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
2017-11-11 08:08:50 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2014-06-13 01:19:42 +08:00
|
|
|
#include <system_error>
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace serialization;
|
|
|
|
|
2017-08-31 14:26:43 +08:00
|
|
|
ModuleFile *ModuleManager::lookupByFileName(StringRef Name) const {
|
2019-08-02 05:31:56 +08:00
|
|
|
auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
|
|
|
|
/*CacheFailure=*/false);
|
2013-03-28 00:47:18 +08:00
|
|
|
if (Entry)
|
2019-08-02 05:31:56 +08:00
|
|
|
return lookup(*Entry);
|
2013-03-28 00:47:18 +08:00
|
|
|
|
2014-05-22 13:54:18 +08:00
|
|
|
return nullptr;
|
2013-03-28 00:47:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 14:26:43 +08:00
|
|
|
ModuleFile *ModuleManager::lookupByModuleName(StringRef Name) const {
|
|
|
|
if (const Module *Mod = HeaderSearchInfo.getModuleMap().findModule(Name))
|
|
|
|
if (const FileEntry *File = Mod->getASTFile())
|
|
|
|
return lookup(File);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-18 08:32:02 +08:00
|
|
|
ModuleFile *ModuleManager::lookup(const FileEntry *File) const {
|
|
|
|
auto Known = Modules.find(File);
|
2013-03-28 00:47:18 +08:00
|
|
|
if (Known == Modules.end())
|
2014-05-22 13:54:18 +08:00
|
|
|
return nullptr;
|
2013-03-28 00:47:18 +08:00
|
|
|
|
|
|
|
return Known->second;
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 03:16:31 +08:00
|
|
|
std::unique_ptr<llvm::MemoryBuffer>
|
|
|
|
ModuleManager::lookupBuffer(StringRef Name) {
|
2019-08-02 05:31:56 +08:00
|
|
|
auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
|
|
|
|
/*CacheFailure=*/false);
|
|
|
|
if (!Entry)
|
|
|
|
return nullptr;
|
|
|
|
return std::move(InMemoryBuffers[*Entry]);
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 05:34:28 +08:00
|
|
|
static bool checkSignature(ASTFileSignature Signature,
|
|
|
|
ASTFileSignature ExpectedSignature,
|
|
|
|
std::string &ErrorStr) {
|
|
|
|
if (!ExpectedSignature || Signature == ExpectedSignature)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ErrorStr =
|
|
|
|
Signature ? "signature mismatch" : "could not read module signature";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
static void updateModuleImports(ModuleFile &MF, ModuleFile *ImportedBy,
|
|
|
|
SourceLocation ImportLoc) {
|
|
|
|
if (ImportedBy) {
|
|
|
|
MF.ImportedBy.insert(ImportedBy);
|
|
|
|
ImportedBy->Imports.insert(&MF);
|
|
|
|
} else {
|
|
|
|
if (!MF.DirectlyImported)
|
|
|
|
MF.ImportLoc = ImportLoc;
|
|
|
|
|
|
|
|
MF.DirectlyImported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:28:20 +08:00
|
|
|
ModuleManager::AddModuleResult
|
2012-12-01 03:28:05 +08:00
|
|
|
ModuleManager::addModule(StringRef FileName, ModuleKind Type,
|
|
|
|
SourceLocation ImportLoc, ModuleFile *ImportedBy,
|
2013-03-19 08:28:20 +08:00
|
|
|
unsigned Generation,
|
|
|
|
off_t ExpectedSize, time_t ExpectedModTime,
|
2014-10-24 02:05:36 +08:00
|
|
|
ASTFileSignature ExpectedSignature,
|
2015-03-24 12:43:52 +08:00
|
|
|
ASTFileSignatureReader ReadSignature,
|
2013-03-19 08:28:20 +08:00
|
|
|
ModuleFile *&Module,
|
|
|
|
std::string &ErrorStr) {
|
2014-05-22 13:54:18 +08:00
|
|
|
Module = nullptr;
|
2013-03-19 08:28:20 +08:00
|
|
|
|
|
|
|
// Look for the file entry. This only fails if the expected size or
|
|
|
|
// modification time differ.
|
2020-10-21 06:11:52 +08:00
|
|
|
OptionalFileEntryRefDegradesToFileEntryPtr Entry;
|
2016-08-19 01:42:15 +08:00
|
|
|
if (Type == MK_ExplicitModule || Type == MK_PrebuiltModule) {
|
2014-11-21 13:37:20 +08:00
|
|
|
// If we're not expecting to pull this file out of the module cache, it
|
|
|
|
// might have a different mtime due to being moved across filesystems in
|
|
|
|
// a distributed build. The size must still match, though. (As must the
|
|
|
|
// contents, but we can't check that.)
|
|
|
|
ExpectedModTime = 0;
|
|
|
|
}
|
Modules: Invalidate out-of-date PCMs as they're discovered
Leverage the InMemoryModuleCache to invalidate a module the first time
it fails to import (and to lock a module as soon as it's built or
imported successfully). For implicit module builds, this optimizes
importing deep graphs where the leaf module is out-of-date; see example
near the end of the commit message.
Previously the cache finalized ("locked in") all modules imported so far
when starting a new module build. This was sufficient to prevent
loading two versions of the same module, but was somewhat arbitrary and
hard to reason about.
Now the cache explicitly tracks module state, where each module must be
one of:
- Unknown: module not in the cache (yet).
- Tentative: module in the cache, but not yet fully imported.
- ToBuild: module found on disk could not be imported; need to build.
- Final: module in the cache has been successfully built or imported.
Preventing repeated failed imports avoids variation in builds based on
shifting filesystem state. Now it's guaranteed that a module is loaded
from disk exactly once. It now seems safe to remove
FileManager::invalidateCache, but I'm leaving that for a later commit.
The new, precise logic uncovered a pre-existing problem in the cache:
the map key is the module filename, and different contexts use different
filenames for the same PCM file. (In particular, the test
Modules/relative-import-path.c does not build without this commit.
r223577 started using a relative path to describe a module's base
directory when importing it within another module. As a result, the
module cache sees an absolute path when (a) building the module or
importing it at the top-level, and a relative path when (b) importing
the module underneath another one.)
The "obvious" fix is to resolve paths using FileManager::getVirtualFile
and change the map key for the cache to a FileEntry, but some contexts
(particularly related to ASTUnit) have a shorter lifetime for their
FileManager than the InMemoryModuleCache. This is worth pursuing
further in a later commit; perhaps by tying together the FileManager and
InMemoryModuleCache lifetime, or moving the in-memory PCM storage into a
VFS layer.
For now, use the PCM's base directory as-written for constructing the
filename to check the ModuleCache.
Example
=======
To understand the build optimization, first consider the build of a
module graph TU -> A -> B -> C -> D with an empty cache:
TU builds A'
A' builds B'
B' builds C'
C' builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
If we build TU again, where A, B, C, and D are in the cache and D is
out-of-date, we would previously get this build:
TU imports A
imports B
imports C
imports D (out-of-date)
TU builds A'
A' imports B
imports C
imports D (out-of-date)
builds B'
B' imports C
imports D (out-of-date)
builds C'
C' imports D (out-of-date)
builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
After this commit, we'll immediateley invalidate A, B, C, and D when we
first observe that D is out-of-date, giving this build:
TU imports A
imports B
imports C
imports D (out-of-date)
TU builds A' // The same graph as an empty cache.
A' builds B'
B' builds C'
C' builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
The new build matches what we'd naively expect, pretty closely matching
the original build with the empty cache.
rdar://problem/48545366
llvm-svn: 355778
2019-03-10 01:44:01 +08:00
|
|
|
// Note: ExpectedSize and ExpectedModTime will be 0 for MK_ImplicitModule
|
|
|
|
// when using an ASTFileSignature.
|
2013-09-06 07:50:58 +08:00
|
|
|
if (lookupModuleFile(FileName, ExpectedSize, ExpectedModTime, Entry)) {
|
|
|
|
ErrorStr = "module file out of date";
|
2013-03-19 08:28:20 +08:00
|
|
|
return OutOfDate;
|
2013-09-06 07:50:58 +08:00
|
|
|
}
|
2013-03-19 08:28:20 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
if (!Entry && FileName != "-") {
|
2013-09-06 07:50:58 +08:00
|
|
|
ErrorStr = "module file not found";
|
2013-03-19 08:28:20 +08:00
|
|
|
return Missing;
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
2013-03-19 08:28:20 +08:00
|
|
|
|
2020-09-03 04:48:44 +08:00
|
|
|
// The ModuleManager's use of FileEntry nodes as the keys for its map of
|
|
|
|
// loaded modules is less than ideal. Uniqueness for FileEntry nodes is
|
|
|
|
// maintained by FileManager, which in turn uses inode numbers on hosts
|
|
|
|
// that support that. When coupled with the module cache's proclivity for
|
|
|
|
// turning over and deleting stale PCMs, this means entries for different
|
|
|
|
// module files can wind up reusing the same underlying inode. When this
|
|
|
|
// happens, subsequent accesses to the Modules map will disagree on the
|
|
|
|
// ModuleFile associated with a given file. In general, it is not sufficient
|
|
|
|
// to resolve this conundrum with a type like FileEntryRef that stores the
|
|
|
|
// name of the FileEntry node on first access because of path canonicalization
|
|
|
|
// issues. However, the paths constructed for implicit module builds are
|
|
|
|
// fully under Clang's control. We *can*, therefore, rely on their structure
|
|
|
|
// being consistent across operating systems and across subsequent accesses
|
|
|
|
// to the Modules map.
|
|
|
|
auto implicitModuleNamesMatch = [](ModuleKind Kind, const ModuleFile *MF,
|
|
|
|
const FileEntry *Entry) -> bool {
|
|
|
|
if (Kind != MK_ImplicitModule)
|
|
|
|
return true;
|
|
|
|
return Entry->getName() == MF->FileName;
|
|
|
|
};
|
|
|
|
|
2013-03-19 08:28:20 +08:00
|
|
|
// Check whether we already loaded this module, before
|
2017-01-29 07:22:40 +08:00
|
|
|
if (ModuleFile *ModuleEntry = Modules.lookup(Entry)) {
|
2020-09-03 04:48:44 +08:00
|
|
|
if (implicitModuleNamesMatch(Type, ModuleEntry, Entry)) {
|
|
|
|
// Check the stored signature.
|
|
|
|
if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr))
|
|
|
|
return OutOfDate;
|
|
|
|
|
|
|
|
Module = ModuleEntry;
|
|
|
|
updateModuleImports(*ModuleEntry, ImportedBy, ImportLoc);
|
|
|
|
return AlreadyLoaded;
|
|
|
|
}
|
2017-01-29 07:22:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a new module.
|
2019-08-15 07:04:18 +08:00
|
|
|
auto NewModule = std::make_unique<ModuleFile>(Type, Generation);
|
2017-01-29 07:22:40 +08:00
|
|
|
NewModule->Index = Chain.size();
|
|
|
|
NewModule->FileName = FileName.str();
|
|
|
|
NewModule->File = Entry;
|
|
|
|
NewModule->ImportLoc = ImportLoc;
|
|
|
|
NewModule->InputFilesValidationTimestamp = 0;
|
|
|
|
|
|
|
|
if (NewModule->Kind == MK_ImplicitModule) {
|
|
|
|
std::string TimestampFilename = NewModule->getTimestampFilename();
|
2018-10-10 21:27:25 +08:00
|
|
|
llvm::vfs::Status Status;
|
2017-01-29 07:22:40 +08:00
|
|
|
// A cached stat value would be fine as well.
|
|
|
|
if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
|
|
|
|
NewModule->InputFilesValidationTimestamp =
|
|
|
|
llvm::sys::toTimeT(Status.getLastModificationTime());
|
|
|
|
}
|
Add an option to allow Clang verify source files for a module only once during
the build
When Clang loads the module, it verifies the user source files that the module
was built from. If any file was changed, the module is rebuilt. There are two
problems with this:
1. correctness: we don't verify system files (there are too many of them, and
stat'ing all of them would take a lot of time);
2. performance: the same module file is verified again and again during a
single build.
This change allows the build system to optimize source file verification. The
idea is based on the fact that while the project is being built, the source
files don't change. This allows us to verify the module only once during a
single build session. The build system passes a flag,
-fbuild-session-timestamp=, to inform Clang of the time when the build started.
The build system also requests to enable this feature by passing
-fmodules-validate-once-per-build-session. If these flags are not passed, the
behavior is not changed. When Clang verifies the module the first time, it
writes out a timestamp file. Then, when Clang loads the module the second
time, it finds a timestamp file, so it can compare the verification timestamp
of the module with the time when the build started. If the verification
timestamp is too old, the module is verified again, and the timestamp file is
updated.
llvm-svn: 201224
2014-02-12 18:33:14 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
// Load the contents of the module
|
|
|
|
if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) {
|
|
|
|
// The buffer was already provided for us.
|
2020-03-11 01:59:26 +08:00
|
|
|
NewModule->Buffer = &ModuleCache->addBuiltPCM(FileName, std::move(Buffer));
|
2018-08-21 01:10:27 +08:00
|
|
|
// Since the cached buffer is reused, it is safe to close the file
|
|
|
|
// descriptor that was opened while stat()ing the PCM in
|
|
|
|
// lookupModuleFile() above, it won't be needed any longer.
|
|
|
|
Entry->closeFile();
|
2019-03-10 01:33:56 +08:00
|
|
|
} else if (llvm::MemoryBuffer *Buffer =
|
Modules: Invalidate out-of-date PCMs as they're discovered
Leverage the InMemoryModuleCache to invalidate a module the first time
it fails to import (and to lock a module as soon as it's built or
imported successfully). For implicit module builds, this optimizes
importing deep graphs where the leaf module is out-of-date; see example
near the end of the commit message.
Previously the cache finalized ("locked in") all modules imported so far
when starting a new module build. This was sufficient to prevent
loading two versions of the same module, but was somewhat arbitrary and
hard to reason about.
Now the cache explicitly tracks module state, where each module must be
one of:
- Unknown: module not in the cache (yet).
- Tentative: module in the cache, but not yet fully imported.
- ToBuild: module found on disk could not be imported; need to build.
- Final: module in the cache has been successfully built or imported.
Preventing repeated failed imports avoids variation in builds based on
shifting filesystem state. Now it's guaranteed that a module is loaded
from disk exactly once. It now seems safe to remove
FileManager::invalidateCache, but I'm leaving that for a later commit.
The new, precise logic uncovered a pre-existing problem in the cache:
the map key is the module filename, and different contexts use different
filenames for the same PCM file. (In particular, the test
Modules/relative-import-path.c does not build without this commit.
r223577 started using a relative path to describe a module's base
directory when importing it within another module. As a result, the
module cache sees an absolute path when (a) building the module or
importing it at the top-level, and a relative path when (b) importing
the module underneath another one.)
The "obvious" fix is to resolve paths using FileManager::getVirtualFile
and change the map key for the cache to a FileEntry, but some contexts
(particularly related to ASTUnit) have a shorter lifetime for their
FileManager than the InMemoryModuleCache. This is worth pursuing
further in a later commit; perhaps by tying together the FileManager and
InMemoryModuleCache lifetime, or moving the in-memory PCM storage into a
VFS layer.
For now, use the PCM's base directory as-written for constructing the
filename to check the ModuleCache.
Example
=======
To understand the build optimization, first consider the build of a
module graph TU -> A -> B -> C -> D with an empty cache:
TU builds A'
A' builds B'
B' builds C'
C' builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
If we build TU again, where A, B, C, and D are in the cache and D is
out-of-date, we would previously get this build:
TU imports A
imports B
imports C
imports D (out-of-date)
TU builds A'
A' imports B
imports C
imports D (out-of-date)
builds B'
B' imports C
imports D (out-of-date)
builds C'
C' imports D (out-of-date)
builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
After this commit, we'll immediateley invalidate A, B, C, and D when we
first observe that D is out-of-date, giving this build:
TU imports A
imports B
imports C
imports D (out-of-date)
TU builds A' // The same graph as an empty cache.
A' builds B'
B' builds C'
C' builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
The new build matches what we'd naively expect, pretty closely matching
the original build with the empty cache.
rdar://problem/48545366
llvm-svn: 355778
2019-03-10 01:44:01 +08:00
|
|
|
getModuleCache().lookupPCM(FileName)) {
|
Reapply "Modules: Cache PCMs in memory and avoid a use-after-free"
This reverts commit r298185, effectively reapplying r298165, after fixing the
new unit tests (PR32338). The memory buffer generator doesn't null-terminate
the MemoryBuffer it creates; this version of the commit informs getMemBuffer
about that to avoid the assert.
Original commit message follows:
----
Clang's internal build system for implicit modules uses lock files to
ensure that after a process writes a PCM it will read the same one back
in (without contention from other -cc1 commands). Since PCMs are read
from disk repeatedly while invalidating, building, and importing, the
lock is not released quickly. Furthermore, the LockFileManager is not
robust in every environment. Other -cc1 commands can stall until
timeout (after about eight minutes).
This commit changes the lock file from being necessary for correctness
to a (possibly dubious) performance hack. The remaining benefit is to
reduce duplicate work in competing -cc1 commands which depend on the
same module. Follow-up commits will change the internal build system to
continue after a timeout, and reduce the timeout. Perhaps we should
reconsider blocking at all.
This also fixes a use-after-free, when one part of a compilation
validates a PCM and starts using it, and another tries to swap out the
PCM for something new.
The PCMCache is a new type called MemoryBufferCache, which saves memory
buffers based on their filename. Its ownership is shared by the
CompilerInstance and ModuleManager.
- The ModuleManager stores PCMs there that it loads from disk, never
touching the disk if the cache is hot.
- When modules fail to validate, they're removed from the cache.
- When a CompilerInstance is spawned to build a new module, each
already-loaded PCM is assumed to be valid, and is frozen to avoid
the use-after-free.
- Any newly-built module is written directly to the cache to avoid the
round-trip to the filesystem, making lock files unnecessary for
correctness.
Original patch by Manman Ren; most testcases by Adrian Prantl!
llvm-svn: 298278
2017-03-21 01:58:26 +08:00
|
|
|
NewModule->Buffer = Buffer;
|
2018-08-21 01:10:27 +08:00
|
|
|
// As above, the file descriptor is no longer needed.
|
|
|
|
Entry->closeFile();
|
2020-03-11 01:59:26 +08:00
|
|
|
} else if (getModuleCache().shouldBuildPCM(FileName)) {
|
|
|
|
// Report that the module is out of date, since we tried (and failed) to
|
|
|
|
// import it earlier.
|
|
|
|
Entry->closeFile();
|
|
|
|
return OutOfDate;
|
2017-01-29 07:22:40 +08:00
|
|
|
} else {
|
|
|
|
// Open the AST file.
|
|
|
|
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf((std::error_code()));
|
|
|
|
if (FileName == "-") {
|
|
|
|
Buf = llvm::MemoryBuffer::getSTDIN();
|
2011-08-26 04:47:51 +08:00
|
|
|
} else {
|
2018-08-21 01:10:27 +08:00
|
|
|
// Get a buffer of the file and close the file descriptor when done.
|
2020-06-11 04:37:03 +08:00
|
|
|
// The file is volatile because in a parallel build we expect multiple
|
|
|
|
// compiler processes to use the same module file rebuilding it if needed.
|
|
|
|
//
|
|
|
|
// RequiresNullTerminator is false because module files don't need it, and
|
|
|
|
// this allows the file to still be mmapped.
|
|
|
|
Buf = FileMgr.getBufferForFile(NewModule->File,
|
|
|
|
/*IsVolatile=*/true,
|
|
|
|
/*RequiresNullTerminator=*/false);
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
2015-06-21 02:53:08 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
if (!Buf) {
|
|
|
|
ErrorStr = Buf.getError().message();
|
|
|
|
return Missing;
|
|
|
|
}
|
2017-01-29 06:24:01 +08:00
|
|
|
|
Modules: Invalidate out-of-date PCMs as they're discovered
Leverage the InMemoryModuleCache to invalidate a module the first time
it fails to import (and to lock a module as soon as it's built or
imported successfully). For implicit module builds, this optimizes
importing deep graphs where the leaf module is out-of-date; see example
near the end of the commit message.
Previously the cache finalized ("locked in") all modules imported so far
when starting a new module build. This was sufficient to prevent
loading two versions of the same module, but was somewhat arbitrary and
hard to reason about.
Now the cache explicitly tracks module state, where each module must be
one of:
- Unknown: module not in the cache (yet).
- Tentative: module in the cache, but not yet fully imported.
- ToBuild: module found on disk could not be imported; need to build.
- Final: module in the cache has been successfully built or imported.
Preventing repeated failed imports avoids variation in builds based on
shifting filesystem state. Now it's guaranteed that a module is loaded
from disk exactly once. It now seems safe to remove
FileManager::invalidateCache, but I'm leaving that for a later commit.
The new, precise logic uncovered a pre-existing problem in the cache:
the map key is the module filename, and different contexts use different
filenames for the same PCM file. (In particular, the test
Modules/relative-import-path.c does not build without this commit.
r223577 started using a relative path to describe a module's base
directory when importing it within another module. As a result, the
module cache sees an absolute path when (a) building the module or
importing it at the top-level, and a relative path when (b) importing
the module underneath another one.)
The "obvious" fix is to resolve paths using FileManager::getVirtualFile
and change the map key for the cache to a FileEntry, but some contexts
(particularly related to ASTUnit) have a shorter lifetime for their
FileManager than the InMemoryModuleCache. This is worth pursuing
further in a later commit; perhaps by tying together the FileManager and
InMemoryModuleCache lifetime, or moving the in-memory PCM storage into a
VFS layer.
For now, use the PCM's base directory as-written for constructing the
filename to check the ModuleCache.
Example
=======
To understand the build optimization, first consider the build of a
module graph TU -> A -> B -> C -> D with an empty cache:
TU builds A'
A' builds B'
B' builds C'
C' builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
If we build TU again, where A, B, C, and D are in the cache and D is
out-of-date, we would previously get this build:
TU imports A
imports B
imports C
imports D (out-of-date)
TU builds A'
A' imports B
imports C
imports D (out-of-date)
builds B'
B' imports C
imports D (out-of-date)
builds C'
C' imports D (out-of-date)
builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
After this commit, we'll immediateley invalidate A, B, C, and D when we
first observe that D is out-of-date, giving this build:
TU imports A
imports B
imports C
imports D (out-of-date)
TU builds A' // The same graph as an empty cache.
A' builds B'
B' builds C'
C' builds D'
imports D'
B' imports C'
imports D'
A' imports B'
imports C'
imports D'
TU imports A'
imports B'
imports C'
imports D'
The new build matches what we'd naively expect, pretty closely matching
the original build with the empty cache.
rdar://problem/48545366
llvm-svn: 355778
2019-03-10 01:44:01 +08:00
|
|
|
NewModule->Buffer = &getModuleCache().addPCM(FileName, std::move(*Buf));
|
2013-03-19 08:28:20 +08:00
|
|
|
}
|
2016-09-02 08:10:28 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
// Initialize the stream.
|
|
|
|
NewModule->Data = PCHContainerRdr.ExtractPCH(*NewModule->Buffer);
|
2013-03-19 08:28:20 +08:00
|
|
|
|
2017-01-29 12:42:21 +08:00
|
|
|
// Read the signature eagerly now so that we can check it. Avoid calling
|
|
|
|
// ReadSignature unless there's something to check though.
|
|
|
|
if (ExpectedSignature && checkSignature(ReadSignature(NewModule->Data),
|
2019-08-29 07:31:32 +08:00
|
|
|
ExpectedSignature, ErrorStr))
|
2017-01-29 07:22:40 +08:00
|
|
|
return OutOfDate;
|
2016-09-02 08:10:28 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
// We're keeping this module. Store it everywhere.
|
|
|
|
Module = Modules[Entry] = NewModule.get();
|
2016-09-02 08:10:28 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
updateModuleImports(*NewModule, ImportedBy, ImportLoc);
|
2016-09-02 08:10:28 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
if (!NewModule->isModule())
|
|
|
|
PCHChain.push_back(NewModule.get());
|
2016-09-02 08:10:28 +08:00
|
|
|
if (!ImportedBy)
|
2017-01-29 07:22:40 +08:00
|
|
|
Roots.push_back(NewModule.get());
|
2016-09-02 08:10:28 +08:00
|
|
|
|
2017-01-29 07:22:40 +08:00
|
|
|
Chain.push_back(std::move(NewModule));
|
2016-09-02 08:10:28 +08:00
|
|
|
return NewlyLoaded;
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
|
2019-11-11 02:31:03 +08:00
|
|
|
void ModuleManager::removeModules(ModuleIterator First, ModuleMap *modMap) {
|
2017-01-29 07:02:12 +08:00
|
|
|
auto Last = end();
|
|
|
|
if (First == Last)
|
2012-11-08 01:46:15 +08:00
|
|
|
return;
|
|
|
|
|
2015-10-22 07:12:45 +08:00
|
|
|
// Explicitly clear VisitOrder since we might not notice it is stale.
|
|
|
|
VisitOrder.clear();
|
|
|
|
|
2012-11-08 01:46:15 +08:00
|
|
|
// Collect the set of module file pointers that we'll be removing.
|
2017-01-29 06:15:22 +08:00
|
|
|
llvm::SmallPtrSet<ModuleFile *, 4> victimSet(
|
2017-01-29 07:02:12 +08:00
|
|
|
(llvm::pointer_iterator<ModuleIterator>(First)),
|
|
|
|
(llvm::pointer_iterator<ModuleIterator>(Last)));
|
2012-11-08 01:46:15 +08:00
|
|
|
|
2015-05-20 18:29:23 +08:00
|
|
|
auto IsVictim = [&](ModuleFile *MF) {
|
|
|
|
return victimSet.count(MF);
|
|
|
|
};
|
2012-11-08 01:46:15 +08:00
|
|
|
// Remove any references to the now-destroyed modules.
|
2017-01-29 07:12:13 +08:00
|
|
|
for (auto I = begin(); I != First; ++I) {
|
|
|
|
I->Imports.remove_if(IsVictim);
|
2017-01-29 07:02:12 +08:00
|
|
|
I->ImportedBy.remove_if(IsVictim);
|
2017-01-29 07:12:13 +08:00
|
|
|
}
|
2021-10-18 04:50:29 +08:00
|
|
|
llvm::erase_if(Roots, IsVictim);
|
2012-11-08 01:46:15 +08:00
|
|
|
|
2015-07-23 06:51:15 +08:00
|
|
|
// Remove the modules from the PCH chain.
|
2017-01-29 07:02:12 +08:00
|
|
|
for (auto I = First; I != Last; ++I) {
|
2017-01-29 06:15:22 +08:00
|
|
|
if (!I->isModule()) {
|
2019-03-31 16:48:19 +08:00
|
|
|
PCHChain.erase(llvm::find(PCHChain, &*I), PCHChain.end());
|
2015-07-23 06:51:15 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 01:46:15 +08:00
|
|
|
// Delete the modules and erase them from the various structures.
|
2017-01-29 07:02:12 +08:00
|
|
|
for (ModuleIterator victim = First; victim != Last; ++victim) {
|
2017-01-29 06:15:22 +08:00
|
|
|
Modules.erase(victim->File);
|
2013-03-19 08:28:20 +08:00
|
|
|
|
|
|
|
if (modMap) {
|
2017-01-29 06:15:22 +08:00
|
|
|
StringRef ModuleName = victim->ModuleName;
|
2013-03-19 08:28:20 +08:00
|
|
|
if (Module *mod = modMap->findModule(ModuleName)) {
|
2020-10-21 06:11:52 +08:00
|
|
|
mod->setASTFile(None);
|
2013-03-19 08:28:20 +08:00
|
|
|
}
|
|
|
|
}
|
2012-11-08 01:46:15 +08:00
|
|
|
}
|
|
|
|
|
2017-01-29 06:24:01 +08:00
|
|
|
// Delete the modules.
|
2017-01-29 07:02:12 +08:00
|
|
|
Chain.erase(Chain.begin() + (First - begin()), Chain.end());
|
2012-11-08 01:46:15 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 03:16:31 +08:00
|
|
|
void
|
|
|
|
ModuleManager::addInMemoryBuffer(StringRef FileName,
|
|
|
|
std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
|
|
|
const FileEntry *Entry =
|
|
|
|
FileMgr.getVirtualFile(FileName, Buffer->getBufferSize(), 0);
|
|
|
|
InMemoryBuffers[Entry] = std::move(Buffer);
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
|
2022-01-20 01:56:53 +08:00
|
|
|
std::unique_ptr<ModuleManager::VisitState> ModuleManager::allocateVisitState() {
|
2013-01-29 00:46:33 +08:00
|
|
|
// Fast path: if we have a cached state, use it.
|
|
|
|
if (FirstVisitState) {
|
2022-01-20 01:56:53 +08:00
|
|
|
auto Result = std::move(FirstVisitState);
|
|
|
|
FirstVisitState = std::move(Result->NextState);
|
2013-01-29 00:46:33 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate and return a new state.
|
2022-01-20 01:56:53 +08:00
|
|
|
return std::make_unique<VisitState>(size());
|
2013-01-29 00:46:33 +08:00
|
|
|
}
|
|
|
|
|
2022-01-20 01:56:53 +08:00
|
|
|
void ModuleManager::returnVisitState(std::unique_ptr<VisitState> State) {
|
2014-05-22 13:54:18 +08:00
|
|
|
assert(State->NextState == nullptr && "Visited state is in list?");
|
2022-01-20 01:56:53 +08:00
|
|
|
State->NextState = std::move(FirstVisitState);
|
|
|
|
FirstVisitState = std::move(State);
|
2013-01-29 00:46:33 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 07:32:03 +08:00
|
|
|
void ModuleManager::setGlobalIndex(GlobalModuleIndex *Index) {
|
|
|
|
GlobalIndex = Index;
|
2013-03-23 02:50:14 +08:00
|
|
|
if (!GlobalIndex) {
|
|
|
|
ModulesInCommonWithGlobalIndex.clear();
|
|
|
|
return;
|
2013-03-19 08:28:20 +08:00
|
|
|
}
|
2013-03-23 02:50:14 +08:00
|
|
|
|
|
|
|
// Notify the global module index about all of the modules we've already
|
|
|
|
// loaded.
|
2017-01-29 06:24:01 +08:00
|
|
|
for (ModuleFile &M : *this)
|
|
|
|
if (!GlobalIndex->loadedModuleFile(&M))
|
|
|
|
ModulesInCommonWithGlobalIndex.push_back(&M);
|
2013-03-23 02:50:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleManager::moduleFileAccepted(ModuleFile *MF) {
|
|
|
|
if (!GlobalIndex || GlobalIndex->loadedModuleFile(MF))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ModulesInCommonWithGlobalIndex.push_back(MF);
|
2013-01-26 07:32:03 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 01:33:56 +08:00
|
|
|
ModuleManager::ModuleManager(FileManager &FileMgr,
|
|
|
|
InMemoryModuleCache &ModuleCache,
|
2017-08-31 14:26:43 +08:00
|
|
|
const PCHContainerReader &PCHContainerRdr,
|
2019-03-10 01:33:56 +08:00
|
|
|
const HeaderSearch &HeaderSearchInfo)
|
|
|
|
: FileMgr(FileMgr), ModuleCache(&ModuleCache),
|
|
|
|
PCHContainerRdr(PCHContainerRdr), HeaderSearchInfo(HeaderSearchInfo) {}
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2015-07-25 20:14:04 +08:00
|
|
|
void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
|
|
|
|
llvm::SmallPtrSetImpl<ModuleFile *> *ModuleFilesHit) {
|
2013-01-26 07:32:03 +08:00
|
|
|
// If the visitation order vector is the wrong size, recompute the order.
|
2013-01-26 06:25:23 +08:00
|
|
|
if (VisitOrder.size() != Chain.size()) {
|
|
|
|
unsigned N = size();
|
|
|
|
VisitOrder.clear();
|
|
|
|
VisitOrder.reserve(N);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-01-26 06:25:23 +08:00
|
|
|
// Record the number of incoming edges for each module. When we
|
|
|
|
// encounter a module with no incoming edges, push it into the queue
|
|
|
|
// to seed the queue.
|
|
|
|
SmallVector<ModuleFile *, 4> Queue;
|
|
|
|
Queue.reserve(N);
|
|
|
|
llvm::SmallVector<unsigned, 4> UnusedIncomingEdges;
|
2015-07-22 09:28:05 +08:00
|
|
|
UnusedIncomingEdges.resize(size());
|
2017-01-29 06:15:22 +08:00
|
|
|
for (ModuleFile &M : llvm::reverse(*this)) {
|
|
|
|
unsigned Size = M.ImportedBy.size();
|
|
|
|
UnusedIncomingEdges[M.Index] = Size;
|
2015-07-22 09:28:05 +08:00
|
|
|
if (!Size)
|
2017-01-29 06:15:22 +08:00
|
|
|
Queue.push_back(&M);
|
2013-01-22 04:07:12 +08:00
|
|
|
}
|
2013-01-26 06:25:23 +08:00
|
|
|
|
|
|
|
// Traverse the graph, making sure to visit a module before visiting any
|
|
|
|
// of its dependencies.
|
2015-07-22 09:28:05 +08:00
|
|
|
while (!Queue.empty()) {
|
|
|
|
ModuleFile *CurrentModule = Queue.pop_back_val();
|
2013-01-26 06:25:23 +08:00
|
|
|
VisitOrder.push_back(CurrentModule);
|
|
|
|
|
|
|
|
// For any module that this module depends on, push it on the
|
|
|
|
// stack (if it hasn't already been marked as visited).
|
2021-11-18 11:40:48 +08:00
|
|
|
for (ModuleFile *M : llvm::reverse(CurrentModule->Imports)) {
|
2013-01-26 06:25:23 +08:00
|
|
|
// Remove our current module as an impediment to visiting the
|
|
|
|
// module we depend on. If we were the last unvisited module
|
|
|
|
// that depends on this particular module, push it into the
|
|
|
|
// queue to be visited.
|
2021-11-18 11:40:48 +08:00
|
|
|
unsigned &NumUnusedEdges = UnusedIncomingEdges[M->Index];
|
2013-01-26 06:25:23 +08:00
|
|
|
if (NumUnusedEdges && (--NumUnusedEdges == 0))
|
2021-11-18 11:40:48 +08:00
|
|
|
Queue.push_back(M);
|
2013-01-26 06:25:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(VisitOrder.size() == N && "Visitation order is wrong?");
|
2013-01-26 07:32:03 +08:00
|
|
|
|
2014-05-22 13:54:18 +08:00
|
|
|
FirstVisitState = nullptr;
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
2013-01-22 04:07:12 +08:00
|
|
|
|
2022-01-20 01:56:53 +08:00
|
|
|
auto State = allocateVisitState();
|
2013-01-29 00:46:33 +08:00
|
|
|
unsigned VisitNumber = State->NextVisitNumber++;
|
2013-01-26 06:25:23 +08:00
|
|
|
|
2013-01-26 07:32:03 +08:00
|
|
|
// If the caller has provided us with a hit-set that came from the global
|
|
|
|
// module index, mark every module file in common with the global module
|
|
|
|
// index that is *not* in that set as 'visited'.
|
|
|
|
if (ModuleFilesHit && !ModulesInCommonWithGlobalIndex.empty()) {
|
|
|
|
for (unsigned I = 0, N = ModulesInCommonWithGlobalIndex.size(); I != N; ++I)
|
|
|
|
{
|
|
|
|
ModuleFile *M = ModulesInCommonWithGlobalIndex[I];
|
2013-03-19 08:28:20 +08:00
|
|
|
if (!ModuleFilesHit->count(M))
|
2013-01-29 00:46:33 +08:00
|
|
|
State->VisitNumber[M->Index] = VisitNumber;
|
2013-01-26 07:32:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 06:25:23 +08:00
|
|
|
for (unsigned I = 0, N = VisitOrder.size(); I != N; ++I) {
|
|
|
|
ModuleFile *CurrentModule = VisitOrder[I];
|
|
|
|
// Should we skip this module file?
|
2013-01-29 00:46:33 +08:00
|
|
|
if (State->VisitNumber[CurrentModule->Index] == VisitNumber)
|
2011-08-26 04:47:51 +08:00
|
|
|
continue;
|
2013-01-26 06:25:23 +08:00
|
|
|
|
|
|
|
// Visit the module.
|
2013-01-29 00:46:33 +08:00
|
|
|
assert(State->VisitNumber[CurrentModule->Index] == VisitNumber - 1);
|
|
|
|
State->VisitNumber[CurrentModule->Index] = VisitNumber;
|
2015-07-25 20:14:04 +08:00
|
|
|
if (!Visitor(*CurrentModule))
|
2013-01-26 06:25:23 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// The visitor has requested that cut off visitation of any
|
|
|
|
// module that the current module depends on. To indicate this
|
|
|
|
// behavior, we mark all of the reachable modules as having been visited.
|
|
|
|
ModuleFile *NextModule = CurrentModule;
|
|
|
|
do {
|
|
|
|
// For any module that this module depends on, push it on the
|
|
|
|
// stack (if it hasn't already been marked as visited).
|
|
|
|
for (llvm::SetVector<ModuleFile *>::iterator
|
|
|
|
M = NextModule->Imports.begin(),
|
|
|
|
MEnd = NextModule->Imports.end();
|
|
|
|
M != MEnd; ++M) {
|
2013-01-29 00:46:33 +08:00
|
|
|
if (State->VisitNumber[(*M)->Index] != VisitNumber) {
|
|
|
|
State->Stack.push_back(*M);
|
|
|
|
State->VisitNumber[(*M)->Index] = VisitNumber;
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-26 06:25:23 +08:00
|
|
|
|
2013-01-29 00:46:33 +08:00
|
|
|
if (State->Stack.empty())
|
2013-01-26 06:25:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Pop the next module off the stack.
|
2013-08-24 00:11:15 +08:00
|
|
|
NextModule = State->Stack.pop_back_val();
|
2013-01-26 06:25:23 +08:00
|
|
|
} while (true);
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
2013-01-29 00:46:33 +08:00
|
|
|
|
2022-01-20 01:56:53 +08:00
|
|
|
returnVisitState(std::move(State));
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 06:11:52 +08:00
|
|
|
bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
|
2013-03-19 08:28:20 +08:00
|
|
|
time_t ExpectedModTime,
|
2020-10-21 06:11:52 +08:00
|
|
|
Optional<FileEntryRef> &File) {
|
|
|
|
File = None;
|
2020-10-21 06:53:51 +08:00
|
|
|
if (FileName == "-")
|
2016-09-02 08:18:05 +08:00
|
|
|
return false;
|
|
|
|
|
2014-05-01 11:33:36 +08:00
|
|
|
// Open the file immediately to ensure there is no race between stat'ing and
|
|
|
|
// opening the file.
|
2020-10-21 06:11:52 +08:00
|
|
|
Optional<FileEntryRef> FileOrErr =
|
|
|
|
expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true,
|
|
|
|
/*CacheFailure=*/false));
|
2020-10-21 06:53:51 +08:00
|
|
|
if (!FileOrErr)
|
2013-03-19 08:28:20 +08:00
|
|
|
return false;
|
2020-10-21 06:53:51 +08:00
|
|
|
|
2019-08-02 05:31:56 +08:00
|
|
|
File = *FileOrErr;
|
2013-03-19 08:28:20 +08:00
|
|
|
|
|
|
|
if ((ExpectedSize && ExpectedSize != File->getSize()) ||
|
2014-05-04 13:20:54 +08:00
|
|
|
(ExpectedModTime && ExpectedModTime != File->getModificationTime()))
|
|
|
|
// Do not destroy File, as it may be referenced. If we need to rebuild it,
|
|
|
|
// it will be destroyed by removeModules.
|
2013-03-19 08:28:20 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-12 03:27:55 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
namespace llvm {
|
2017-11-11 08:08:50 +08:00
|
|
|
|
2011-10-12 03:27:55 +08:00
|
|
|
template<>
|
|
|
|
struct GraphTraits<ModuleManager> {
|
2017-11-11 08:08:50 +08:00
|
|
|
using NodeRef = ModuleFile *;
|
|
|
|
using ChildIteratorType = llvm::SetVector<ModuleFile *>::const_iterator;
|
|
|
|
using nodes_iterator = pointer_iterator<ModuleManager::ModuleConstIterator>;
|
2016-08-23 05:09:30 +08:00
|
|
|
|
|
|
|
static ChildIteratorType child_begin(NodeRef Node) {
|
2011-10-12 03:27:55 +08:00
|
|
|
return Node->Imports.begin();
|
|
|
|
}
|
|
|
|
|
2016-08-23 05:09:30 +08:00
|
|
|
static ChildIteratorType child_end(NodeRef Node) {
|
2011-10-12 03:27:55 +08:00
|
|
|
return Node->Imports.end();
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-10-12 03:27:55 +08:00
|
|
|
static nodes_iterator nodes_begin(const ModuleManager &Manager) {
|
2017-01-29 06:15:22 +08:00
|
|
|
return nodes_iterator(Manager.begin());
|
2011-10-12 03:27:55 +08:00
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-10-12 03:27:55 +08:00
|
|
|
static nodes_iterator nodes_end(const ModuleManager &Manager) {
|
2017-01-29 06:15:22 +08:00
|
|
|
return nodes_iterator(Manager.end());
|
2011-10-12 03:27:55 +08:00
|
|
|
}
|
|
|
|
};
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-10-12 03:27:55 +08:00
|
|
|
template<>
|
|
|
|
struct DOTGraphTraits<ModuleManager> : public DefaultDOTGraphTraits {
|
|
|
|
explicit DOTGraphTraits(bool IsSimple = false)
|
2017-11-11 08:08:50 +08:00
|
|
|
: DefaultDOTGraphTraits(IsSimple) {}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
static bool renderGraphFromBottomUp() { return true; }
|
2011-10-12 03:27:55 +08:00
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
std::string getNodeLabel(ModuleFile *M, const ModuleManager&) {
|
2014-04-15 02:00:01 +08:00
|
|
|
return M->ModuleName;
|
2011-10-12 03:27:55 +08:00
|
|
|
}
|
|
|
|
};
|
2017-11-11 08:08:50 +08:00
|
|
|
|
|
|
|
} // namespace llvm
|
2011-10-12 03:27:55 +08:00
|
|
|
|
|
|
|
void ModuleManager::viewGraph() {
|
|
|
|
llvm::ViewGraph(*this, "Modules");
|
|
|
|
}
|
|
|
|
#endif
|