LLVM 17.0.0git
MCSPIRVStreamer.cpp
Go to the documentation of this file.
1//===- lib/MC/MCSPIRVStreamer.cpp - SPIR-V Object Output ------*- 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// This file assembles .s files and emits SPIR-V .o object files.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/MC/MCAssembler.h"
16
17using namespace llvm;
18
19void MCSPIRVStreamer::emitInstToData(const MCInst &Inst,
20 const MCSubtargetInfo &STI) {
21 MCAssembler &Assembler = getAssembler();
24 raw_svector_ostream VecOS(Code);
25 Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
26
27 // Append the encoded instruction to the current data fragment (or create a
28 // new such fragment if the current fragment is not a data fragment).
30
31 DF->setHasInstructions(STI);
32 DF->getContents().append(Code.begin(), Code.end());
33}
34
36 std::unique_ptr<MCAsmBackend> &&MAB,
37 std::unique_ptr<MCObjectWriter> &&OW,
38 std::unique_ptr<MCCodeEmitter> &&CE,
39 bool RelaxAll) {
40 MCSPIRVStreamer *S = new MCSPIRVStreamer(Context, std::move(MAB),
41 std::move(OW), std::move(CE));
42 if (RelaxAll)
43 S->getAssembler().setRelaxAll(true);
44 return S;
45}
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
LLVMContext & Context
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:331
void setRelaxAll(bool Value)
Definition: MCAssembler.h:358
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
Context object for machine code objects.
Definition: MCContext.h:76
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment.
MCAssembler & getAssembler()
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Generic base class for all target subtargets.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:672
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCStreamer * createSPIRVStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)