]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Target / RISCV / MCTargetDesc / RISCVMCAsmInfo.cpp
1 //===-- RISCVMCAsmInfo.cpp - RISCV Asm properties -------------------------===//
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 contains the declarations of the RISCVMCAsmInfo properties.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "RISCVMCAsmInfo.h"
14 #include "MCTargetDesc/RISCVMCExpr.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/BinaryFormat/Dwarf.h"
17 #include "llvm/MC/MCStreamer.h"
18 using namespace llvm;
19
20 void RISCVMCAsmInfo::anchor() {}
21
22 RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) {
23   CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;
24   CommentString = "#";
25   AlignmentIsInBytes = false;
26   SupportsDebugInformation = true;
27   ExceptionsType = ExceptionHandling::DwarfCFI;
28   Data16bitsDirective = "\t.half\t";
29   Data32bitsDirective = "\t.word\t";
30 }
31
32 const MCExpr *RISCVMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
33                                                   unsigned Encoding,
34                                                   MCStreamer &Streamer) const {
35   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
36     return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);
37
38   // The default symbol subtraction results in an ADD/SUB relocation pair.
39   // Processing this relocation pair is problematic when linker relaxation is
40   // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation
41   // for the FDE initial location.
42   MCContext &Ctx = Streamer.getContext();
43   const MCExpr *ME =
44       MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx);
45   assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding");
46   return RISCVMCExpr::create(ME, RISCVMCExpr::VK_RISCV_32_PCREL, Ctx);
47 }