LLVM 24.0.0git
ModulePool.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_MODULEPOOL_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_MODULEPOOL_H
11
12#include "TypePool.h"
13#include "llvm/ADT/StringMap.h"
14#include <limits>
15#include <mutex>
16
17namespace llvm {
18namespace dwarf_linker {
19namespace parallel {
20
22
23/// Where the DW_TAG_module DIE describing a clang module ended up in the
24/// output. Clang imposes a one-definition rule (ODR) on module names regardless
25/// of the source language, so a module is described once and every importer
26/// resolves to that description.
27///
28/// A module DIE lands either in the artificial type unit, or in the plain DWARF
29/// of the unit which emitted it.
31 bool isSet() const { return TypeName != nullptr || Section != nullptr; }
32
33 TypeEntry *TypeName = nullptr;
36
37 /// Priority of the unit which recorded this anchor.
38 uint64_t Priority = std::numeric_limits<uint64_t>::max();
39};
40
42public:
44 std::lock_guard<std::mutex> Guard(Mutex);
45
46 // The underlying StringMap guarantees the pointer remains stable. The
47 // pointee is written while cloning, so it may only be read afterwards.
48 return &Anchors[Path];
49 }
50
51 void set(StringRef Path, const ModuleAnchor &Location) {
52 std::lock_guard<std::mutex> Guard(Mutex);
53
54 // Anchors are keyed by module name while a unit is created per .pcm, so a
55 // module built more than once has a unit for each copy. The lowest priority
56 // wins, as in the type pool, guaranteeing determinism.
57 ModuleAnchor &Anchor = Anchors[Path];
58 if (!Anchor.isSet() || Location.Priority < Anchor.Priority)
59 Anchor = Location;
60 }
61
62private:
63 /// Unlike the type pool this is not a per-DIE structure. It is accessed once
64 /// for each DW_TAG_module cloned and once for each DW_AT_import cloned.
65 std::mutex Mutex;
67};
68
69} // end of namespace parallel
70} // end of namespace dwarf_linker
71} // end of namespace llvm
72
73#endif // LLVM_LIB_DWARFLINKER_PARALLEL_MODULEPOOL_H
This file defines the StringMap class.
unsigned uint64_t
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:128
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
void set(StringRef Path, const ModuleAnchor &Location)
Definition ModulePool.h:51
ModuleAnchor * getOrCreate(StringRef Path)
Definition ModulePool.h:43
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
Definition TypePool.h:28
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
Definition Mutex.h:66
This is an optimization pass for GlobalISel generic memory operations.
Where the DW_TAG_module DIE describing a clang module ended up in the output.
Definition ModulePool.h:30
uint64_t Priority
Priority of the unit which recorded this anchor.
Definition ModulePool.h:38
This structure is used to keep data of the concrete section.