diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -154,12 +154,33 @@ DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename) : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {} - const std::string TheTriple; - const std::string Arch; - const std::string Filename; + std::string TheTriple; + std::string Arch; + std::string Filename; +}; - operator std::string() const { return TheTriple + "-" + Arch; } +namespace llvm { +/// Helper that allows DeviceFile to be used as a key in a DenseMap. +template <> struct DenseMapInfo { + static DeviceFile getEmptyKey() { + return {DenseMapInfo::getEmptyKey(), + DenseMapInfo::getEmptyKey(), + DenseMapInfo::getEmptyKey()}; + } + static DeviceFile getTombstoneKey() { + return {DenseMapInfo::getTombstoneKey(), + DenseMapInfo::getTombstoneKey(), + DenseMapInfo::getTombstoneKey()}; + } + static unsigned getHashValue(const DeviceFile &I) { + return DenseMapInfo::getHashValue(I.TheTriple) ^ + DenseMapInfo::getHashValue(I.Arch); + } + static bool isEqual(const DeviceFile &LHS, const DeviceFile &RHS) { + return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch; + } }; +} // namespace llvm namespace { @@ -1063,28 +1084,28 @@ Error linkDeviceFiles(ArrayRef DeviceFiles, SmallVectorImpl &LinkedImages) { // Get the list of inputs for a specific device. - StringMap> LinkerInputMap; + DenseMap> LinkerInputMap; for (auto &File : DeviceFiles) - LinkerInputMap[StringRef(File)].push_back(File.Filename); + LinkerInputMap[File].push_back(File.Filename); // Try to link each device toolchain. for (auto &LinkerInput : LinkerInputMap) { - auto TargetFeatures = LinkerInput.getKey().rsplit('-'); - Triple TheTriple(TargetFeatures.first); - StringRef Arch(TargetFeatures.second); + DeviceFile &File = LinkerInput.getFirst(); + Triple TheTriple = Triple(File.TheTriple); // Run LTO on any bitcode files and replace the input with the result. - if (Error Err = linkBitcodeFiles(LinkerInput.getValue(), TheTriple, Arch)) + if (Error Err = + linkBitcodeFiles(LinkerInput.getSecond(), TheTriple, File.Arch)) return Err; // If we are embedding bitcode for JIT, skip the final device linking. if (EmbedBitcode) { - assert(!LinkerInput.getValue().empty() && "No bitcode image to embed"); - LinkedImages.push_back(LinkerInput.getValue().front()); + assert(!LinkerInput.getSecond().empty() && "No bitcode image to embed"); + LinkedImages.push_back(LinkerInput.getSecond().front()); continue; } - auto ImageOrErr = linkDevice(LinkerInput.getValue(), TheTriple, Arch); + auto ImageOrErr = linkDevice(LinkerInput.getSecond(), TheTriple, File.Arch); if (!ImageOrErr) return ImageOrErr.takeError();