LLVM 20.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.
25 MCStreamer &S, const MCSubtargetInfo &STI)
27 auto &MAB = static_cast<LoongArchAsmBackend &>(
31 MAB.getTargetOptions().getABIName()));
32}
33
35 return static_cast<MCELFStreamer &>(Streamer);
36}
37
42
43 // Figure out the e_flags.
44 //
45 // Bitness is already represented with the EI_CLASS byte in the current spec,
46 // so here we only record the base ABI modifier. Also set the object file ABI
47 // version to v1, as upstream LLVM cannot handle the previous stack-machine-
48 // based relocs from day one.
49 //
50 // Refer to LoongArch ELF psABI v2.01 for details.
51 unsigned EFlags = W.getELFHeaderEFlags();
53 switch (ABI) {
57 break;
61 break;
65 break;
67 llvm_unreachable("Improperly initialized target ABI");
68 }
69 W.setELFHeaderEFlags(EFlags);
70}
71
72namespace {
73class LoongArchELFStreamer : public MCELFStreamer {
74public:
75 LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
76 std::unique_ptr<MCObjectWriter> MOW,
77 std::unique_ptr<MCCodeEmitter> MCE)
78 : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
79};
80} // end namespace
81
82namespace llvm {
84 std::unique_ptr<MCAsmBackend> MAB,
85 std::unique_ptr<MCObjectWriter> MOW,
86 std::unique_ptr<MCCodeEmitter> MCE) {
87 LoongArchELFStreamer *S = new LoongArchELFStreamer(
88 C, std::move(MAB), std::move(MOW), std::move(MCE));
89 return S;
90}
91} // end namespace llvm
LoongArchTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
LoongArchABI::ABI getTargetABI() const
void setTargetABI(LoongArchABI::ABI ABI)
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:188
Context object for machine code objects.
Definition: MCContext.h:83
ELFObjectWriter & getWriter()
MCAssembler & getAssembler()
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
virtual void finish()
Definition: MCStreamer.cpp:55
MCStreamer & Streamer
Definition: MCStreamer.h:96
#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:1018
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition: ELF.h:1012
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition: ELF.h:1013
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition: ELF.h:1011
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1849
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:858