LLVM 22.0.0git
MipsMCAsmInfo.cpp
Go to the documentation of this file.
1//===-- MipsMCAsmInfo.cpp - Mips 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 MipsMCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MipsMCAsmInfo.h"
14#include "MipsABIInfo.h"
15#include "llvm/MC/MCValue.h"
18
19using namespace llvm;
20
21void MipsELFMCAsmInfo::anchor() {}
22
24 const MCTargetOptions &Options) {
25 IsLittleEndian = TheTriple.isLittleEndian();
26
28
29 if (TheTriple.isMIPS64() && !ABI.IsN32())
31
32 if (ABI.IsO32())
34 else if (ABI.IsN32() || ABI.IsN64())
37
38 AlignmentIsInBytes = false;
39 Data16bitsDirective = "\t.2byte\t";
40 Data32bitsDirective = "\t.4byte\t";
41 Data64bitsDirective = "\t.8byte\t";
42 CommentString = "#";
44 ZeroDirective = "\t.space\t";
48 DwarfRegNumForCFI = true;
49}
50
51void MipsCOFFMCAsmInfo::anchor() {}
52
56
58
60 PrivateLabelPrefix = ".L";
61 AllowAtInName = true;
62}
63
65 MCContext &Ctx) {
66 Expr = MCSpecifierExpr::create(Expr, Mips::S_GPREL, Ctx);
67 Expr = MCSpecifierExpr::create(Expr, Mips::S_NEG, Ctx);
68 return MCSpecifierExpr::create(Expr, S, Ctx);
69}
70
71static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
72 const MCSpecifierExpr &Expr) {
73 int64_t AbsVal;
74
75 switch (Expr.getSpecifier()) {
76 case Mips::S_None:
77 case Mips::S_Special:
78 llvm_unreachable("Mips::S_None and MEK_Special are invalid");
79 break;
80 case Mips::S_DTPREL:
81 // Mips::S_DTPREL is used for marking TLS DIEExpr only
82 // and contains a regular sub-expression.
83 MAI.printExpr(OS, *Expr.getSubExpr());
84 return;
86 OS << "%call_hi";
87 break;
89 OS << "%call_lo";
90 break;
92 OS << "%dtprel_hi";
93 break;
95 OS << "%dtprel_lo";
96 break;
97 case Mips::S_GOT:
98 OS << "%got";
99 break;
100 case Mips::S_GOTTPREL:
101 OS << "%gottprel";
102 break;
103 case Mips::S_GOT_CALL:
104 OS << "%call16";
105 break;
106 case Mips::S_GOT_DISP:
107 OS << "%got_disp";
108 break;
109 case Mips::S_GOT_HI16:
110 OS << "%got_hi";
111 break;
112 case Mips::S_GOT_LO16:
113 OS << "%got_lo";
114 break;
115 case Mips::S_GOT_PAGE:
116 OS << "%got_page";
117 break;
118 case Mips::S_GOT_OFST:
119 OS << "%got_ofst";
120 break;
121 case Mips::S_GPREL:
122 OS << "%gp_rel";
123 break;
124 case Mips::S_HI:
125 OS << "%hi";
126 break;
127 case Mips::S_HIGHER:
128 OS << "%higher";
129 break;
130 case Mips::S_HIGHEST:
131 OS << "%highest";
132 break;
133 case Mips::S_LO:
134 OS << "%lo";
135 break;
136 case Mips::S_NEG:
137 OS << "%neg";
138 break;
140 OS << "%pcrel_hi";
141 break;
143 OS << "%pcrel_lo";
144 break;
145 case Mips::S_TLSGD:
146 OS << "%tlsgd";
147 break;
148 case Mips::S_TLSLDM:
149 OS << "%tlsldm";
150 break;
151 case Mips::S_TPREL_HI:
152 OS << "%tprel_hi";
153 break;
154 case Mips::S_TPREL_LO:
155 OS << "%tprel_lo";
156 break;
157 }
158
159 OS << '(';
160 if (Expr.evaluateAsAbsolute(AbsVal))
161 OS << AbsVal;
162 else
163 MAI.printExpr(OS, *Expr.getSubExpr());
164 OS << ')';
165}
166
168 if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
169 if (const auto *S1 = dyn_cast<const MCSpecifierExpr>(E.getSubExpr())) {
170 if (const auto *S2 = dyn_cast<const MCSpecifierExpr>(S1->getSubExpr())) {
171 if (S1->getSpecifier() == Mips::S_NEG &&
172 S2->getSpecifier() == Mips::S_GPREL) {
173 // S = E.getSpecifier();
174 return true;
175 }
176 }
177 }
178 }
179 return false;
180}
181
182static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
183 const MCAssembler *Asm) {
184 // Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
185 // special cases.
186 if (Mips::isGpOff(Expr)) {
187 const MCExpr *SubExpr =
188 cast<MCSpecifierExpr>(
189 cast<MCSpecifierExpr>(Expr.getSubExpr())->getSubExpr())
190 ->getSubExpr();
191 if (!SubExpr->evaluateAsRelocatable(Res, Asm))
192 return false;
193
195 return true;
196 }
197
198 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
199 return false;
200 Res.setSpecifier(Expr.getSpecifier());
201 return !Res.getSubSym();
202}
203
205 const MCSpecifierExpr &Expr) const {
206 printImpl(*this, OS, Expr);
207}
208
210 MCValue &Res,
211 const MCAssembler *Asm) const {
212 return evaluate(Expr, Res, Asm);
213}
214
216 const MCSpecifierExpr &Expr) const {
217 printImpl(*this, OS, Expr);
218}
219
221 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
222 return evaluate(Expr, Res, Asm);
223}
static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm)
constexpr LLT S1
static LVOptions Options
Definition: LVOptions.cpp:25
static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS, const MCSpecifierExpr &Expr)
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
const char * Data16bitsDirective
Definition: MCAsmInfo.h:248
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
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition: MCAsmInfo.h:160
const char * Data32bitsDirective
Definition: MCAsmInfo.h:249
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition: MCAsmInfo.h:366
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:164
void printExpr(raw_ostream &, const MCExpr &) const
Definition: MCAsmInfo.cpp:153
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition: MCAsmInfo.h:182
bool UseAssignmentForEHBegin
Definition: MCAsmInfo.h:152
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition: MCAsmInfo.h:356
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition: MCAsmInfo.h:310
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
bool IsLittleEndian
True if target is little endian. Default is true.
Definition: MCAsmInfo.h:94
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
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:450
LLVM_ABI bool evaluateAsAbsolute(int64_t &Res) const
Try to evaluate the expression to an absolute value.
Definition: MCExpr.cpp:238
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition: MCExpr.h:495
const MCExpr * getSubExpr() const
Definition: MCExpr.h:509
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:743
Spec getSpecifier() const
Definition: MCExpr.h:508
void setSpecifier(uint32_t S)
Definition: MCValue.h:47
const MCSymbol * getSubSym() const
Definition: MCValue.h:51
static MipsABIInfo computeTargetABI(const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
Definition: MipsABIInfo.cpp:60
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
MipsELFMCAsmInfo(const Triple &TheTriple, const MCTargetOptions &Options)
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition: Triple.cpp:2062
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition: Triple.h:1027
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.
bool isGpOff(const MCSpecifierExpr &E)
const MCSpecifierExpr * createGpOff(const MCExpr *Expr, Specifier S, MCContext &Ctx)
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ DwarfCFI
DWARF-like instruction based exceptions.
@ WinEH
Windows Exception Handling.