Skip to content

Commit ac940f1

Browse files
cyndyishidahyp
authored andcommitted
[TextAPI] Arch&Platform to Target
Summary: This is a patch for updating TextAPI/Macho to read in targets as opposed to arch/platform. This is because in previous versions tbd files only supported a single platform but that is no longer the case, so, now its tracked by unique triples. This precedes a seperate patch that will add the TBD-v4 format Reviewers: ributzka, steven_wu, plotfi, compnerd, smeenai Reviewed By: ributzka Subscribers: mgorny, hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67527 llvm-svn: 372396
1 parent ee5311c commit ac940f1

18 files changed

+609
-201
lines changed

llvm/include/llvm/TextAPI/MachO/Architecture.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_TEXTAPI_MACHO_ARCHITECTURE_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/ADT/Triple.h"
1718
#include "llvm/Support/raw_ostream.h"
1819

1920
namespace llvm {
@@ -39,6 +40,9 @@ StringRef getArchitectureName(Architecture Arch);
3940
/// Convert an architecture slice to a CPU Type and Subtype pair.
4041
std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch);
4142

43+
/// Convert a target to an architecture slice.
44+
Architecture mapToArchitecture(const llvm::Triple &Target);
45+
4246
raw_ostream &operator<<(raw_ostream &OS, Architecture Arch);
4347

4448
} // end namespace MachO.

llvm/include/llvm/TextAPI/MachO/ArchitectureSet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class ArchitectureSet {
5959

6060
ArchSetType rawValue() const { return ArchSet; }
6161

62+
bool hasX86() const {
63+
return has(AK_i386) || has(AK_x86_64) || has(AK_x86_64h);
64+
}
65+
6266
template <typename Ty>
6367
class arch_iterator
6468
: public std::iterator<std::forward_iterator_tag, Architecture, size_t> {

llvm/include/llvm/TextAPI/MachO/InterfaceFile.h

Lines changed: 84 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,13 @@
2626
#include "llvm/TextAPI/MachO/Architecture.h"
2727
#include "llvm/TextAPI/MachO/ArchitectureSet.h"
2828
#include "llvm/TextAPI/MachO/PackedVersion.h"
29+
#include "llvm/TextAPI/MachO/Platform.h"
2930
#include "llvm/TextAPI/MachO/Symbol.h"
31+
#include "llvm/TextAPI/MachO/Target.h"
3032

3133
namespace llvm {
3234
namespace MachO {
3335

34-
/// Defines the list of MachO platforms.
35-
enum class PlatformKind : unsigned {
36-
unknown,
37-
macOS = MachO::PLATFORM_MACOS,
38-
iOS = MachO::PLATFORM_IOS,
39-
tvOS = MachO::PLATFORM_TVOS,
40-
watchOS = MachO::PLATFORM_WATCHOS,
41-
bridgeOS = MachO::PLATFORM_BRIDGEOS,
42-
};
43-
4436
/// Defines a list of Objective-C constraints.
4537
enum class ObjCConstraintType : unsigned {
4638
/// No constraint.
@@ -89,29 +81,42 @@ class InterfaceFileRef {
8981

9082
InterfaceFileRef(StringRef InstallName) : InstallName(InstallName) {}
9183

92-
InterfaceFileRef(StringRef InstallName, ArchitectureSet Archs)
93-
: InstallName(InstallName), Architectures(Archs) {}
84+
InterfaceFileRef(StringRef InstallName, const TargetList Targets)
85+
: InstallName(InstallName), Targets(std::move(Targets)) {}
9486

9587
StringRef getInstallName() const { return InstallName; };
96-
void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; }
97-
ArchitectureSet getArchitectures() const { return Architectures; }
98-
bool hasArchitecture(Architecture Arch) const {
99-
return Architectures.has(Arch);
88+
89+
void addTarget(const Target &Target);
90+
template <typename RangeT> void addTargets(RangeT &&Targets) {
91+
for (const auto &Target : Targets)
92+
addTarget(Target(Target));
10093
}
10194

95+
using const_target_iterator = TargetList::const_iterator;
96+
using const_target_range = llvm::iterator_range<const_target_iterator>;
97+
const_target_range targets() const { return {Targets}; }
98+
99+
ArchitectureSet getArchitectures() const {
100+
return mapToArchitectureSet(Targets);
101+
}
102+
103+
PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); }
104+
102105
bool operator==(const InterfaceFileRef &O) const {
103-
return std::tie(InstallName, Architectures) ==
104-
std::tie(O.InstallName, O.Architectures);
106+
return std::tie(InstallName, Targets) == std::tie(O.InstallName, O.Targets);
107+
}
108+
109+
bool operator!=(const InterfaceFileRef &O) const {
110+
return std::tie(InstallName, Targets) != std::tie(O.InstallName, O.Targets);
105111
}
106112

107113
bool operator<(const InterfaceFileRef &O) const {
108-
return std::tie(InstallName, Architectures) <
109-
std::tie(O.InstallName, O.Architectures);
114+
return std::tie(InstallName, Targets) < std::tie(O.InstallName, O.Targets);
110115
}
111116

112117
private:
113118
std::string InstallName;
114-
ArchitectureSet Architectures;
119+
TargetList Targets;
115120
};
116121

117122
} // end namespace MachO.
@@ -170,27 +175,43 @@ class InterfaceFile {
170175
/// \return The file type.
171176
FileType getFileType() const { return FileKind; }
172177

173-
/// Set the platform.
174-
void setPlatform(PlatformKind Platform_) { Platform = Platform_; }
178+
/// Get the architectures.
179+
///
180+
/// \return The applicable architectures.
181+
ArchitectureSet getArchitectures() const {
182+
return mapToArchitectureSet(Targets);
183+
}
175184

176-
/// Get the platform.
177-
PlatformKind getPlatform() const { return Platform; }
185+
/// Get the platforms.
186+
///
187+
/// \return The applicable platforms.
188+
PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); }
178189

179-
/// Specify the set of supported architectures by this file.
180-
void setArchitectures(ArchitectureSet Architectures_) {
181-
Architectures = Architectures_;
182-
}
190+
/// Set and add target.
191+
///
192+
/// \param Target the target to add into.
193+
void addTarget(const Target &Target);
183194

184-
/// Add the set of supported architectures by this file.
185-
void addArchitectures(ArchitectureSet Architectures_) {
186-
Architectures |= Architectures_;
195+
/// Set and add targets.
196+
///
197+
/// Add the subset of llvm::triples that is supported by Tapi
198+
///
199+
/// \param Targets the collection of targets.
200+
template <typename RangeT> void addTargets(RangeT &&Targets) {
201+
for (const auto &Target_ : Targets)
202+
addTarget(Target(Target_));
187203
}
188204

189-
/// Add supported architecture by this file..
190-
void addArch(Architecture Arch) { Architectures.set(Arch); }
205+
using const_target_iterator = TargetList::const_iterator;
206+
using const_target_range = llvm::iterator_range<const_target_iterator>;
207+
const_target_range targets() const { return {Targets}; }
191208

192-
/// Get the set of supported architectures.
193-
ArchitectureSet getArchitectures() const { return Architectures; }
209+
using const_filtered_target_iterator =
210+
llvm::filter_iterator<const_target_iterator,
211+
std::function<bool(const Target &)>>;
212+
using const_filtered_target_range =
213+
llvm::iterator_range<const_filtered_target_iterator>;
214+
const_filtered_target_range targets(ArchitectureSet Archs) const;
194215

195216
/// Set the install name of the library.
196217
void setInstallName(StringRef InstallName_) { InstallName = InstallName_; }
@@ -244,11 +265,18 @@ class InterfaceFile {
244265
/// Check if this file was generated during InstallAPI.
245266
bool isInstallAPI() const { return IsInstallAPI; }
246267

247-
/// Set the parent umbrella framework.
248-
void setParentUmbrella(StringRef Parent) { ParentUmbrella = Parent; }
268+
/// Set the parent umbrella frameworks.
269+
/// \param Target_ The target applicable to Parent
270+
/// \param Parent The name of Parent
271+
void addParentUmbrella(const Target &Target_, StringRef Parent);
272+
const std::vector<std::pair<Target, std::string>> &umbrellas() const {
273+
return ParentUmbrellas;
274+
}
249275

250276
/// Get the parent umbrella framework.
251-
StringRef getParentUmbrella() const { return ParentUmbrella; }
277+
const std::vector<std::pair<Target, std::string>> getParentUmbrellas() const {
278+
return ParentUmbrellas;
279+
}
252280

253281
/// Add an allowable client.
254282
///
@@ -258,8 +286,8 @@ class InterfaceFile {
258286
/// linker refuses to link this library.
259287
///
260288
/// \param Name The name of the client that is allowed to link this library.
261-
/// \param Architectures The set of architecture for which this applies.
262-
void addAllowableClient(StringRef Name, ArchitectureSet Architectures);
289+
/// \param Target The target triple for which this applies.
290+
void addAllowableClient(StringRef InstallName, const Target &Target);
263291

264292
/// Get the list of allowable clients.
265293
///
@@ -271,9 +299,8 @@ class InterfaceFile {
271299
/// Add a re-exported library.
272300
///
273301
/// \param InstallName The name of the library to re-export.
274-
/// \param Architectures The set of architecture for which this applies.
275-
void addReexportedLibrary(StringRef InstallName,
276-
ArchitectureSet Architectures);
302+
/// \param Target The target triple for which this applies.
303+
void addReexportedLibrary(StringRef InstallName, const Target &Target);
277304

278305
/// Get the list of re-exported libraries.
279306
///
@@ -282,27 +309,27 @@ class InterfaceFile {
282309
return ReexportedLibraries;
283310
}
284311

285-
/// Add an architecture/UUID pair.
312+
/// Add an Target/UUID pair.
286313
///
287-
/// \param Arch The architecture for which this applies.
314+
/// \param Target The target triple for which this applies.
288315
/// \param UUID The UUID of the library for the specified architecture.
289-
void addUUID(Architecture Arch, StringRef UUID);
316+
void addUUID(const Target &Target, StringRef UUID);
290317

291-
/// Add an architecture/UUID pair.
318+
/// Add an Target/UUID pair.
292319
///
293-
/// \param Arch The architecture for which this applies.
320+
/// \param Target The target triple for which this applies.
294321
/// \param UUID The UUID of the library for the specified architecture.
295-
void addUUID(Architecture Arch, uint8_t UUID[16]);
322+
void addUUID(const Target &Target, uint8_t UUID[16]);
296323

297-
/// Get the list of architecture/UUID pairs.
324+
/// Get the list of Target/UUID pairs.
298325
///
299-
/// \return Returns a list of architecture/UUID pairs.
300-
const std::vector<std::pair<Architecture, std::string>> &uuids() const {
326+
/// \return Returns a list of Target/UUID pairs.
327+
const std::vector<std::pair<Target, std::string>> &uuids() const {
301328
return UUIDs;
302329
}
303330

304331
/// Add a symbol to the symbols list or extend an existing one.
305-
void addSymbol(SymbolKind Kind, StringRef Name, ArchitectureSet Architectures,
332+
void addSymbol(SymbolKind Kind, StringRef Name, const TargetList &Targets,
306333
SymbolFlags Flags = SymbolFlags::None);
307334

308335
using SymbolMapType = DenseMap<SymbolsMapKey, Symbol *>;
@@ -411,10 +438,9 @@ class InterfaceFile {
411438
return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
412439
}
413440

441+
TargetList Targets;
414442
std::string Path;
415443
FileType FileKind;
416-
PlatformKind Platform;
417-
ArchitectureSet Architectures;
418444
std::string InstallName;
419445
PackedVersion CurrentVersion;
420446
PackedVersion CompatibilityVersion;
@@ -423,10 +449,10 @@ class InterfaceFile {
423449
bool IsAppExtensionSafe{false};
424450
bool IsInstallAPI{false};
425451
ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;
426-
std::string ParentUmbrella;
452+
std::vector<std::pair<Target, std::string>> ParentUmbrellas;
427453
std::vector<InterfaceFileRef> AllowableClients;
428454
std::vector<InterfaceFileRef> ReexportedLibraries;
429-
std::vector<std::pair<Architecture, std::string>> UUIDs;
455+
std::vector<std::pair<Target, std::string>> UUIDs;
430456
SymbolMapType Symbols;
431457
};
432458

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- llvm/TextAPI/MachO/Platform.h - Platform -----------------*- C++ -*-===//
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+
// Defines the Platforms supported by Tapi and helpers.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
#ifndef LLVM_TEXTAPI_MACHO_PLATFORM_H
13+
#define LLVM_TEXTAPI_MACHO_PLATFORM_H
14+
15+
#include "llvm/ADT/SmallSet.h"
16+
#include "llvm/BinaryFormat/MachO.h"
17+
18+
namespace llvm {
19+
namespace MachO {
20+
21+
/// Defines the list of MachO platforms.
22+
enum class PlatformKind : unsigned {
23+
unknown,
24+
macOS = MachO::PLATFORM_MACOS,
25+
iOS = MachO::PLATFORM_IOS,
26+
tvOS = MachO::PLATFORM_TVOS,
27+
watchOS = MachO::PLATFORM_WATCHOS,
28+
bridgeOS = MachO::PLATFORM_BRIDGEOS
29+
};
30+
31+
using PlatformSet = SmallSet<PlatformKind, 3>;
32+
33+
PlatformKind mapToPlatformKind(const Triple &Target);
34+
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
35+
StringRef getPlatformName(PlatformKind Platform);
36+
37+
} // end namespace MachO.
38+
} // end namespace llvm.
39+
40+
#endif // LLVM_TEXTAPI_MACHO_PLATFORM_H

llvm/include/llvm/TextAPI/MachO/Symbol.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/Support/Error.h"
1515
#include "llvm/Support/raw_ostream.h"
1616
#include "llvm/TextAPI/MachO/ArchitectureSet.h"
17+
#include "llvm/TextAPI/MachO/Target.h"
1718

1819
namespace llvm {
1920
namespace MachO {
@@ -49,16 +50,18 @@ enum class SymbolKind : uint8_t {
4950
ObjectiveCInstanceVariable,
5051
};
5152

53+
using TargetList = SmallVector<Target, 20>;
5254
class Symbol {
5355
public:
54-
constexpr Symbol(SymbolKind Kind, StringRef Name,
55-
ArchitectureSet Architectures, SymbolFlags Flags)
56-
: Name(Name), Architectures(Architectures), Kind(Kind), Flags(Flags) {}
56+
Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
57+
: Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
5758

59+
void addTarget(Target target) { Targets.emplace_back(target); }
5860
SymbolKind getKind() const { return Kind; }
5961
StringRef getName() const { return Name; }
60-
ArchitectureSet getArchitectures() const { return Architectures; }
61-
void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; }
62+
ArchitectureSet getArchitectures() const {
63+
return mapToArchitectureSet(Targets);
64+
}
6265
SymbolFlags getFlags() const { return Flags; }
6366

6467
bool isWeakDefined() const {
@@ -78,14 +81,25 @@ class Symbol {
7881
return (Flags & SymbolFlags::Undefined) == SymbolFlags::Undefined;
7982
}
8083

84+
using const_target_iterator = TargetList::const_iterator;
85+
using const_target_range = llvm::iterator_range<const_target_iterator>;
86+
const_target_range targets() const { return {Targets}; }
87+
88+
using const_filtered_target_iterator =
89+
llvm::filter_iterator<const_target_iterator,
90+
std::function<bool(const Target &)>>;
91+
using const_filtered_target_range =
92+
llvm::iterator_range<const_filtered_target_iterator>;
93+
const_filtered_target_range targets(ArchitectureSet architectures) const;
94+
8195
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
8296
void dump(raw_ostream &OS) const;
8397
void dump() const { dump(llvm::errs()); }
8498
#endif
8599

86100
private:
87101
StringRef Name;
88-
ArchitectureSet Architectures;
102+
TargetList Targets;
89103
SymbolKind Kind;
90104
SymbolFlags Flags;
91105
};

0 commit comments

Comments
 (0)