xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric //===-- RISCVMCAsmInfo.cpp - RISC-V Asm properties ------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the declarations of the RISCVMCAsmInfo properties.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "RISCVMCAsmInfo.h"
140b57cec5SDimitry Andric #include "MCTargetDesc/RISCVMCExpr.h"
150b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
160b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h"
17*06c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h"
180b57cec5SDimitry Andric using namespace llvm;
190b57cec5SDimitry Andric 
anchor()200b57cec5SDimitry Andric void RISCVMCAsmInfo::anchor() {}
210b57cec5SDimitry Andric 
RISCVMCAsmInfo(const Triple & TT)220b57cec5SDimitry Andric RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) {
230b57cec5SDimitry Andric   CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;
240b57cec5SDimitry Andric   CommentString = "#";
250b57cec5SDimitry Andric   AlignmentIsInBytes = false;
260b57cec5SDimitry Andric   SupportsDebugInformation = true;
270b57cec5SDimitry Andric   ExceptionsType = ExceptionHandling::DwarfCFI;
280b57cec5SDimitry Andric   Data16bitsDirective = "\t.half\t";
290b57cec5SDimitry Andric   Data32bitsDirective = "\t.word\t";
300b57cec5SDimitry Andric }
310b57cec5SDimitry Andric 
getExprForFDESymbol(const MCSymbol * Sym,unsigned Encoding,MCStreamer & Streamer) const320b57cec5SDimitry Andric const MCExpr *RISCVMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
330b57cec5SDimitry Andric                                                   unsigned Encoding,
340b57cec5SDimitry Andric                                                   MCStreamer &Streamer) const {
350b57cec5SDimitry Andric   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
360b57cec5SDimitry Andric     return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   // The default symbol subtraction results in an ADD/SUB relocation pair.
390b57cec5SDimitry Andric   // Processing this relocation pair is problematic when linker relaxation is
400b57cec5SDimitry Andric   // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation
410b57cec5SDimitry Andric   // for the FDE initial location.
420b57cec5SDimitry Andric   MCContext &Ctx = Streamer.getContext();
430b57cec5SDimitry Andric   const MCExpr *ME =
440b57cec5SDimitry Andric       MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx);
450b57cec5SDimitry Andric   assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding");
460b57cec5SDimitry Andric   return RISCVMCExpr::create(ME, RISCVMCExpr::VK_RISCV_32_PCREL, Ctx);
470b57cec5SDimitry Andric }
48