LLVM  16.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 
13 #include "LoongArchELFStreamer.h"
14 #include "LoongArchAsmBackend.h"
15 #include "llvm/BinaryFormat/ELF.h"
16 #include "llvm/MC/MCAssembler.h"
17 #include "llvm/MC/MCCodeEmitter.h"
18 #include "llvm/MC/MCObjectWriter.h"
19 
20 using namespace llvm;
21 
22 // This part is for ELF object output.
24  MCStreamer &S, const MCSubtargetInfo &STI)
26  // FIXME: select appropriate ABI.
29 }
30 
32  return static_cast<MCELFStreamer &>(Streamer);
33 }
34 
39 
40  // Figure out the e_flags.
41  //
42  // Bitness is already represented with the EI_CLASS byte in the current spec,
43  // so here we only record the base ABI modifier. Also set the object file ABI
44  // version to v1, as upstream LLVM cannot handle the previous stack-machine-
45  // based relocs from day one.
46  //
47  // Refer to LoongArch ELF psABI v2.01 for details.
48  unsigned EFlags = MCA.getELFHeaderEFlags();
50  switch (ABI) {
54  break;
58  break;
62  break;
64  llvm_unreachable("Improperly initialized target ABI");
65  }
66  MCA.setELFHeaderEFlags(EFlags);
67 }
68 
69 namespace {
70 class LoongArchELFStreamer : public MCELFStreamer {
71 public:
72  LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
73  std::unique_ptr<MCObjectWriter> MOW,
74  std::unique_ptr<MCCodeEmitter> MCE)
75  : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
76 };
77 } // end namespace
78 
79 namespace llvm {
81  std::unique_ptr<MCAsmBackend> MAB,
82  std::unique_ptr<MCObjectWriter> MOW,
83  std::unique_ptr<MCCodeEmitter> MCE,
84  bool RelaxAll) {
85  LoongArchELFStreamer *S = new LoongArchELFStreamer(
86  C, std::move(MAB), std::move(MOW), std::move(MCE));
87  S->getAssembler().setRelaxAll(RelaxAll);
88  return S;
89 }
90 } // end namespace llvm
llvm::ELF::EF_LOONGARCH_ABI_SINGLE_FLOAT
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition: ELF.h:918
llvm::MCAssembler::getELFHeaderEFlags
unsigned getELFHeaderEFlags() const
ELF e_header flags.
Definition: MCAssembler.h:276
ABI
Generic address nodes are lowered to some combination of target independent and machine specific ABI
Definition: Relocation.txt:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::LoongArchABI::ABI_LP64S
@ ABI_LP64S
Definition: LoongArchBaseInfo.h:51
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:77
MCCodeEmitter.h
llvm::ELF::EF_LOONGARCH_ABI_SOFT_FLOAT
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition: ELF.h:917
llvm::LoongArchTargetELFStreamer::finish
void finish() override
Definition: LoongArchELFStreamer.cpp:35
llvm::LoongArchABI::ABI_ILP32D
@ ABI_ILP32D
Definition: LoongArchBaseInfo.h:50
llvm::MCTargetStreamer::finish
virtual void finish()
Definition: MCStreamer.cpp:56
MCAssembler.h
llvm::LoongArchABI::ABI_LP64F
@ ABI_LP64F
Definition: LoongArchBaseInfo.h:52
llvm::LoongArchABI::ABI_ILP32F
@ ABI_ILP32F
Definition: LoongArchBaseInfo.h:49
llvm::ELF::EF_LOONGARCH_OBJABI_V1
@ EF_LOONGARCH_OBJABI_V1
Definition: ELF.h:924
llvm::Triple::isArch64Bit
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1462
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:213
ELF.h
llvm::MCELFStreamer
Definition: MCELFStreamer.h:31
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:109
LoongArchELFStreamer.h
llvm::LoongArchTargetStreamer::setTargetABI
void setTargetABI(LoongArchABI::ABI ABI)
Definition: LoongArchTargetStreamer.cpp:20
llvm::LoongArchTargetELFStreamer::getStreamer
MCELFStreamer & getStreamer()
Definition: LoongArchELFStreamer.cpp:31
LoongArchAsmBackend.h
llvm::LoongArchABI::ABI_Unknown
@ ABI_Unknown
Definition: LoongArchBaseInfo.h:54
llvm::MCAssembler
Definition: MCAssembler.h:73
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:96
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::MCAssembler::setELFHeaderEFlags
void setELFHeaderEFlags(unsigned Flags)
Definition: MCAssembler.h:277
llvm::LoongArchABI::ABI
ABI
Definition: LoongArchBaseInfo.h:47
llvm::move
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:1861
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:128
llvm::ELF::EF_LOONGARCH_ABI_DOUBLE_FLOAT
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition: ELF.h:919
llvm::createLoongArchELFStreamer
MCELFStreamer * createLoongArchELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE, bool RelaxAll)
Definition: LoongArchELFStreamer.cpp:80
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::LoongArchABI::ABI_ILP32S
@ ABI_ILP32S
Definition: LoongArchBaseInfo.h:48
MCObjectWriter.h
std
Definition: BitVector.h:851
llvm::LoongArchABI::ABI_LP64D
@ ABI_LP64D
Definition: LoongArchBaseInfo.h:53
llvm::LoongArchTargetELFStreamer::LoongArchTargetELFStreamer
LoongArchTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: LoongArchELFStreamer.cpp:23
llvm::LoongArchTargetStreamer
Definition: LoongArchTargetStreamer.h:17
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:77
llvm::LoongArchTargetStreamer::getTargetABI
LoongArchABI::ABI getTargetABI() const
Definition: LoongArchTargetStreamer.h:23