Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cherry-picks from stable/20190619 into swift/master #71

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/TextAPI/MachO/Architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_TEXTAPI_MACHO_ARCHITECTURE_H

#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/raw_ostream.h"

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

/// Convert a target to an architecture slice.
Architecture mapToArchitecture(const llvm::Triple &Target);

raw_ostream &operator<<(raw_ostream &OS, Architecture Arch);

} // end namespace MachO.
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/TextAPI/MachO/ArchitectureSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class ArchitectureSet {

ArchSetType rawValue() const { return ArchSet; }

bool hasX86() const {
return has(AK_i386) || has(AK_x86_64) || has(AK_x86_64h);
}

template <typename Ty>
class arch_iterator
: public std::iterator<std::forward_iterator_tag, Architecture, size_t> {
Expand Down
142 changes: 84 additions & 58 deletions llvm/include/llvm/TextAPI/MachO/InterfaceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,13 @@
#include "llvm/TextAPI/MachO/Architecture.h"
#include "llvm/TextAPI/MachO/ArchitectureSet.h"
#include "llvm/TextAPI/MachO/PackedVersion.h"
#include "llvm/TextAPI/MachO/Platform.h"
#include "llvm/TextAPI/MachO/Symbol.h"
#include "llvm/TextAPI/MachO/Target.h"

namespace llvm {
namespace MachO {

/// Defines the list of MachO platforms.
enum class PlatformKind : unsigned {
unknown,
macOS = MachO::PLATFORM_MACOS,
iOS = MachO::PLATFORM_IOS,
tvOS = MachO::PLATFORM_TVOS,
watchOS = MachO::PLATFORM_WATCHOS,
bridgeOS = MachO::PLATFORM_BRIDGEOS,
};

/// Defines a list of Objective-C constraints.
enum class ObjCConstraintType : unsigned {
/// No constraint.
Expand Down Expand Up @@ -89,29 +81,42 @@ class InterfaceFileRef {

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

InterfaceFileRef(StringRef InstallName, ArchitectureSet Archs)
: InstallName(InstallName), Architectures(Archs) {}
InterfaceFileRef(StringRef InstallName, const TargetList Targets)
: InstallName(InstallName), Targets(std::move(Targets)) {}

StringRef getInstallName() const { return InstallName; };
void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; }
ArchitectureSet getArchitectures() const { return Architectures; }
bool hasArchitecture(Architecture Arch) const {
return Architectures.has(Arch);

void addTarget(const Target &Target);
template <typename RangeT> void addTargets(RangeT &&Targets) {
for (const auto &Target : Targets)
addTarget(Target(Target));
}

using const_target_iterator = TargetList::const_iterator;
using const_target_range = llvm::iterator_range<const_target_iterator>;
const_target_range targets() const { return {Targets}; }

ArchitectureSet getArchitectures() const {
return mapToArchitectureSet(Targets);
}

PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); }

bool operator==(const InterfaceFileRef &O) const {
return std::tie(InstallName, Architectures) ==
std::tie(O.InstallName, O.Architectures);
return std::tie(InstallName, Targets) == std::tie(O.InstallName, O.Targets);
}

bool operator!=(const InterfaceFileRef &O) const {
return std::tie(InstallName, Targets) != std::tie(O.InstallName, O.Targets);
}

bool operator<(const InterfaceFileRef &O) const {
return std::tie(InstallName, Architectures) <
std::tie(O.InstallName, O.Architectures);
return std::tie(InstallName, Targets) < std::tie(O.InstallName, O.Targets);
}

private:
std::string InstallName;
ArchitectureSet Architectures;
TargetList Targets;
};

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

/// Set the platform.
void setPlatform(PlatformKind Platform_) { Platform = Platform_; }
/// Get the architectures.
///
/// \return The applicable architectures.
ArchitectureSet getArchitectures() const {
return mapToArchitectureSet(Targets);
}

/// Get the platform.
PlatformKind getPlatform() const { return Platform; }
/// Get the platforms.
///
/// \return The applicable platforms.
PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); }

/// Specify the set of supported architectures by this file.
void setArchitectures(ArchitectureSet Architectures_) {
Architectures = Architectures_;
}
/// Set and add target.
///
/// \param Target the target to add into.
void addTarget(const Target &Target);

/// Add the set of supported architectures by this file.
void addArchitectures(ArchitectureSet Architectures_) {
Architectures |= Architectures_;
/// Set and add targets.
///
/// Add the subset of llvm::triples that is supported by Tapi
///
/// \param Targets the collection of targets.
template <typename RangeT> void addTargets(RangeT &&Targets) {
for (const auto &Target_ : Targets)
addTarget(Target(Target_));
}

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

/// Get the set of supported architectures.
ArchitectureSet getArchitectures() const { return Architectures; }
using const_filtered_target_iterator =
llvm::filter_iterator<const_target_iterator,
std::function<bool(const Target &)>>;
using const_filtered_target_range =
llvm::iterator_range<const_filtered_target_iterator>;
const_filtered_target_range targets(ArchitectureSet Archs) const;

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

/// Set the parent umbrella framework.
void setParentUmbrella(StringRef Parent) { ParentUmbrella = Parent; }
/// Set the parent umbrella frameworks.
/// \param Target_ The target applicable to Parent
/// \param Parent The name of Parent
void addParentUmbrella(const Target &Target_, StringRef Parent);
const std::vector<std::pair<Target, std::string>> &umbrellas() const {
return ParentUmbrellas;
}

/// Get the parent umbrella framework.
StringRef getParentUmbrella() const { return ParentUmbrella; }
const std::vector<std::pair<Target, std::string>> getParentUmbrellas() const {
return ParentUmbrellas;
}

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

/// Get the list of allowable clients.
///
Expand All @@ -271,9 +299,8 @@ class InterfaceFile {
/// Add a re-exported library.
///
/// \param InstallName The name of the library to re-export.
/// \param Architectures The set of architecture for which this applies.
void addReexportedLibrary(StringRef InstallName,
ArchitectureSet Architectures);
/// \param Target The target triple for which this applies.
void addReexportedLibrary(StringRef InstallName, const Target &Target);

/// Get the list of re-exported libraries.
///
Expand All @@ -282,27 +309,27 @@ class InterfaceFile {
return ReexportedLibraries;
}

/// Add an architecture/UUID pair.
/// Add an Target/UUID pair.
///
/// \param Arch The architecture for which this applies.
/// \param Target The target triple for which this applies.
/// \param UUID The UUID of the library for the specified architecture.
void addUUID(Architecture Arch, StringRef UUID);
void addUUID(const Target &Target, StringRef UUID);

/// Add an architecture/UUID pair.
/// Add an Target/UUID pair.
///
/// \param Arch The architecture for which this applies.
/// \param Target The target triple for which this applies.
/// \param UUID The UUID of the library for the specified architecture.
void addUUID(Architecture Arch, uint8_t UUID[16]);
void addUUID(const Target &Target, uint8_t UUID[16]);

/// Get the list of architecture/UUID pairs.
/// Get the list of Target/UUID pairs.
///
/// \return Returns a list of architecture/UUID pairs.
const std::vector<std::pair<Architecture, std::string>> &uuids() const {
/// \return Returns a list of Target/UUID pairs.
const std::vector<std::pair<Target, std::string>> &uuids() const {
return UUIDs;
}

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

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

TargetList Targets;
std::string Path;
FileType FileKind;
PlatformKind Platform;
ArchitectureSet Architectures;
std::string InstallName;
PackedVersion CurrentVersion;
PackedVersion CompatibilityVersion;
Expand All @@ -423,10 +449,10 @@ class InterfaceFile {
bool IsAppExtensionSafe{false};
bool IsInstallAPI{false};
ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;
std::string ParentUmbrella;
std::vector<std::pair<Target, std::string>> ParentUmbrellas;
std::vector<InterfaceFileRef> AllowableClients;
std::vector<InterfaceFileRef> ReexportedLibraries;
std::vector<std::pair<Architecture, std::string>> UUIDs;
std::vector<std::pair<Target, std::string>> UUIDs;
SymbolMapType Symbols;
};

Expand Down
40 changes: 40 additions & 0 deletions llvm/include/llvm/TextAPI/MachO/Platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===- llvm/TextAPI/MachO/Platform.h - Platform -----------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// Defines the Platforms supported by Tapi and helpers.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TEXTAPI_MACHO_PLATFORM_H
#define LLVM_TEXTAPI_MACHO_PLATFORM_H

#include "llvm/ADT/SmallSet.h"
#include "llvm/BinaryFormat/MachO.h"

namespace llvm {
namespace MachO {

/// Defines the list of MachO platforms.
enum class PlatformKind : unsigned {
unknown,
macOS = MachO::PLATFORM_MACOS,
iOS = MachO::PLATFORM_IOS,
tvOS = MachO::PLATFORM_TVOS,
watchOS = MachO::PLATFORM_WATCHOS,
bridgeOS = MachO::PLATFORM_BRIDGEOS
};

using PlatformSet = SmallSet<PlatformKind, 3>;

PlatformKind mapToPlatformKind(const Triple &Target);
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
StringRef getPlatformName(PlatformKind Platform);

} // end namespace MachO.
} // end namespace llvm.

#endif // LLVM_TEXTAPI_MACHO_PLATFORM_H
26 changes: 20 additions & 6 deletions llvm/include/llvm/TextAPI/MachO/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TextAPI/MachO/ArchitectureSet.h"
#include "llvm/TextAPI/MachO/Target.h"

namespace llvm {
namespace MachO {
Expand Down Expand Up @@ -49,16 +50,18 @@ enum class SymbolKind : uint8_t {
ObjectiveCInstanceVariable,
};

using TargetList = SmallVector<Target, 20>;
class Symbol {
public:
constexpr Symbol(SymbolKind Kind, StringRef Name,
ArchitectureSet Architectures, SymbolFlags Flags)
: Name(Name), Architectures(Architectures), Kind(Kind), Flags(Flags) {}
Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
: Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}

void addTarget(Target target) { Targets.emplace_back(target); }
SymbolKind getKind() const { return Kind; }
StringRef getName() const { return Name; }
ArchitectureSet getArchitectures() const { return Architectures; }
void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; }
ArchitectureSet getArchitectures() const {
return mapToArchitectureSet(Targets);
}
SymbolFlags getFlags() const { return Flags; }

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

using const_target_iterator = TargetList::const_iterator;
using const_target_range = llvm::iterator_range<const_target_iterator>;
const_target_range targets() const { return {Targets}; }

using const_filtered_target_iterator =
llvm::filter_iterator<const_target_iterator,
std::function<bool(const Target &)>>;
using const_filtered_target_range =
llvm::iterator_range<const_filtered_target_iterator>;
const_filtered_target_range targets(ArchitectureSet architectures) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void dump(raw_ostream &OS) const;
void dump() const { dump(llvm::errs()); }
#endif

private:
StringRef Name;
ArchitectureSet Architectures;
TargetList Targets;
SymbolKind Kind;
SymbolFlags Flags;
};
Expand Down
Loading