LLVM  14.0.0git
InterfaceFile.cpp
Go to the documentation of this file.
1 //===- InterfaceFile.cpp --------------------------------------------------===//
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 // Implements the Interface File.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include <iomanip>
15 #include <sstream>
16 
17 using namespace llvm;
18 using namespace llvm::MachO;
19 
20 namespace {
21 template <typename C>
22 typename C::iterator addEntry(C &Container, StringRef InstallName) {
23  auto I = partition_point(Container, [=](const InterfaceFileRef &O) {
24  return O.getInstallName() < InstallName;
25  });
26  if (I != Container.end() && I->getInstallName() == InstallName)
27  return I;
28 
29  return Container.emplace(I, InstallName);
30 }
31 
32 template <typename C>
33 typename C::iterator addEntry(C &Container, const Target &Target_) {
34  auto Iter =
35  lower_bound(Container, Target_, [](const Target &LHS, const Target &RHS) {
36  return LHS < RHS;
37  });
38  if ((Iter != std::end(Container)) && !(Target_ < *Iter))
39  return Iter;
40 
41  return Container.insert(Iter, Target_);
42 }
43 } // end namespace
44 
46  addEntry(Targets, Target);
47 }
48 
50  const Target &Target) {
51  auto Client = addEntry(AllowableClients, InstallName);
52  Client->addTarget(Target);
53 }
54 
56  const Target &Target) {
57  auto Lib = addEntry(ReexportedLibraries, InstallName);
58  Lib->addTarget(Target);
59 }
60 
61 void InterfaceFile::addParentUmbrella(const Target &Target_, StringRef Parent) {
62  auto Iter = lower_bound(ParentUmbrellas, Target_,
63  [](const std::pair<Target, std::string> &LHS,
64  Target RHS) { return LHS.first < RHS; });
65 
66  if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {
67  Iter->second = std::string(Parent);
68  return;
69  }
70 
71  ParentUmbrellas.emplace(Iter, Target_, std::string(Parent));
72 }
73 
75  auto Iter = lower_bound(UUIDs, Target_,
76  [](const std::pair<Target, std::string> &LHS,
77  Target RHS) { return LHS.first < RHS; });
78 
79  if ((Iter != UUIDs.end()) && !(Target_ < Iter->first)) {
80  Iter->second = std::string(UUID);
81  return;
82  }
83 
84  UUIDs.emplace(Iter, Target_, std::string(UUID));
85 }
86 
87 void InterfaceFile::addUUID(const Target &Target, uint8_t UUID[16]) {
88  std::stringstream Stream;
89  for (unsigned i = 0; i < 16; ++i) {
90  if (i == 4 || i == 6 || i == 8 || i == 10)
91  Stream << '-';
92  Stream << std::setfill('0') << std::setw(2) << std::uppercase << std::hex
93  << static_cast<int>(UUID[i]);
94  }
95  addUUID(Target, Stream.str());
96 }
97 
99  addEntry(Targets, Target);
100 }
101 
104  std::function<bool(const Target &)> fn = [Archs](const Target &Target_) {
105  return Archs.has(Target_.Arch);
106  };
107  return make_filter_range(Targets, fn);
108 }
109 
111  const TargetList &Targets, SymbolFlags Flags) {
112  Name = copyString(Name);
113  auto result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
114  if (result.second)
115  result.first->second = new (Allocator) Symbol{Kind, Name, Targets, Flags};
116  else
117  for (const auto &Target : Targets)
118  result.first->second->addTarget(Target);
119 }
120 
121 void InterfaceFile::addDocument(std::shared_ptr<InterfaceFile> &&Document) {
122  auto Pos = llvm::lower_bound(Documents, Document,
123  [](const std::shared_ptr<InterfaceFile> &LHS,
124  const std::shared_ptr<InterfaceFile> &RHS) {
125  return LHS->InstallName < RHS->InstallName;
126  });
127  Document->Parent = this;
128  Documents.insert(Pos, Document);
129 }
130 
132  if (Targets != O.Targets)
133  return false;
134  if (InstallName != O.InstallName)
135  return false;
136  if ((CurrentVersion != O.CurrentVersion) ||
137  (CompatibilityVersion != O.CompatibilityVersion))
138  return false;
139  if (SwiftABIVersion != O.SwiftABIVersion)
140  return false;
141  if (IsTwoLevelNamespace != O.IsTwoLevelNamespace)
142  return false;
143  if (IsAppExtensionSafe != O.IsAppExtensionSafe)
144  return false;
145  if (IsInstallAPI != O.IsInstallAPI)
146  return false;
147  if (ParentUmbrellas != O.ParentUmbrellas)
148  return false;
149  if (AllowableClients != O.AllowableClients)
150  return false;
151  if (ReexportedLibraries != O.ReexportedLibraries)
152  return false;
153  if (Symbols != O.Symbols)
154  return false;
155  if (!std::equal(Documents.begin(), Documents.end(), O.Documents.begin(),
156  O.Documents.end(),
157  [](const std::shared_ptr<InterfaceFile> LHS,
158  const std::shared_ptr<InterfaceFile> RHS) {
159  return *LHS == *RHS;
160  }))
161  return false;
162  return true;
163 }
i
i
Definition: README.txt:29
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MachO::InterfaceFile::addSymbol
void addSymbol(SymbolKind Kind, StringRef Name, const TargetList &Targets, SymbolFlags Flags=SymbolFlags::None)
Add a symbol to the symbols list or extend an existing one.
Definition: InterfaceFile.cpp:110
llvm::lower_bound
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1657
llvm::MachO::InterfaceFile::addReexportedLibrary
void addReexportedLibrary(StringRef InstallName, const Target &Target)
Add a re-exported library.
Definition: InterfaceFile.cpp:55
llvm::MachO::InterfaceFile::addTarget
void addTarget(const Target &Target)
Set and add target.
Definition: InterfaceFile.cpp:98
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::SmallVector< Target, 5 >
llvm::MachO::Target
Definition: Target.h:24
llvm::MachO::SymbolKind
SymbolKind
Definition: Symbol.h:49
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::SymbolsMapKey
Definition: InterfaceFile.h:127
llvm::MachO
Definition: MachO.h:25
llvm::MachO::SymbolFlags
SymbolFlags
Symbol flags.
Definition: Symbol.h:25
llvm::lltok::equal
@ equal
Definition: LLToken.h:25
result
It looks like we only need to define PPCfmarto for these because according to these instructions perform RTO on fma s result
Definition: README_P9.txt:256
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::MachO::ArchitectureSet::has
bool has(Architecture Arch) const
Definition: ArchitectureSet.h:51
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MachO::InterfaceFile::targets
const_target_range targets() const
Definition: InterfaceFile.h:210
llvm::MachO::ArchitectureSet
Definition: ArchitectureSet.h:29
llvm::MachO::InterfaceFileRef::addTarget
void addTarget(const Target &Target)
Definition: InterfaceFile.cpp:45
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:192
llvm::MachO::InterfaceFile::operator==
bool operator==(const InterfaceFile &O) const
The equality is determined by attributes that impact linking compatibilities.
Definition: InterfaceFile.cpp:131
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MachO::InterfaceFile
Defines the interface file.
Definition: InterfaceFile.h:156
llvm::MachO::InterfaceFileRef
Reference to an interface file.
Definition: InterfaceFile.h:81
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
UUID
std::pair< llvm::MachO::Target, std::string > UUID
Definition: TextStubCommon.h:23
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MachO::Symbol
Definition: Symbol.h:63
llvm::make_filter_range
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:486
llvm::partition_point
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:1695
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MachO::InterfaceFile::addAllowableClient
void addAllowableClient(StringRef InstallName, const Target &Target)
Add an allowable client.
Definition: InterfaceFile.cpp:49
llvm::MachO::InterfaceFile::addUUID
void addUUID(const Target &Target, StringRef UUID)
Add an Target/UUID pair.
Definition: InterfaceFile.cpp:74
llvm::DenseMapBase::try_emplace
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Definition: DenseMap.h:222
llvm::MachO::InterfaceFile::addParentUmbrella
void addParentUmbrella(const Target &Target_, StringRef Parent)
Set the parent umbrella frameworks.
Definition: InterfaceFile.cpp:61
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::MachO::InterfaceFile::addDocument
void addDocument(std::shared_ptr< InterfaceFile > &&Document)
Add a library for inlining to top level library.
Definition: InterfaceFile.cpp:121
InterfaceFile.h