LLVM  16.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 
12 #include "llvm/Support/Error.h"
14 
15 using namespace llvm;
16 using namespace OffloadYAML;
17 
18 namespace llvm {
19 namespace yaml {
20 
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  StringMap<StringRef> &StringData = Image.StringData;
32  if (Member.StringEntries) {
33  for (const auto &Entry : *Member.StringEntries) {
34  StringData[Entry.Key] = Entry.Value;
35  }
36  }
37 
40  if (Member.Content)
41  Member.Content->writeAsBinary(OS);
42  Image.Image = MemoryBuffer::getMemBufferCopy(OS.str());
43 
44  std::unique_ptr<MemoryBuffer> Binary = object::OffloadBinary::write(Image);
45 
46  // Copy the data to a new buffer so we can modify the bytes directly.
47  SmallVector<char> NewBuffer;
48  std::copy(Binary->getBufferStart(), Binary->getBufferEnd(),
49  std::back_inserter(NewBuffer));
50  auto *TheHeader =
51  reinterpret_cast<object::OffloadBinary::Header *>(&NewBuffer[0]);
52  if (Doc.Version)
53  TheHeader->Version = *Doc.Version;
54  if (Doc.Size)
55  TheHeader->Size = *Doc.Size;
56  if (Doc.EntryOffset)
57  TheHeader->EntryOffset = *Doc.EntryOffset;
58  if (Doc.EntrySize)
59  TheHeader->EntrySize = *Doc.EntrySize;
60 
61  Out.write(NewBuffer.begin(), NewBuffer.size());
62  }
63 
64  return true;
65 }
66 
67 } // namespace yaml
68 } // namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OffloadYAML.h
llvm::OffloadYAML::Binary::Size
Optional< uint64_t > Size
Definition: OffloadYAML.h:41
llvm::SmallVector< char, 1024 >
Error.h
llvm::object::OffloadBinary::OffloadingImage
The offloading metadata that will be serialized to a memory buffer.
Definition: OffloadBinary.h:69
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::object::OffloadBinary::Header::Version
uint32_t Version
Definition: OffloadBinary.h:108
llvm::object::OffloadBinary::write
static std::unique_ptr< MemoryBuffer > write(const OffloadingImage &)
Serialize the contents of File to a binary buffer to be read later.
Definition: OffloadBinary.cpp:208
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:218
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::OffloadYAML::Binary::Version
Optional< uint32_t > Version
Definition: OffloadYAML.h:40
llvm::yaml::yaml2offload
bool yaml2offload(OffloadYAML::Binary &Doc, raw_ostream &Out, ErrorHandler EH)
Definition: OffloadEmitter.cpp:21
yaml2obj.h
llvm::raw_svector_ostream::str
StringRef str() const
Return a StringRef for the vector contents.
Definition: raw_ostream.h:684
OffloadBinary.h
llvm::object::OffloadBinary::Header
Definition: OffloadBinary.h:106
llvm::OffloadYAML::Binary::Members
std::vector< Member > Members
Definition: OffloadYAML.h:44
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:659
raw_ostream.h
llvm::OffloadYAML::Binary::EntrySize
Optional< uint64_t > EntrySize
Definition: OffloadYAML.h:43
llvm::MemoryBuffer::getMemBufferCopy
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.
Definition: MemoryBuffer.cpp:143
copy
we should consider alternate ways to model stack dependencies Lots of things could be done in WebAssemblyTargetTransformInfo cpp there are numerous optimization related hooks that can be overridden in WebAssemblyTargetLowering Instead of the OptimizeReturned which should consider preserving the returned attribute through to MachineInstrs and extending the MemIntrinsicResults pass to do this optimization on calls too That would also let the WebAssemblyPeephole pass clean up dead defs for such as it does for stores Consider implementing and or getMachineCombinerPatterns Find a clean way to fix the problem which leads to the Shrink Wrapping pass being run after the WebAssembly PEI pass When setting multiple variables to the same we currently get code like const It could be done with a smaller encoding like local tee $pop5 local copy
Definition: README.txt:101
llvm::OffloadYAML::Binary::EntryOffset
Optional< uint64_t > EntryOffset
Definition: OffloadYAML.h:42
llvm::OffloadYAML::Binary
Definition: OffloadYAML.h:26