clang  14.0.0git
ModuleManager.cpp
Go to the documentation of this file.
1 //===- ModuleManager.cpp - Module Manager ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ModuleManager class, which manages a set of loaded
10 // modules for the ASTReader.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "clang/Basic/LLVM.h"
17 #include "clang/Lex/HeaderSearch.h"
18 #include "clang/Lex/ModuleMap.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/SetVector.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/StringRef.h"
28 #include "llvm/ADT/iterator.h"
29 #include "llvm/Support/Chrono.h"
30 #include "llvm/Support/DOTGraphTraits.h"
31 #include "llvm/Support/ErrorOr.h"
32 #include "llvm/Support/GraphWriter.h"
33 #include "llvm/Support/MemoryBuffer.h"
34 #include "llvm/Support/VirtualFileSystem.h"
35 #include <algorithm>
36 #include <cassert>
37 #include <memory>
38 #include <string>
39 #include <system_error>
40 
41 using namespace clang;
42 using namespace serialization;
43 
45  auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
46  /*CacheFailure=*/false);
47  if (Entry)
48  return lookup(*Entry);
49 
50  return nullptr;
51 }
52 
54  if (const Module *Mod = HeaderSearchInfo.getModuleMap().findModule(Name))
55  if (const FileEntry *File = Mod->getASTFile())
56  return lookup(File);
57 
58  return nullptr;
59 }
60 
62  auto Known = Modules.find(File);
63  if (Known == Modules.end())
64  return nullptr;
65 
66  return Known->second;
67 }
68 
69 std::unique_ptr<llvm::MemoryBuffer>
70 ModuleManager::lookupBuffer(StringRef Name) {
71  auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
72  /*CacheFailure=*/false);
73  if (!Entry)
74  return nullptr;
75  return std::move(InMemoryBuffers[*Entry]);
76 }
77 
78 static bool checkSignature(ASTFileSignature Signature,
79  ASTFileSignature ExpectedSignature,
80  std::string &ErrorStr) {
81  if (!ExpectedSignature || Signature == ExpectedSignature)
82  return false;
83 
84  ErrorStr =
85  Signature ? "signature mismatch" : "could not read module signature";
86  return true;
87 }
88 
89 static void updateModuleImports(ModuleFile &MF, ModuleFile *ImportedBy,
90  SourceLocation ImportLoc) {
91  if (ImportedBy) {
92  MF.ImportedBy.insert(ImportedBy);
93  ImportedBy->Imports.insert(&MF);
94  } else {
95  if (!MF.DirectlyImported)
96  MF.ImportLoc = ImportLoc;
97 
98  MF.DirectlyImported = true;
99  }
100 }
101 
104  SourceLocation ImportLoc, ModuleFile *ImportedBy,
105  unsigned Generation,
106  off_t ExpectedSize, time_t ExpectedModTime,
107  ASTFileSignature ExpectedSignature,
108  ASTFileSignatureReader ReadSignature,
109  ModuleFile *&Module,
110  std::string &ErrorStr) {
111  Module = nullptr;
112 
113  // Look for the file entry. This only fails if the expected size or
114  // modification time differ.
117  // If we're not expecting to pull this file out of the module cache, it
118  // might have a different mtime due to being moved across filesystems in
119  // a distributed build. The size must still match, though. (As must the
120  // contents, but we can't check that.)
121  ExpectedModTime = 0;
122  }
123  // Note: ExpectedSize and ExpectedModTime will be 0 for MK_ImplicitModule
124  // when using an ASTFileSignature.
125  if (lookupModuleFile(FileName, ExpectedSize, ExpectedModTime, Entry)) {
126  ErrorStr = "module file out of date";
127  return OutOfDate;
128  }
129 
130  if (!Entry && FileName != "-") {
131  ErrorStr = "module file not found";
132  return Missing;
133  }
134 
135  // The ModuleManager's use of FileEntry nodes as the keys for its map of
136  // loaded modules is less than ideal. Uniqueness for FileEntry nodes is
137  // maintained by FileManager, which in turn uses inode numbers on hosts
138  // that support that. When coupled with the module cache's proclivity for
139  // turning over and deleting stale PCMs, this means entries for different
140  // module files can wind up reusing the same underlying inode. When this
141  // happens, subsequent accesses to the Modules map will disagree on the
142  // ModuleFile associated with a given file. In general, it is not sufficient
143  // to resolve this conundrum with a type like FileEntryRef that stores the
144  // name of the FileEntry node on first access because of path canonicalization
145  // issues. However, the paths constructed for implicit module builds are
146  // fully under Clang's control. We *can*, therefore, rely on their structure
147  // being consistent across operating systems and across subsequent accesses
148  // to the Modules map.
149  auto implicitModuleNamesMatch = [](ModuleKind Kind, const ModuleFile *MF,
150  const FileEntry *Entry) -> bool {
151  if (Kind != MK_ImplicitModule)
152  return true;
153  return Entry->getName() == MF->FileName;
154  };
155 
156  // Check whether we already loaded this module, before
157  if (ModuleFile *ModuleEntry = Modules.lookup(Entry)) {
158  if (implicitModuleNamesMatch(Type, ModuleEntry, Entry)) {
159  // Check the stored signature.
160  if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr))
161  return OutOfDate;
162 
163  Module = ModuleEntry;
164  updateModuleImports(*ModuleEntry, ImportedBy, ImportLoc);
165  return AlreadyLoaded;
166  }
167  }
168 
169  // Allocate a new module.
170  auto NewModule = std::make_unique<ModuleFile>(Type, Generation);
171  NewModule->Index = Chain.size();
172  NewModule->FileName = FileName.str();
173  NewModule->File = Entry;
174  NewModule->ImportLoc = ImportLoc;
175  NewModule->InputFilesValidationTimestamp = 0;
176 
177  if (NewModule->Kind == MK_ImplicitModule) {
178  std::string TimestampFilename = NewModule->getTimestampFilename();
179  llvm::vfs::Status Status;
180  // A cached stat value would be fine as well.
181  if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
182  NewModule->InputFilesValidationTimestamp =
183  llvm::sys::toTimeT(Status.getLastModificationTime());
184  }
185 
186  // Load the contents of the module
187  if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) {
188  // The buffer was already provided for us.
189  NewModule->Buffer = &ModuleCache->addBuiltPCM(FileName, std::move(Buffer));
190  // Since the cached buffer is reused, it is safe to close the file
191  // descriptor that was opened while stat()ing the PCM in
192  // lookupModuleFile() above, it won't be needed any longer.
193  Entry->closeFile();
194  } else if (llvm::MemoryBuffer *Buffer =
195  getModuleCache().lookupPCM(FileName)) {
196  NewModule->Buffer = Buffer;
197  // As above, the file descriptor is no longer needed.
198  Entry->closeFile();
199  } else if (getModuleCache().shouldBuildPCM(FileName)) {
200  // Report that the module is out of date, since we tried (and failed) to
201  // import it earlier.
202  Entry->closeFile();
203  return OutOfDate;
204  } else {
205  // Open the AST file.
206  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf((std::error_code()));
207  if (FileName == "-") {
208  Buf = llvm::MemoryBuffer::getSTDIN();
209  } else {
210  // Get a buffer of the file and close the file descriptor when done.
211  // The file is volatile because in a parallel build we expect multiple
212  // compiler processes to use the same module file rebuilding it if needed.
213  //
214  // RequiresNullTerminator is false because module files don't need it, and
215  // this allows the file to still be mmapped.
216  Buf = FileMgr.getBufferForFile(NewModule->File,
217  /*IsVolatile=*/true,
218  /*RequiresNullTerminator=*/false);
219  }
220 
221  if (!Buf) {
222  ErrorStr = Buf.getError().message();
223  return Missing;
224  }
225 
226  NewModule->Buffer = &getModuleCache().addPCM(FileName, std::move(*Buf));
227  }
228 
229  // Initialize the stream.
230  NewModule->Data = PCHContainerRdr.ExtractPCH(*NewModule->Buffer);
231 
232  // Read the signature eagerly now so that we can check it. Avoid calling
233  // ReadSignature unless there's something to check though.
234  if (ExpectedSignature && checkSignature(ReadSignature(NewModule->Data),
235  ExpectedSignature, ErrorStr))
236  return OutOfDate;
237 
238  // We're keeping this module. Store it everywhere.
239  Module = Modules[Entry] = NewModule.get();
240 
241  updateModuleImports(*NewModule, ImportedBy, ImportLoc);
242 
243  if (!NewModule->isModule())
244  PCHChain.push_back(NewModule.get());
245  if (!ImportedBy)
246  Roots.push_back(NewModule.get());
247 
248  Chain.push_back(std::move(NewModule));
249  return NewlyLoaded;
250 }
251 
253  auto Last = end();
254  if (First == Last)
255  return;
256 
257  // Explicitly clear VisitOrder since we might not notice it is stale.
258  VisitOrder.clear();
259 
260  // Collect the set of module file pointers that we'll be removing.
262  (llvm::pointer_iterator<ModuleIterator>(First)),
263  (llvm::pointer_iterator<ModuleIterator>(Last)));
264 
265  auto IsVictim = [&](ModuleFile *MF) {
266  return victimSet.count(MF);
267  };
268  // Remove any references to the now-destroyed modules.
269  for (auto I = begin(); I != First; ++I) {
270  I->Imports.remove_if(IsVictim);
271  I->ImportedBy.remove_if(IsVictim);
272  }
273  llvm::erase_if(Roots, IsVictim);
274 
275  // Remove the modules from the PCH chain.
276  for (auto I = First; I != Last; ++I) {
277  if (!I->isModule()) {
278  PCHChain.erase(llvm::find(PCHChain, &*I), PCHChain.end());
279  break;
280  }
281  }
282 
283  // Delete the modules and erase them from the various structures.
284  for (ModuleIterator victim = First; victim != Last; ++victim) {
285  Modules.erase(victim->File);
286 
287  if (modMap) {
288  StringRef ModuleName = victim->ModuleName;
289  if (Module *mod = modMap->findModule(ModuleName)) {
290  mod->setASTFile(None);
291  }
292  }
293  }
294 
295  // Delete the modules.
296  Chain.erase(Chain.begin() + (First - begin()), Chain.end());
297 }
298 
299 void
301  std::unique_ptr<llvm::MemoryBuffer> Buffer) {
302  const FileEntry *Entry =
303  FileMgr.getVirtualFile(FileName, Buffer->getBufferSize(), 0);
304  InMemoryBuffers[Entry] = std::move(Buffer);
305 }
306 
307 ModuleManager::VisitState *ModuleManager::allocateVisitState() {
308  // Fast path: if we have a cached state, use it.
309  if (FirstVisitState) {
310  VisitState *Result = FirstVisitState;
311  FirstVisitState = FirstVisitState->NextState;
312  Result->NextState = nullptr;
313  return Result;
314  }
315 
316  // Allocate and return a new state.
317  return new VisitState(size());
318 }
319 
320 void ModuleManager::returnVisitState(VisitState *State) {
321  assert(State->NextState == nullptr && "Visited state is in list?");
322  State->NextState = FirstVisitState;
323  FirstVisitState = State;
324 }
325 
327  GlobalIndex = Index;
328  if (!GlobalIndex) {
329  ModulesInCommonWithGlobalIndex.clear();
330  return;
331  }
332 
333  // Notify the global module index about all of the modules we've already
334  // loaded.
335  for (ModuleFile &M : *this)
336  if (!GlobalIndex->loadedModuleFile(&M))
337  ModulesInCommonWithGlobalIndex.push_back(&M);
338 }
339 
341  if (!GlobalIndex || GlobalIndex->loadedModuleFile(MF))
342  return;
343 
344  ModulesInCommonWithGlobalIndex.push_back(MF);
345 }
346 
348  InMemoryModuleCache &ModuleCache,
349  const PCHContainerReader &PCHContainerRdr,
350  const HeaderSearch &HeaderSearchInfo)
351  : FileMgr(FileMgr), ModuleCache(&ModuleCache),
352  PCHContainerRdr(PCHContainerRdr), HeaderSearchInfo(HeaderSearchInfo) {}
353 
354 ModuleManager::~ModuleManager() { delete FirstVisitState; }
355 
356 void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
357  llvm::SmallPtrSetImpl<ModuleFile *> *ModuleFilesHit) {
358  // If the visitation order vector is the wrong size, recompute the order.
359  if (VisitOrder.size() != Chain.size()) {
360  unsigned N = size();
361  VisitOrder.clear();
362  VisitOrder.reserve(N);
363 
364  // Record the number of incoming edges for each module. When we
365  // encounter a module with no incoming edges, push it into the queue
366  // to seed the queue.
368  Queue.reserve(N);
369  llvm::SmallVector<unsigned, 4> UnusedIncomingEdges;
370  UnusedIncomingEdges.resize(size());
371  for (ModuleFile &M : llvm::reverse(*this)) {
372  unsigned Size = M.ImportedBy.size();
373  UnusedIncomingEdges[M.Index] = Size;
374  if (!Size)
375  Queue.push_back(&M);
376  }
377 
378  // Traverse the graph, making sure to visit a module before visiting any
379  // of its dependencies.
380  while (!Queue.empty()) {
381  ModuleFile *CurrentModule = Queue.pop_back_val();
382  VisitOrder.push_back(CurrentModule);
383 
384  // For any module that this module depends on, push it on the
385  // stack (if it hasn't already been marked as visited).
386  for (auto M = CurrentModule->Imports.rbegin(),
387  MEnd = CurrentModule->Imports.rend();
388  M != MEnd; ++M) {
389  // Remove our current module as an impediment to visiting the
390  // module we depend on. If we were the last unvisited module
391  // that depends on this particular module, push it into the
392  // queue to be visited.
393  unsigned &NumUnusedEdges = UnusedIncomingEdges[(*M)->Index];
394  if (NumUnusedEdges && (--NumUnusedEdges == 0))
395  Queue.push_back(*M);
396  }
397  }
398 
399  assert(VisitOrder.size() == N && "Visitation order is wrong?");
400 
401  delete FirstVisitState;
402  FirstVisitState = nullptr;
403  }
404 
405  VisitState *State = allocateVisitState();
406  unsigned VisitNumber = State->NextVisitNumber++;
407 
408  // If the caller has provided us with a hit-set that came from the global
409  // module index, mark every module file in common with the global module
410  // index that is *not* in that set as 'visited'.
411  if (ModuleFilesHit && !ModulesInCommonWithGlobalIndex.empty()) {
412  for (unsigned I = 0, N = ModulesInCommonWithGlobalIndex.size(); I != N; ++I)
413  {
414  ModuleFile *M = ModulesInCommonWithGlobalIndex[I];
415  if (!ModuleFilesHit->count(M))
416  State->VisitNumber[M->Index] = VisitNumber;
417  }
418  }
419 
420  for (unsigned I = 0, N = VisitOrder.size(); I != N; ++I) {
421  ModuleFile *CurrentModule = VisitOrder[I];
422  // Should we skip this module file?
423  if (State->VisitNumber[CurrentModule->Index] == VisitNumber)
424  continue;
425 
426  // Visit the module.
427  assert(State->VisitNumber[CurrentModule->Index] == VisitNumber - 1);
428  State->VisitNumber[CurrentModule->Index] = VisitNumber;
429  if (!Visitor(*CurrentModule))
430  continue;
431 
432  // The visitor has requested that cut off visitation of any
433  // module that the current module depends on. To indicate this
434  // behavior, we mark all of the reachable modules as having been visited.
435  ModuleFile *NextModule = CurrentModule;
436  do {
437  // For any module that this module depends on, push it on the
438  // stack (if it hasn't already been marked as visited).
439  for (llvm::SetVector<ModuleFile *>::iterator
440  M = NextModule->Imports.begin(),
441  MEnd = NextModule->Imports.end();
442  M != MEnd; ++M) {
443  if (State->VisitNumber[(*M)->Index] != VisitNumber) {
444  State->Stack.push_back(*M);
445  State->VisitNumber[(*M)->Index] = VisitNumber;
446  }
447  }
448 
449  if (State->Stack.empty())
450  break;
451 
452  // Pop the next module off the stack.
453  NextModule = State->Stack.pop_back_val();
454  } while (true);
455  }
456 
457  returnVisitState(State);
458 }
459 
460 bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
461  time_t ExpectedModTime,
462  Optional<FileEntryRef> &File) {
463  File = None;
464  if (FileName == "-")
465  return false;
466 
467  // Open the file immediately to ensure there is no race between stat'ing and
468  // opening the file.
469  Optional<FileEntryRef> FileOrErr =
470  expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true,
471  /*CacheFailure=*/false));
472  if (!FileOrErr)
473  return false;
474 
475  File = *FileOrErr;
476 
477  if ((ExpectedSize && ExpectedSize != File->getSize()) ||
478  (ExpectedModTime && ExpectedModTime != File->getModificationTime()))
479  // Do not destroy File, as it may be referenced. If we need to rebuild it,
480  // it will be destroyed by removeModules.
481  return true;
482 
483  return false;
484 }
485 
486 #ifndef NDEBUG
487 namespace llvm {
488 
489  template<>
491  using NodeRef = ModuleFile *;
492  using ChildIteratorType = llvm::SetVector<ModuleFile *>::const_iterator;
493  using nodes_iterator = pointer_iterator<ModuleManager::ModuleConstIterator>;
494 
496  return Node->Imports.begin();
497  }
498 
500  return Node->Imports.end();
501  }
502 
503  static nodes_iterator nodes_begin(const ModuleManager &Manager) {
504  return nodes_iterator(Manager.begin());
505  }
506 
507  static nodes_iterator nodes_end(const ModuleManager &Manager) {
508  return nodes_iterator(Manager.end());
509  }
510  };
511 
512  template<>
513  struct DOTGraphTraits<ModuleManager> : public DefaultDOTGraphTraits {
514  explicit DOTGraphTraits(bool IsSimple = false)
515  : DefaultDOTGraphTraits(IsSimple) {}
516 
517  static bool renderGraphFromBottomUp() { return true; }
518 
520  return M->ModuleName;
521  }
522  };
523 
524 } // namespace llvm
525 
527  llvm::ViewGraph(*this, "Modules");
528 }
529 #endif
clang::FileManager::getNoncachedStatValue
std::error_code getNoncachedStatValue(StringRef Path, llvm::vfs::Status &Result)
Get the 'stat' information for the given Path.
Definition: FileManager.cpp:583
clang::serialization::ModuleFile::DirectlyImported
bool DirectlyImported
Whether this module has been directly imported by the user.
Definition: ModuleFile.h:182
checkSignature
static bool checkSignature(ASTFileSignature Signature, ASTFileSignature ExpectedSignature, std::string &ErrorStr)
Definition: ModuleManager.cpp:78
clang::GlobalModuleIndex
A global index for a set of module files, providing information about the identifiers within those mo...
Definition: GlobalModuleIndex.h:56
llvm::DOTGraphTraits< ModuleManager >::getNodeLabel
std::string getNodeLabel(ModuleFile *M, const ModuleManager &)
Definition: ModuleManager.cpp:519
llvm
Definition: Dominators.h:30
clang::serialization::ModuleManager::setGlobalIndex
void setGlobalIndex(GlobalModuleIndex *Index)
Set the global module index.
Definition: ModuleManager.cpp:326
clang::serialization::ModuleManager
Manages the set of modules loaded by an AST reader.
Definition: ModuleManager.h:48
clang::serialization::ModuleManager::OutOfDate
@ OutOfDate
The module file is out-of-date.
Definition: ModuleManager.h:209
clang::DeclaratorContext::File
@ File
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::serialization::ModuleManager::addInMemoryBuffer
void addInMemoryBuffer(StringRef FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add an in-memory buffer the list of known buffers.
Definition: ModuleManager.cpp:300
ModuleMap.h
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::serialization::ModuleManager::removeModules
void removeModules(ModuleIterator First, ModuleMap *modMap)
Remove the modules starting from First (to the end).
Definition: ModuleManager.cpp:252
clang::FileManager::getFileRef
llvm::Expected< FileEntryRef > getFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:204
llvm::GraphTraits< ModuleManager >::ChildIteratorType
llvm::SetVector< ModuleFile * >::const_iterator ChildIteratorType
Definition: ModuleManager.cpp:492
llvm::Optional< FileEntryRef >
clang::ComparisonCategoryType::First
@ First
clang::serialization::ModuleManager::size
unsigned size() const
Number of modules loaded.
Definition: ModuleManager.h:195
llvm::SmallPtrSet
Definition: ASTContext.h:82
clang::OptionalFileEntryRefDegradesToFileEntryPtr
Wrapper around Optional<FileEntryRef> that degrades to 'const FileEntry*', facilitating incremental p...
Definition: FileEntry.h:280
clang::serialization::ModuleManager::AlreadyLoaded
@ AlreadyLoaded
The module file had already been loaded.
Definition: ModuleManager.h:200
clang::serialization::ModuleManager::ModuleManager
ModuleManager(FileManager &FileMgr, InMemoryModuleCache &ModuleCache, const PCHContainerReader &PCHContainerRdr, const HeaderSearch &HeaderSearchInfo)
Definition: ModuleManager.cpp:347
clang::serialization::ModuleManager::~ModuleManager
~ModuleManager()
Definition: ModuleManager.cpp:354
clang::PCHContainerReader
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
Definition: PCHContainerOperations.h:57
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:169
DefaultDOTGraphTraits
clang::Module
Describes a module or submodule.
Definition: Module.h:96
Node
DynTypedNode Node
Definition: ASTMatchFinder.cpp:67
clang::InMemoryModuleCache::addPCM
llvm::MemoryBuffer & addPCM(llvm::StringRef Filename, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Store the PCM under the Filename.
Definition: InMemoryModuleCache.cpp:25
clang::ModuleMap::findModule
Module * findModule(StringRef Name) const
Retrieve a module with the given name.
Definition: ModuleMap.cpp:791
clang::serialization::ModuleFile::ImportedBy
llvm::SetVector< ModuleFile * > ImportedBy
List of modules which depend on this module.
Definition: ModuleFile.h:495
clang::serialization::ModuleManager::ModuleIterator
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::iterator > ModuleIterator
Definition: ModuleManager.h:135
llvm::GraphTraits< ModuleManager >::child_begin
static ChildIteratorType child_begin(NodeRef Node)
Definition: ModuleManager.cpp:495
clang::serialization::ModuleManager::lookupBuffer
std::unique_ptr< llvm::MemoryBuffer > lookupBuffer(StringRef Name)
Returns the in-memory (virtual file) buffer with the given name.
Definition: ModuleManager.cpp:70
clang::serialization::ModuleManager::visit
void visit(llvm::function_ref< bool(ModuleFile &M)> Visitor, llvm::SmallPtrSetImpl< ModuleFile * > *ModuleFilesHit=nullptr)
Visit each of the modules.
Definition: ModuleManager.cpp:356
clang::serialization::ModuleManager::addModule
AddModuleResult addModule(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, ModuleFile *ImportedBy, unsigned Generation, off_t ExpectedSize, time_t ExpectedModTime, ASTFileSignature ExpectedSignature, ASTFileSignatureReader ReadSignature, ModuleFile *&Module, std::string &ErrorStr)
Attempts to create a new module and add it to the list of known modules.
Definition: ModuleManager.cpp:103
clang::serialization::ModuleManager::viewGraph
void viewGraph()
View the graphviz representation of the module graph.
Definition: ModuleManager.cpp:526
clang::serialization::MK_ImplicitModule
@ MK_ImplicitModule
File is an implicitly-loaded module.
Definition: ModuleFile.h:44
clang::ASTFileSignature
The signature of a module, which is a hash of the AST content.
Definition: Module.h:56
clang::serialization::ModuleFile::Index
unsigned Index
The index of this module in the list of modules.
Definition: ModuleFile.h:120
llvm::GraphTraits< ModuleManager >::child_end
static ChildIteratorType child_end(NodeRef Node)
Definition: ModuleManager.cpp:499
updateModuleImports
static void updateModuleImports(ModuleFile &MF, ModuleFile *ImportedBy, SourceLocation ImportLoc)
Definition: ModuleManager.cpp:89
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:331
clang::ModuleMap
Definition: ModuleMap.h:75
clang::serialization::ModuleManager::Missing
@ Missing
The module file is missing.
Definition: ModuleManager.h:206
InMemoryModuleCache.h
clang::serialization::ModuleManager::getModuleCache
InMemoryModuleCache & getModuleCache() const
Definition: ModuleManager.h:316
clang::serialization::MK_ExplicitModule
@ MK_ExplicitModule
File is an explicitly-loaded module.
Definition: ModuleFile.h:47
clang::serialization::ModuleManager::lookupByModuleName
ModuleFile * lookupByModuleName(StringRef ModName) const
Returns the module associated with the given module name.
Definition: ModuleManager.cpp:53
clang::serialization::ModuleManager::lookupModuleFile
bool lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, Optional< FileEntryRef > &File)
Attempt to resolve the given module file name to a file entry.
Definition: ModuleManager.cpp:460
GraphTraits
clang::GlobalModuleIndex::loadedModuleFile
bool loadedModuleFile(ModuleFile *File)
Note that the given module file has been loaded.
Definition: GlobalModuleIndex.cpp:337
clang::serialization::ModuleManager::lookupByFileName
ModuleFile * lookupByFileName(StringRef FileName) const
Returns the module associated with the given file name.
Definition: ModuleManager.cpp:44
clang::serialization::ModuleManager::ASTFileSignatureReader
ASTFileSignature(*)(StringRef) ASTFileSignatureReader
Definition: ModuleManager.h:212
HeaderSearch.h
clang::FileManager::getBufferForFile
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: FileManager.cpp:521
clang::serialization::ModuleManager::moduleFileAccepted
void moduleFileAccepted(ModuleFile *MF)
Notification from the AST reader that the given module file has been "accepted", and will not (can no...
Definition: ModuleManager.cpp:340
clang::serialization::ModuleManager::NewlyLoaded
@ NewlyLoaded
The module file was just loaded in response to this call.
Definition: ModuleManager.h:203
LLVM.h
clang::serialization::MK_PrebuiltModule
@ MK_PrebuiltModule
File is from a prebuilt module path.
Definition: ModuleFile.h:59
State
LineState State
Definition: UnwrappedLineFormatter.cpp:986
GlobalModuleIndex.h
llvm::GraphTraits< ModuleManager >::nodes_end
static nodes_iterator nodes_end(const ModuleManager &Manager)
Definition: ModuleManager.cpp:507
clang::serialization::ModuleManager::begin
ModuleIterator begin()
Forward iterator to traverse all loaded modules.
Definition: ModuleManager.h:148
ModuleManager.h
PCHContainerOperations.h
clang::serialization::ModuleFile::ModuleName
std::string ModuleName
The name of the module.
Definition: ModuleFile.h:129
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
llvm::DOTGraphTraits< ModuleManager >::renderGraphFromBottomUp
static bool renderGraphFromBottomUp()
Definition: ModuleManager.cpp:517
ModuleFile.h
clang
Definition: CalledOnceCheck.h:17
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::serialization::ModuleFile::Imports
llvm::SetVector< ModuleFile * > Imports
List of modules which this module depends on.
Definition: ModuleFile.h:498
clang::serialization::ModuleFile::ImportLoc
SourceLocation ImportLoc
The source location where this module was first imported.
Definition: ModuleFile.h:218
clang::ComparisonCategoryType::Last
@ Last
clang::serialization::ModuleManager::AddModuleResult
AddModuleResult
The result of attempting to add a new module.
Definition: ModuleManager.h:198
clang::PCHContainerReader::ExtractPCH
virtual llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const =0
Returns the serialized AST inside the PCH container Buffer.
clang::InMemoryModuleCache
In-memory cache for modules.
Definition: InMemoryModuleCache.h:30
clang::serialization::ModuleManager::lookup
ModuleFile * lookup(const FileEntry *File) const
Returns the module associated with the given module file.
Definition: ModuleManager.cpp:61
clang::FileManager::getFile
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:196
llvm::GraphTraits< ModuleManager >::nodes_iterator
pointer_iterator< ModuleManager::ModuleConstIterator > nodes_iterator
Definition: ModuleManager.cpp:493
clang::serialization::ModuleManager::end
ModuleIterator end()
Forward iterator end-point to traverse all loaded modules.
Definition: ModuleManager.h:151
clang::serialization::ModuleKind
ModuleKind
Specifies the kind of module that has been loaded.
Definition: ModuleFile.h:42
FileManager.h
clang::FileManager::getVirtualFile
const FileEntry * getVirtualFile(StringRef Filename, off_t Size, time_t ModificationTime)
Definition: FileManager.cpp:372
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:740
clang::serialization::ModuleFile
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:111
llvm::DOTGraphTraits< ModuleManager >::DOTGraphTraits
DOTGraphTraits(bool IsSimple=false)
Definition: ModuleManager.cpp:514
llvm::GraphTraits< ModuleManager >::nodes_begin
static nodes_iterator nodes_begin(const ModuleManager &Manager)
Definition: ModuleManager.cpp:503