LLVM 22.0.0git
LoongArchMCAsmInfo.cpp
Go to the documentation of this file.
1//===-- LoongArchMCAsmInfo.cpp - LoongArch Asm properties ------*- 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 contains the declarations of the LoongArchMCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "LoongArchMCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCStreamer.h"
19
20using namespace llvm;
21
23 MCContext &Ctx, bool Hint) {
24 return new (Ctx) LoongArchMCExpr(Expr, S, Hint);
25}
26
28 switch (S) {
29 default:
30 llvm_unreachable("Invalid ELF symbol kind");
31 case ELF::R_LARCH_B16:
32 return "b16";
33 case ELF::R_LARCH_B21:
34 return "b21";
35 case ELF::R_LARCH_ABS_HI20:
36 return "abs_hi20";
37 case ELF::R_LARCH_ABS_LO12:
38 return "abs_lo12";
39 case ELF::R_LARCH_ABS64_LO20:
40 return "abs64_lo20";
41 case ELF::R_LARCH_ABS64_HI12:
42 return "abs64_hi12";
43 case ELF::R_LARCH_PCALA_HI20:
44 return "pc_hi20";
45 case ELF::R_LARCH_PCALA_LO12:
46 return "pc_lo12";
47 case ELF::R_LARCH_PCALA64_LO20:
48 return "pc64_lo20";
49 case ELF::R_LARCH_PCALA64_HI12:
50 return "pc64_hi12";
51 case ELF::R_LARCH_GOT_PC_HI20:
52 return "got_pc_hi20";
53 case ELF::R_LARCH_GOT_PC_LO12:
54 return "got_pc_lo12";
55 case ELF::R_LARCH_GOT64_PC_LO20:
56 return "got64_pc_lo20";
57 case ELF::R_LARCH_GOT64_PC_HI12:
58 return "got64_pc_hi12";
59 case ELF::R_LARCH_GOT_HI20:
60 return "got_hi20";
61 case ELF::R_LARCH_GOT_LO12:
62 return "got_lo12";
63 case ELF::R_LARCH_GOT64_LO20:
64 return "got64_lo20";
65 case ELF::R_LARCH_GOT64_HI12:
66 return "got64_hi12";
67 case ELF::R_LARCH_TLS_LE_HI20:
68 return "le_hi20";
69 case ELF::R_LARCH_TLS_LE_LO12:
70 return "le_lo12";
71 case ELF::R_LARCH_TLS_LE64_LO20:
72 return "le64_lo20";
73 case ELF::R_LARCH_TLS_LE64_HI12:
74 return "le64_hi12";
75 case ELF::R_LARCH_TLS_IE_PC_HI20:
76 return "ie_pc_hi20";
77 case ELF::R_LARCH_TLS_IE_PC_LO12:
78 return "ie_pc_lo12";
79 case ELF::R_LARCH_TLS_IE64_PC_LO20:
80 return "ie64_pc_lo20";
81 case ELF::R_LARCH_TLS_IE64_PC_HI12:
82 return "ie64_pc_hi12";
83 case ELF::R_LARCH_TLS_IE_HI20:
84 return "ie_hi20";
85 case ELF::R_LARCH_TLS_IE_LO12:
86 return "ie_lo12";
87 case ELF::R_LARCH_TLS_IE64_LO20:
88 return "ie64_lo20";
89 case ELF::R_LARCH_TLS_IE64_HI12:
90 return "ie64_hi12";
91 case ELF::R_LARCH_TLS_LD_PC_HI20:
92 return "ld_pc_hi20";
93 case ELF::R_LARCH_TLS_LD_HI20:
94 return "ld_hi20";
95 case ELF::R_LARCH_TLS_GD_PC_HI20:
96 return "gd_pc_hi20";
97 case ELF::R_LARCH_TLS_GD_HI20:
98 return "gd_hi20";
99 case ELF::R_LARCH_CALL36:
100 return "call36";
101 case ELF::R_LARCH_TLS_DESC_PC_HI20:
102 return "desc_pc_hi20";
103 case ELF::R_LARCH_TLS_DESC_PC_LO12:
104 return "desc_pc_lo12";
105 case ELF::R_LARCH_TLS_DESC64_PC_LO20:
106 return "desc64_pc_lo20";
107 case ELF::R_LARCH_TLS_DESC64_PC_HI12:
108 return "desc64_pc_hi12";
109 case ELF::R_LARCH_TLS_DESC_HI20:
110 return "desc_hi20";
111 case ELF::R_LARCH_TLS_DESC_LO12:
112 return "desc_lo12";
113 case ELF::R_LARCH_TLS_DESC64_LO20:
114 return "desc64_lo20";
115 case ELF::R_LARCH_TLS_DESC64_HI12:
116 return "desc64_hi12";
117 case ELF::R_LARCH_TLS_DESC_LD:
118 return "desc_ld";
119 case ELF::R_LARCH_TLS_DESC_CALL:
120 return "desc_call";
121 case ELF::R_LARCH_TLS_LE_HI20_R:
122 return "le_hi20_r";
123 case ELF::R_LARCH_TLS_LE_ADD_R:
124 return "le_add_r";
125 case ELF::R_LARCH_TLS_LE_LO12_R:
126 return "le_lo12_r";
127 case ELF::R_LARCH_PCREL20_S2:
128 return "pcrel_20";
129 case ELF::R_LARCH_TLS_LD_PCREL20_S2:
130 return "ld_pcrel_20";
131 case ELF::R_LARCH_TLS_GD_PCREL20_S2:
132 return "gd_pcrel_20";
133 case ELF::R_LARCH_TLS_DESC_PCREL20_S2:
134 return "desc_pcrel_20";
135 }
136}
137
140 .Case("plt", ELF::R_LARCH_B26)
141 .Case("b16", ELF::R_LARCH_B16)
142 .Case("b21", ELF::R_LARCH_B21)
143 .Case("b26", ELF::R_LARCH_B26)
144 .Case("abs_hi20", ELF::R_LARCH_ABS_HI20)
145 .Case("abs_lo12", ELF::R_LARCH_ABS_LO12)
146 .Case("abs64_lo20", ELF::R_LARCH_ABS64_LO20)
147 .Case("abs64_hi12", ELF::R_LARCH_ABS64_HI12)
148 .Case("pc_hi20", ELF::R_LARCH_PCALA_HI20)
149 .Case("pc_lo12", ELF::R_LARCH_PCALA_LO12)
150 .Case("pc64_lo20", ELF::R_LARCH_PCALA64_LO20)
151 .Case("pc64_hi12", ELF::R_LARCH_PCALA64_HI12)
152 .Case("got_pc_hi20", ELF::R_LARCH_GOT_PC_HI20)
153 .Case("got_pc_lo12", ELF::R_LARCH_GOT_PC_LO12)
154 .Case("got64_pc_lo20", ELF::R_LARCH_GOT64_PC_LO20)
155 .Case("got64_pc_hi12", ELF::R_LARCH_GOT64_PC_HI12)
156 .Case("got_hi20", ELF::R_LARCH_GOT_HI20)
157 .Case("got_lo12", ELF::R_LARCH_GOT_LO12)
158 .Case("got64_lo20", ELF::R_LARCH_GOT64_LO20)
159 .Case("got64_hi12", ELF::R_LARCH_GOT64_HI12)
160 .Case("le_hi20", ELF::R_LARCH_TLS_LE_HI20)
161 .Case("le_lo12", ELF::R_LARCH_TLS_LE_LO12)
162 .Case("le64_lo20", ELF::R_LARCH_TLS_LE64_LO20)
163 .Case("le64_hi12", ELF::R_LARCH_TLS_LE64_HI12)
164 .Case("ie_pc_hi20", ELF::R_LARCH_TLS_IE_PC_HI20)
165 .Case("ie_pc_lo12", ELF::R_LARCH_TLS_IE_PC_LO12)
166 .Case("ie64_pc_lo20", ELF::R_LARCH_TLS_IE64_PC_LO20)
167 .Case("ie64_pc_hi12", ELF::R_LARCH_TLS_IE64_PC_HI12)
168 .Case("ie_hi20", ELF::R_LARCH_TLS_IE_HI20)
169 .Case("ie_lo12", ELF::R_LARCH_TLS_IE_LO12)
170 .Case("ie64_lo20", ELF::R_LARCH_TLS_IE64_LO20)
171 .Case("ie64_hi12", ELF::R_LARCH_TLS_IE64_HI12)
172 .Case("ld_pc_hi20", ELF::R_LARCH_TLS_LD_PC_HI20)
173 .Case("ld_hi20", ELF::R_LARCH_TLS_LD_HI20)
174 .Case("gd_pc_hi20", ELF::R_LARCH_TLS_GD_PC_HI20)
175 .Case("gd_hi20", ELF::R_LARCH_TLS_GD_HI20)
176 .Case("call36", ELF::R_LARCH_CALL36)
177 .Case("desc_pc_hi20", ELF::R_LARCH_TLS_DESC_PC_HI20)
178 .Case("desc_pc_lo12", ELF::R_LARCH_TLS_DESC_PC_LO12)
179 .Case("desc64_pc_lo20", ELF::R_LARCH_TLS_DESC64_PC_LO20)
180 .Case("desc64_pc_hi12", ELF::R_LARCH_TLS_DESC64_PC_HI12)
181 .Case("desc_hi20", ELF::R_LARCH_TLS_DESC_HI20)
182 .Case("desc_lo12", ELF::R_LARCH_TLS_DESC_LO12)
183 .Case("desc64_lo20", ELF::R_LARCH_TLS_DESC64_LO20)
184 .Case("desc64_hi12", ELF::R_LARCH_TLS_DESC64_HI12)
185 .Case("desc_ld", ELF::R_LARCH_TLS_DESC_LD)
186 .Case("desc_call", ELF::R_LARCH_TLS_DESC_CALL)
187 .Case("le_hi20_r", ELF::R_LARCH_TLS_LE_HI20_R)
188 .Case("le_add_r", ELF::R_LARCH_TLS_LE_ADD_R)
189 .Case("le_lo12_r", ELF::R_LARCH_TLS_LE_LO12_R)
190 .Case("pcrel_20", ELF::R_LARCH_PCREL20_S2)
191 .Case("ld_pcrel_20", ELF::R_LARCH_TLS_LD_PCREL20_S2)
192 .Case("gd_pcrel_20", ELF::R_LARCH_TLS_GD_PCREL20_S2)
193 .Case("desc_pcrel_20", ELF::R_LARCH_TLS_DESC_PCREL20_S2)
194 .Default(0);
195}
196
197void LoongArchMCAsmInfo::anchor() {}
198
200 CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;
201 AlignmentIsInBytes = false;
202 Data8bitsDirective = "\t.byte\t";
203 Data16bitsDirective = "\t.half\t";
204 Data32bitsDirective = "\t.word\t";
205 Data64bitsDirective = "\t.dword\t";
206 ZeroDirective = "\t.space\t";
207 CommentString = "#";
210 DwarfRegNumForCFI = true;
212}
213
215 const MCSpecifierExpr &Expr) const {
216 auto S = Expr.getSpecifier();
217 bool HasSpecifier = S != 0 && S != ELF::R_LARCH_B26;
218 if (HasSpecifier)
219 OS << '%' << getLoongArchSpecifierName(S) << '(';
220 printExpr(OS, *Expr.getSubExpr());
221 if (HasSpecifier)
222 OS << ')';
223}
This file contains constants used for implementing Dwarf debug support.
static StringRef getLoongArchSpecifierName(uint16_t S)
static const char * name
Definition: SMEABIPass.cpp:52
raw_pwrite_stream & OS
LoongArchMCAsmInfo(const Triple &TargetTriple)
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
static const LoongArchMCExpr * create(const MCExpr *Expr, uint16_t S, MCContext &Ctx, bool Hint=false)
const char * Data16bitsDirective
Definition: MCAsmInfo.h:248
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:247
const char * Data64bitsDirective
Definition: MCAsmInfo.h:250
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition: MCAsmInfo.h:359
bool AllowDollarAtStartOfIdentifier
This is true if the assembler allows the "$" character at the start of of a string to be lexed as an ...
Definition: MCAsmInfo.h:196
const char * Data32bitsDirective
Definition: MCAsmInfo.h:249
void printExpr(raw_ostream &, const MCExpr &) const
Definition: MCAsmInfo.cpp:153
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition: MCAsmInfo.h:356
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition: MCAsmInfo.h:273
const char * ZeroDirective
This should be set to the directive used to get some number of zero (and non-zero if supported by the...
Definition: MCAsmInfo.h:226
bool DwarfRegNumForCFI
True if dwarf register numbers are printed instead of symbolic register names in ....
Definition: MCAsmInfo.h:382
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition: MCAsmInfo.h:87
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition: MCAsmInfo.h:91
StringRef CommentString
This indicates the comment string used by the assembler.
Definition: MCAsmInfo.h:135
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition: MCExpr.h:495
const MCExpr * getSubExpr() const
Definition: MCExpr.h:509
const MCExpr * Expr
Definition: MCExpr.h:497
Spec getSpecifier() const
Definition: MCExpr.h:508
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:68
R Default(T Value)
Definition: StringSwitch.h:177
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint16_t parseSpecifier(StringRef name)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ DwarfCFI
DWARF-like instruction based exceptions.