LLVM  16.0.0git
LoongArchAsmBackend.cpp
Go to the documentation of this file.
1 //===-- LoongArchAsmBackend.cpp - LoongArch Assembler Backend -*- 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 implements the LoongArchAsmBackend class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LoongArchAsmBackend.h"
14 #include "llvm/MC/MCAsmLayout.h"
15 #include "llvm/MC/MCAssembler.h"
16 #include "llvm/MC/MCContext.h"
18 #include "llvm/Support/Endian.h"
20 
21 #define DEBUG_TYPE "loongarch-asmbackend"
22 
23 using namespace llvm;
24 
26  const MCFixup &Fixup,
27  const MCValue &Target,
29  bool IsResolved,
30  const MCSubtargetInfo *STI) const {
31  // TODO: Apply the Value for given Fixup into the provided data fragment.
32  return;
33 }
34 
36  const MCFixup &Fixup,
37  const MCValue &Target) {
38  // TODO: Determine which relocation require special processing at linking
39  // time.
40  return false;
41 }
42 
44  const MCSubtargetInfo *STI) const {
45  // Check for byte count not multiple of instruction word size
46  if (Count % 4 != 0)
47  return false;
48 
49  // The nop on LoongArch is andi r0, r0, 0.
50  for (; Count >= 4; Count -= 4)
51  support::endian::write<uint32_t>(OS, 0x03400000, support::little);
52 
53  return true;
54 }
55 
56 std::unique_ptr<MCObjectTargetWriter>
58  return createLoongArchELFObjectWriter(OSABI, Is64Bit);
59 }
60 
62  const MCSubtargetInfo &STI,
63  const MCRegisterInfo &MRI,
64  const MCTargetOptions &Options) {
65  const Triple &TT = STI.getTargetTriple();
66  uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
67  return new LoongArchAsmBackend(STI, OSABI, TT.isArch64Bit());
68 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
llvm::LoongArchAsmBackend::createObjectTargetWriter
std::unique_ptr< MCObjectTargetWriter > createObjectTargetWriter() const override
Definition: LoongArchAsmBackend.cpp:57
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
MCAssembler.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MCAsmBackend
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
llvm::MutableArrayRef< char >
llvm::support::little
@ little
Definition: Endian.h:27
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:108
MCContext.h
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::LoongArchAsmBackend::shouldForceRelocation
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target) override
Hook to check if a relocation is needed for some target specific reason.
Definition: LoongArchAsmBackend.cpp:35
llvm::createLoongArchAsmBackend
MCAsmBackend * createLoongArchAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: LoongArchAsmBackend.cpp:61
LoongArchAsmBackend.h
llvm::MCAssembler
Definition: MCAssembler.h:73
uint64_t
MCELFObjectWriter.h
llvm::MCTargetOptions
Definition: MCTargetOptions.h:41
llvm::MCELFObjectTargetWriter::getOSABI
uint8_t getOSABI() const
Definition: MCELFObjectWriter.h:101
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
MCAsmLayout.h
llvm::createLoongArchELFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createLoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit)
Definition: LoongArchELFObjectWriter.cpp:62
EndianStream.h
llvm::LoongArchAsmBackend::writeNopData
bool writeNopData(raw_ostream &OS, uint64_t Count, const MCSubtargetInfo *STI) const override
Write an (optimal) nop sequence of Count bytes to the given output.
Definition: LoongArchAsmBackend.cpp:43
llvm::LoongArchAsmBackend::applyFixup
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const override
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
Definition: LoongArchAsmBackend.cpp:25
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:36
Endian.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::LoongArchAsmBackend
Definition: LoongArchAsmBackend.h:24