This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG06b336c4cd2c: [OpenMP] Implement dense map info for device file (authored by jhuber6).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D120288/new/ https://reviews.llvm.org/D120288 Files: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp =================================================================== --- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ 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<DeviceFile> { + static DeviceFile getEmptyKey() { + return {DenseMapInfo<StringRef>::getEmptyKey(), + DenseMapInfo<StringRef>::getEmptyKey(), + DenseMapInfo<StringRef>::getEmptyKey()}; + } + static DeviceFile getTombstoneKey() { + return {DenseMapInfo<StringRef>::getTombstoneKey(), + DenseMapInfo<StringRef>::getTombstoneKey(), + DenseMapInfo<StringRef>::getTombstoneKey()}; + } + static unsigned getHashValue(const DeviceFile &I) { + return DenseMapInfo<StringRef>::getHashValue(I.TheTriple) ^ + DenseMapInfo<StringRef>::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<DeviceFile> DeviceFiles, SmallVectorImpl<std::string> &LinkedImages) { // Get the list of inputs for a specific device. - StringMap<SmallVector<std::string, 4>> LinkerInputMap; + DenseMap<DeviceFile, SmallVector<std::string, 4>> 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();
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp =================================================================== --- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ 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<DeviceFile> { + static DeviceFile getEmptyKey() { + return {DenseMapInfo<StringRef>::getEmptyKey(), + DenseMapInfo<StringRef>::getEmptyKey(), + DenseMapInfo<StringRef>::getEmptyKey()}; + } + static DeviceFile getTombstoneKey() { + return {DenseMapInfo<StringRef>::getTombstoneKey(), + DenseMapInfo<StringRef>::getTombstoneKey(), + DenseMapInfo<StringRef>::getTombstoneKey()}; + } + static unsigned getHashValue(const DeviceFile &I) { + return DenseMapInfo<StringRef>::getHashValue(I.TheTriple) ^ + DenseMapInfo<StringRef>::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<DeviceFile> DeviceFiles, SmallVectorImpl<std::string> &LinkedImages) { // Get the list of inputs for a specific device. - StringMap<SmallVector<std::string, 4>> LinkerInputMap; + DenseMap<DeviceFile, SmallVector<std::string, 4>> 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();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits