[llvm] 601ec17 - [Binary] Add iterator to the OffloadBinary string maps
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 15 09:24:33 PDT 2022
Author: Joseph Huber
Date: 2022-06-15T12:24:26-04:00
New Revision: 601ec17d547bf2dc03565b541bae8ec069fbd22b
URL: https://github.com/llvm/llvm-project/commit/601ec17d547bf2dc03565b541bae8ec069fbd22b
DIFF: https://github.com/llvm/llvm-project/commit/601ec17d547bf2dc03565b541bae8ec069fbd22b.diff
LOG: [Binary] Add iterator to the OffloadBinary string maps
The offload binary contains internally a string map of all the key and
value pairs identified in the binary itself. Normally users query these
values from the `getString` function, but this makes it difficult to
identify which strings are availible. This patch adds a simple const
iterator range to the offload binary allowing users to iterate through
the strings.
Reviewed By: tra
Differential Revision: https://reviews.llvm.org/D127774
Added:
Modified:
llvm/include/llvm/Object/OffloadBinary.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h
index 3ff82ec86aa8c..446d52327066b 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -59,6 +59,9 @@ enum ImageKind : uint16_t {
/// offsets from the beginning of the file.
class OffloadBinary : public Binary {
public:
+ using string_iterator = StringMap<StringRef>::const_iterator;
+ using string_iterator_range = iterator_range<string_iterator>;
+
/// The offloading metadata that will be serialized to a memory buffer.
struct OffloadingImage {
ImageKind TheImageKind;
@@ -88,6 +91,11 @@ class OffloadBinary : public Binary {
return StringRef(&Buffer[TheEntry->ImageOffset], TheEntry->ImageSize);
}
+ // Iterator over all the key and value pairs in the binary.
+ string_iterator_range strings() const {
+ return string_iterator_range(StringData.begin(), StringData.end());
+ }
+
StringRef getString(StringRef Key) const { return StringData.lookup(Key); }
static bool classof(const Binary *V) { return V->isOffloadFile(); }
More information about the llvm-commits
mailing list