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" 17 #include "llvm/MC/MCELFObjectWriter.h" 18 #include "llvm/Support/Endian.h" 19 #include "llvm/Support/EndianStream.h" 20 21 #define DEBUG_TYPE "loongarch-asmbackend" 22 23 using namespace llvm; 24 25 void LoongArchAsmBackend::applyFixup(const MCAssembler &Asm, 26 const MCFixup &Fixup, 27 const MCValue &Target, 28 MutableArrayRef<char> Data, uint64_t Value, 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 35 bool LoongArchAsmBackend::shouldForceRelocation(const MCAssembler &Asm, 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 43 bool LoongArchAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count, 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> 57 LoongArchAsmBackend::createObjectTargetWriter() const { 58 return createLoongArchELFObjectWriter(OSABI, Is64Bit); 59 } 60 61 MCAsmBackend *llvm::createLoongArchAsmBackend(const Target &T, 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 } 69