[llvm] [TextAPI] use unique sorted vector for holding target triples for (PR #75959)
Cyndy Ishida via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 10:28:29 PST 2023
https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/75959
reading dylibs
* This is a better fix than what I originally did to appease CI.
>From f7e64a257ac1654fd60f71cc1427cc1e254db6e4 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida <cyndy_ishida at apple.com>
Date: Tue, 19 Dec 2023 10:25:50 -0800
Subject: [PATCH] [TextAPI] use unique sorted vector for holding target triples
for reading dylibs
* This is a better fix than what I originally did to appease CI.
---
llvm/lib/TextAPI/BinaryReader/DylibReader.cpp | 49 ++++++++++++-------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp b/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
index 846ec9a8460675..b01130cee60620 100644
--- a/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
+++ b/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/TextAPI/DylibReader.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/MachOUniversal.h"
@@ -22,6 +23,7 @@
#include <set>
#include <sstream>
#include <string>
+#include <tuple>
using namespace llvm;
using namespace llvm::object;
@@ -29,6 +31,17 @@ using namespace llvm::MachO;
using namespace llvm::MachO::DylibReader;
using TripleVec = std::vector<Triple>;
+static typename TripleVec::iterator emplace(TripleVec &Container, Triple &&T) {
+ auto I = partition_point(Container, [=](const Triple &CT) {
+ return std::forward_as_tuple(CT.getArch(), CT.getOS(),
+ CT.getEnvironment()) <
+ std::forward_as_tuple(T.getArch(), T.getOS(), T.getEnvironment());
+ });
+
+ if (I != Container.end() && *I == T)
+ return I;
+ return Container.emplace(I, T);
+}
static TripleVec constructTriples(MachOObjectFile *Obj,
const Architecture ArchT) {
@@ -53,61 +66,61 @@ static TripleVec constructTriples(MachOObjectFile *Obj,
switch (cmd.C.cmd) {
case MachO::LC_VERSION_MIN_MACOSX:
OSVersion = getOSVersion(cmd);
- Triples.emplace_back(Arch, "apple", "macos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "macos" + OSVersion});
break;
case MachO::LC_VERSION_MIN_IPHONEOS:
OSVersion = getOSVersion(cmd);
if (IsIntel)
- Triples.emplace_back(Arch, "apple", "ios" + OSVersion, "simulator");
+ emplace(Triples, {Arch, "apple", "ios" + OSVersion, "simulator"});
else
- Triples.emplace_back(Arch, "apple", "ios" + OSVersion);
+ emplace(Triples, {Arch, "apple", "ios" + OSVersion});
break;
case MachO::LC_VERSION_MIN_TVOS:
OSVersion = getOSVersion(cmd);
if (IsIntel)
- Triples.emplace_back(Arch, "apple", "tvos" + OSVersion, "simulator");
+ emplace(Triples, {Arch, "apple", "tvos" + OSVersion, "simulator"});
else
- Triples.emplace_back(Arch, "apple", "tvos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "tvos" + OSVersion});
break;
case MachO::LC_VERSION_MIN_WATCHOS:
OSVersion = getOSVersion(cmd);
if (IsIntel)
- Triples.emplace_back(Arch, "apple", "watchos" + OSVersion, "simulator");
+ emplace(Triples, {Arch, "apple", "watchos" + OSVersion, "simulator"});
else
- Triples.emplace_back(Arch, "apple", "watchos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "watchos" + OSVersion});
break;
case MachO::LC_BUILD_VERSION: {
OSVersion = getOSVersionStr(Obj->getBuildVersionLoadCommand(cmd).minos);
switch (Obj->getBuildVersionLoadCommand(cmd).platform) {
case MachO::PLATFORM_MACOS:
- Triples.emplace_back(Arch, "apple", "macos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "macos" + OSVersion});
break;
case MachO::PLATFORM_IOS:
- Triples.emplace_back(Arch, "apple", "ios" + OSVersion);
+ emplace(Triples, {Arch, "apple", "ios" + OSVersion});
break;
case MachO::PLATFORM_TVOS:
- Triples.emplace_back(Arch, "apple", "tvos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "tvos" + OSVersion});
break;
case MachO::PLATFORM_WATCHOS:
- Triples.emplace_back(Arch, "apple", "watchos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "watchos" + OSVersion});
break;
case MachO::PLATFORM_BRIDGEOS:
- Triples.emplace_back(Arch, "apple", "bridgeos" + OSVersion);
+ emplace(Triples, {Arch, "apple", "bridgeos" + OSVersion});
break;
case MachO::PLATFORM_MACCATALYST:
- Triples.emplace_back(Arch, "apple", "ios" + OSVersion, "macabi");
+ emplace(Triples, {Arch, "apple", "ios" + OSVersion, "macabi"});
break;
case MachO::PLATFORM_IOSSIMULATOR:
- Triples.emplace_back(Arch, "apple", "ios" + OSVersion, "simulator");
+ emplace(Triples, {Arch, "apple", "ios" + OSVersion, "simulator"});
break;
case MachO::PLATFORM_TVOSSIMULATOR:
- Triples.emplace_back(Arch, "apple", "tvos" + OSVersion, "simulator");
+ emplace(Triples, {Arch, "apple", "tvos" + OSVersion, "simulator"});
break;
case MachO::PLATFORM_WATCHOSSIMULATOR:
- Triples.emplace_back(Arch, "apple", "watchos" + OSVersion, "simulator");
+ emplace(Triples, {Arch, "apple", "watchos" + OSVersion, "simulator"});
break;
case MachO::PLATFORM_DRIVERKIT:
- Triples.emplace_back(Arch, "apple", "driverkit" + OSVersion);
+ emplace(Triples, {Arch, "apple", "driverkit" + OSVersion});
break;
default:
break; // Skip any others.
@@ -122,7 +135,7 @@ static TripleVec constructTriples(MachOObjectFile *Obj,
// Record unknown platform for older binaries that don't enforce platform
// load commands.
if (Triples.empty())
- Triples.emplace_back(Arch, "apple", "unknown");
+ emplace(Triples, {Arch, "apple", "unknown"});
return Triples;
}
More information about the llvm-commits
mailing list