LLVM 23.0.0git
LoongArchELFStreamer.cpp
Go to the documentation of this file.
1//===-- LoongArchELFStreamer.cpp - LoongArch ELF Target Streamer Methods --===//
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 provides LoongArch specific target streamer methods.
10//
11//===----------------------------------------------------------------------===//
12
14#include "LoongArchAsmBackend.h"
15#include "LoongArchBaseInfo.h"
17#include "llvm/MC/MCAssembler.h"
20
21using namespace llvm;
22
23// This part is for ELF object output.
33
37
42
44 auto &S = getStreamer();
45 S.ensureHeadroom(4);
47 S.appendContents(4, 0);
48}
49
51 auto &S = getStreamer();
52 S.ensureHeadroom(8);
54 S.appendContents(8, 0);
55}
56
61
62 // Figure out the e_flags.
63 //
64 // Bitness is already represented with the EI_CLASS byte in the current spec,
65 // so here we only record the base ABI modifier. Also set the object file ABI
66 // version to v1, as upstream LLVM cannot handle the previous stack-machine-
67 // based relocs from day one.
68 //
69 // Refer to LoongArch ELF psABI v2.01 for details.
70 unsigned EFlags = W.getELFHeaderEFlags();
72 switch (ABI) {
76 break;
80 break;
84 break;
86 llvm_unreachable("Improperly initialized target ABI");
87 }
88 W.setELFHeaderEFlags(EFlags);
89}
90
91namespace {
92class LoongArchELFStreamer : public MCELFStreamer {
93public:
94 LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
95 std::unique_ptr<MCObjectWriter> MOW,
96 std::unique_ptr<MCCodeEmitter> MCE)
97 : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
98};
99} // end namespace
100
101namespace llvm {
103 std::unique_ptr<MCAsmBackend> MAB,
104 std::unique_ptr<MCObjectWriter> MOW,
105 std::unique_ptr<MCCodeEmitter> MCE) {
106 LoongArchELFStreamer *S = new LoongArchELFStreamer(
107 C, std::move(MAB), std::move(MOW), std::move(MCE));
108 return S;
109}
110} // end namespace llvm
void emitDTPRel32Value(const MCExpr *) override
void emitDTPRel64Value(const MCExpr *) override
LoongArchTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
LoongArchABI::ABI getTargetABI() const
void setTargetABI(LoongArchABI::ABI ABI)
MCAsmBackend & getBackend() const
Context object for machine code objects.
Definition MCContext.h:83
ELFObjectWriter & getWriter()
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCAssembler & getAssembler()
Streaming machine code generation interface.
Definition MCStreamer.h:222
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
virtual void finish()
MCStreamer & Streamer
Definition MCStreamer.h:97
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ EF_LOONGARCH_OBJABI_V1
Definition ELF.h:1077
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition ELF.h:1071
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition ELF.h:1072
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition ELF.h:1070
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
This is an optimization pass for GlobalISel generic memory operations.
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:1916
MCELFStreamer * createLoongArchELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874