LLVM 23.0.0git
OffloadEmitter.cpp
Go to the documentation of this file.
1//===- OffloadEmitter.cpp -------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13
14using namespace llvm;
15using namespace OffloadYAML;
16
17namespace llvm {
18namespace yaml {
19
22 for (const auto &Member : Doc.Members) {
24 if (Member.ImageKind)
25 Image.TheImageKind = *Member.ImageKind;
26 if (Member.OffloadKind)
27 Image.TheOffloadKind = *Member.OffloadKind;
28 if (Member.Flags)
29 Image.Flags = *Member.Flags;
30
31 if (Member.StringEntries)
32 for (const auto &Entry : *Member.StringEntries)
33 Image.StringData[Entry.Key] = Entry.Value;
34
37 if (Member.Content)
38 Member.Content->writeAsBinary(OS);
39 Image.Image = MemoryBuffer::getMemBufferCopy(OS.str());
40 Images.push_back(std::move(Image));
41 }
42
43 // Copy the data to a new buffer so we can modify the bytes directly.
44 auto Buffer = object::OffloadBinary::write(Images);
45 auto *TheHeader =
46 reinterpret_cast<object::OffloadBinary::Header *>(&Buffer[0]);
47 if (Doc.Version)
48 TheHeader->Version = *Doc.Version;
49 if (Doc.Size)
50 TheHeader->Size = *Doc.Size;
51 if (Doc.EntriesOffset)
52 TheHeader->EntriesOffset = *Doc.EntriesOffset;
53 if (Doc.EntriesCount)
54 TheHeader->EntriesCount = *Doc.EntriesCount;
55
56 Out.write(Buffer.begin(), Buffer.size());
57
58 return true;
59}
60
61} // namespace yaml
62} // namespace llvm
This file declares classes for handling the YAML representation of offloading binaries.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI SmallString< 0 > write(ArrayRef< OffloadingImage > OffloadingData)
Serialize the contents of OffloadingData to a binary buffer to be read later.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
llvm::function_ref< void(const Twine &Msg)> ErrorHandler
Definition yaml2obj.h:68
LLVM_ABI bool yaml2offload(OffloadYAML::Binary &Doc, raw_ostream &Out, ErrorHandler EH)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
std::optional< uint64_t > EntriesOffset
Definition OffloadYAML.h:42
std::optional< uint32_t > Version
Definition OffloadYAML.h:40
std::optional< uint64_t > Size
Definition OffloadYAML.h:41
std::vector< Member > Members
Definition OffloadYAML.h:44
std::optional< uint64_t > EntriesCount
Definition OffloadYAML.h:43
The offloading metadata that will be serialized to a memory buffer.
Common declarations for yaml2obj.