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
22const LoongArchMCExpr *LoongArchMCExpr::create(const MCExpr *Expr, uint16_t S,
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_MARK_LA:
36 case ELF::R_LARCH_ABS_HI20:
37 return "abs_hi20";
38 case ELF::R_LARCH_ABS_LO12:
39 return "abs_lo12";
40 case ELF::R_LARCH_ABS64_LO20:
41 return "abs64_lo20";
42 case ELF::R_LARCH_ABS64_HI12:
43 return "abs64_hi12";
44 case ELF::R_LARCH_PCALA_HI20:
45 return "pc_hi20";
46 case ELF::R_LARCH_PCALA_LO12:
47 return "pc_lo12";
48 case ELF::R_LARCH_PCALA64_LO20:
49 return "pc64_lo20";
50 case ELF::R_LARCH_PCALA64_HI12:
51 return "pc64_hi12";
52 case ELF::R_LARCH_GOT_PC_HI20:
53 return "got_pc_hi20";
54 case ELF::R_LARCH_GOT_PC_LO12:
55 return "got_pc_lo12";
56 case ELF::R_LARCH_GOT64_PC_LO20:
57 return "got64_pc_lo20";
58 case ELF::R_LARCH_GOT64_PC_HI12:
59 return "got64_pc_hi12";
60 case ELF::R_LARCH_GOT_HI20:
61 return "got_hi20";
62 case ELF::R_LARCH_GOT_LO12:
63 return "got_lo12";
64 case ELF::R_LARCH_GOT64_LO20:
65 return "got64_lo20";
66 case ELF::R_LARCH_GOT64_HI12:
67 return "got64_hi12";
68 case ELF::R_LARCH_TLS_LE_HI20:
69 return "le_hi20";
70 case ELF::R_LARCH_TLS_LE_LO12:
71 return "le_lo12";
72 case ELF::R_LARCH_TLS_LE64_LO20:
73 return "le64_lo20";
74 case ELF::R_LARCH_TLS_LE64_HI12:
75 return "le64_hi12";
76 case ELF::R_LARCH_TLS_IE_PC_HI20:
77 return "ie_pc_hi20";
78 case ELF::R_LARCH_TLS_IE_PC_LO12:
79 return "ie_pc_lo12";
80 case ELF::R_LARCH_TLS_IE64_PC_LO20:
81 return "ie64_pc_lo20";
82 case ELF::R_LARCH_TLS_IE64_PC_HI12:
83 return "ie64_pc_hi12";
84 case ELF::R_LARCH_TLS_IE_HI20:
85 return "ie_hi20";
86 case ELF::R_LARCH_TLS_IE_LO12:
87 return "ie_lo12";
88 case ELF::R_LARCH_TLS_IE64_LO20:
89 return "ie64_lo20";
90 case ELF::R_LARCH_TLS_IE64_HI12:
91 return "ie64_hi12";
92 case ELF::R_LARCH_TLS_LD_PC_HI20:
93 return "ld_pc_hi20";
94 case ELF::R_LARCH_TLS_LD_HI20:
95 return "ld_hi20";
96 case ELF::R_LARCH_TLS_GD_PC_HI20:
97 return "gd_pc_hi20";
98 case ELF::R_LARCH_TLS_GD_HI20:
99 return "gd_hi20";
100 case ELF::R_LARCH_CALL36:
101 return "call36";
102 case ELF::R_LARCH_TLS_DESC_PC_HI20:
103 return "desc_pc_hi20";
104 case ELF::R_LARCH_TLS_DESC_PC_LO12:
105 return "desc_pc_lo12";
106 case ELF::R_LARCH_TLS_DESC64_PC_LO20:
107 return "desc64_pc_lo20";
108 case ELF::R_LARCH_TLS_DESC64_PC_HI12:
109 return "desc64_pc_hi12";
110 case ELF::R_LARCH_TLS_DESC_HI20:
111 return "desc_hi20";
112 case ELF::R_LARCH_TLS_DESC_LO12:
113 return "desc_lo12";
114 case ELF::R_LARCH_TLS_DESC64_LO20:
115 return "desc64_lo20";
116 case ELF::R_LARCH_TLS_DESC64_HI12:
117 return "desc64_hi12";
118 case ELF::R_LARCH_TLS_DESC_LD:
119 return "desc_ld";
120 case ELF::R_LARCH_TLS_DESC_CALL:
121 return "desc_call";
122 case ELF::R_LARCH_TLS_LE_HI20_R:
123 return "le_hi20_r";
124 case ELF::R_LARCH_TLS_LE_ADD_R:
125 return "le_add_r";
126 case ELF::R_LARCH_TLS_LE_LO12_R:
127 return "le_lo12_r";
128 case ELF::R_LARCH_PCREL20_S2:
129 return "pcrel_20";
130 case ELF::R_LARCH_TLS_LD_PCREL20_S2:
131 return "ld_pcrel_20";
132 case ELF::R_LARCH_TLS_GD_PCREL20_S2:
133 return "gd_pcrel_20";
134 case ELF::R_LARCH_TLS_DESC_PCREL20_S2:
135 return "desc_pcrel_20";
136 }
137}
138
141 .Case("plt", ELF::R_LARCH_B26)
142 .Case("b16", ELF::R_LARCH_B16)
143 .Case("b21", ELF::R_LARCH_B21)
144 .Case("b26", ELF::R_LARCH_B26)
145 .Case("abs_hi20", ELF::R_LARCH_ABS_HI20)
146 .Case("abs_lo12", ELF::R_LARCH_ABS_LO12)
147 .Case("abs64_lo20", ELF::R_LARCH_ABS64_LO20)
148 .Case("abs64_hi12", ELF::R_LARCH_ABS64_HI12)
149 .Case("pc_hi20", ELF::R_LARCH_PCALA_HI20)
150 .Case("pc_lo12", ELF::R_LARCH_PCALA_LO12)
151 .Case("pc64_lo20", ELF::R_LARCH_PCALA64_LO20)
152 .Case("pc64_hi12", ELF::R_LARCH_PCALA64_HI12)
153 .Case("got_pc_hi20", ELF::R_LARCH_GOT_PC_HI20)
154 .Case("got_pc_lo12", ELF::R_LARCH_GOT_PC_LO12)
155 .Case("got64_pc_lo20", ELF::R_LARCH_GOT64_PC_LO20)
156 .Case("got64_pc_hi12", ELF::R_LARCH_GOT64_PC_HI12)
157 .Case("got_hi20", ELF::R_LARCH_GOT_HI20)
158 .Case("got_lo12", ELF::R_LARCH_GOT_LO12)
159 .Case("got64_lo20", ELF::R_LARCH_GOT64_LO20)
160 .Case("got64_hi12", ELF::R_LARCH_GOT64_HI12)
161 .Case("le_hi20", ELF::R_LARCH_TLS_LE_HI20)
162 .Case("le_lo12", ELF::R_LARCH_TLS_LE_LO12)
163 .Case("le64_lo20", ELF::R_LARCH_TLS_LE64_LO20)
164 .Case("le64_hi12", ELF::R_LARCH_TLS_LE64_HI12)
165 .Case("ie_pc_hi20", ELF::R_LARCH_TLS_IE_PC_HI20)
166 .Case("ie_pc_lo12", ELF::R_LARCH_TLS_IE_PC_LO12)
167 .Case("ie64_pc_lo20", ELF::R_LARCH_TLS_IE64_PC_LO20)
168 .Case("ie64_pc_hi12", ELF::R_LARCH_TLS_IE64_PC_HI12)
169 .Case("ie_hi20", ELF::R_LARCH_TLS_IE_HI20)
170 .Case("ie_lo12", ELF::R_LARCH_TLS_IE_LO12)
171 .Case("ie64_lo20", ELF::R_LARCH_TLS_IE64_LO20)
172 .Case("ie64_hi12", ELF::R_LARCH_TLS_IE64_HI12)
173 .Case("ld_pc_hi20", ELF::R_LARCH_TLS_LD_PC_HI20)
174 .Case("ld_hi20", ELF::R_LARCH_TLS_LD_HI20)
175 .Case("gd_pc_hi20", ELF::R_LARCH_TLS_GD_PC_HI20)
176 .Case("gd_hi20", ELF::R_LARCH_TLS_GD_HI20)
177 .Case("call36", ELF::R_LARCH_CALL36)
178 .Case("desc_pc_hi20", ELF::R_LARCH_TLS_DESC_PC_HI20)
179 .Case("desc_pc_lo12", ELF::R_LARCH_TLS_DESC_PC_LO12)
180 .Case("desc64_pc_lo20", ELF::R_LARCH_TLS_DESC64_PC_LO20)
181 .Case("desc64_pc_hi12", ELF::R_LARCH_TLS_DESC64_PC_HI12)
182 .Case("desc_hi20", ELF::R_LARCH_TLS_DESC_HI20)
183 .Case("desc_lo12", ELF::R_LARCH_TLS_DESC_LO12)
184 .Case("desc64_lo20", ELF::R_LARCH_TLS_DESC64_LO20)
185 .Case("desc64_hi12", ELF::R_LARCH_TLS_DESC64_HI12)
186 .Case("desc_ld", ELF::R_LARCH_TLS_DESC_LD)
187 .Case("desc_call", ELF::R_LARCH_TLS_DESC_CALL)
188 .Case("le_hi20_r", ELF::R_LARCH_TLS_LE_HI20_R)
189 .Case("le_add_r", ELF::R_LARCH_TLS_LE_ADD_R)
190 .Case("le_lo12_r", ELF::R_LARCH_TLS_LE_LO12_R)
191 .Case("pcrel_20", ELF::R_LARCH_PCREL20_S2)
192 .Case("ld_pcrel_20", ELF::R_LARCH_TLS_LD_PCREL20_S2)
193 .Case("gd_pcrel_20", ELF::R_LARCH_TLS_GD_PCREL20_S2)
194 .Case("desc_pcrel_20", ELF::R_LARCH_TLS_DESC_PCREL20_S2)
195 .Default(0);
196}
197
198void LoongArchMCAsmInfo::anchor() {}
199
201 CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;
202 AlignmentIsInBytes = false;
203 Data8bitsDirective = "\t.byte\t";
204 Data16bitsDirective = "\t.half\t";
205 Data32bitsDirective = "\t.word\t";
206 Data64bitsDirective = "\t.dword\t";
207 ZeroDirective = "\t.space\t";
208 CommentString = "#";
211 DwarfRegNumForCFI = true;
213}
214
216 const MCSpecifierExpr &Expr) const {
217 auto S = Expr.getSpecifier();
218 bool HasSpecifier = S != 0 && S != ELF::R_LARCH_B26;
219 if (HasSpecifier)
220 OS << '%' << getLoongArchSpecifierName(S) << '(';
221 printExpr(OS, *Expr.getSubExpr());
222 if (HasSpecifier)
223 OS << ')';
224}
This file contains constants used for implementing Dwarf debug support.
static StringRef getLoongArchSpecifierName(uint16_t S)
static const char * name
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
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.
StringSwitch & Case(StringLiteral S, T Value)
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.
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55