LLVM 22.0.0git
MCSPIRVObjectWriter.h
Go to the documentation of this file.
1//===-- llvm/MC/MCSPIRVObjectWriter.h - SPIR-V Object Writer -----*- C++ *-===//
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
9#ifndef LLVM_MC_MCSPIRVOBJECTWRITER_H
10#define LLVM_MC_MCSPIRVOBJECTWRITER_H
11
13#include "llvm/MC/MCValue.h"
16#include <memory>
17
18namespace llvm {
19
21public:
23 static bool classof(const MCObjectTargetWriter *W) {
24 return W->getFormat() == Triple::SPIRV;
25 }
26};
27
28class SPIRVObjectWriter final : public MCObjectWriter {
30 std::unique_ptr<MCSPIRVObjectTargetWriter> TargetObjectWriter;
31
32 struct VersionInfoType {
33 unsigned Major = 0;
34 unsigned Minor = 0;
35 unsigned Bound = 0;
36 } VersionInfo;
37
38public:
39 SPIRVObjectWriter(std::unique_ptr<MCSPIRVObjectTargetWriter> MOTW,
41 : W(OS, llvm::endianness::little), TargetObjectWriter(std::move(MOTW)) {}
42
43 void setBuildVersion(unsigned Major, unsigned Minor, unsigned Bound);
44
45private:
46 uint64_t writeObject() override;
47 void writeHeader(const MCAssembler &Asm);
48};
49
50/// Construct a new SPIR-V writer instance.
51///
52/// \param MOTW - The target specific SPIR-V writer subclass.
53/// \param OS - The stream to write to.
54/// \returns The constructed object writer.
55std::unique_ptr<MCObjectWriter>
56createSPIRVObjectWriter(std::unique_ptr<MCSPIRVObjectTargetWriter> MOTW,
57 raw_pwrite_stream &OS);
58
59} // namespace llvm
60
61#endif
raw_pwrite_stream & OS
Base class for classes that define behaviour that is specific to both the target and the object forma...
Defines the object file and target independent interfaces used by the assembler backend to write nati...
static bool classof(const MCObjectTargetWriter *W)
Triple::ObjectFormatType getFormat() const override
SPIRVObjectWriter(std::unique_ptr< MCSPIRVObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
void setBuildVersion(unsigned Major, unsigned Minor, unsigned Bound)
ObjectFormatType
Definition: Triple.h:314
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:435
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::unique_ptr< MCObjectWriter > createSPIRVObjectWriter(std::unique_ptr< MCSPIRVObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
Construct a new SPIR-V writer instance.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
endianness
Definition: bit.h:71
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:67