LLVM 23.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
26 IsLittleEndian = TheTriple.isLittleEndian();
27
28 MipsABIInfo ABI =
29 MipsABIInfo::computeTargetABI(TheTriple, Options.getABIName());
30
31 if (TheTriple.isMIPS64() && !ABI.IsN32())
33
34 if (ABI.IsO32())
36 else if (ABI.IsN32() || ABI.IsN64())
39
40 AlignmentIsInBytes = false;
41 Data16bitsDirective = "\t.2byte\t";
42 Data32bitsDirective = "\t.4byte\t";
43 Data64bitsDirective = "\t.8byte\t";
44 CommentString = "#";
45 ZeroDirective = "\t.space\t";
49 DwarfRegNumForCFI = true;
50}
51
52void MipsCOFFMCAsmInfo::anchor() {}
53
65
67 MCContext &Ctx) {
68 Expr = MCSpecifierExpr::create(Expr, Mips::S_GPREL, Ctx);
69 Expr = MCSpecifierExpr::create(Expr, Mips::S_NEG, Ctx);
70 return MCSpecifierExpr::create(Expr, S, Ctx);
71}
72
73static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
74 const MCSpecifierExpr &Expr) {
75 int64_t AbsVal;
76
77 switch (Expr.getSpecifier()) {
78 case Mips::S_None:
79 case Mips::S_Special:
80 llvm_unreachable("Mips::S_None and MEK_Special are invalid");
81 break;
82 case Mips::S_DTPREL:
83 // Mips::S_DTPREL is used for marking TLS DIEExpr only
84 // and contains a regular sub-expression.
85 MAI.printExpr(OS, *Expr.getSubExpr());
86 return;
88 OS << "%call_hi";
89 break;
91 OS << "%call_lo";
92 break;
94 OS << "%dtprel_hi";
95 break;
97 OS << "%dtprel_lo";
98 break;
99 case Mips::S_GOT:
100 OS << "%got";
101 break;
102 case Mips::S_GOTTPREL:
103 OS << "%gottprel";
104 break;
105 case Mips::S_GOT_CALL:
106 OS << "%call16";
107 break;
108 case Mips::S_GOT_DISP:
109 OS << "%got_disp";
110 break;
111 case Mips::S_GOT_HI16:
112 OS << "%got_hi";
113 break;
114 case Mips::S_GOT_LO16:
115 OS << "%got_lo";
116 break;
117 case Mips::S_GOT_PAGE:
118 OS << "%got_page";
119 break;
120 case Mips::S_GOT_OFST:
121 OS << "%got_ofst";
122 break;
123 case Mips::S_GPREL:
124 OS << "%gp_rel";
125 break;
126 case Mips::S_HI:
127 OS << "%hi";
128 break;
129 case Mips::S_HIGHER:
130 OS << "%higher";
131 break;
132 case Mips::S_HIGHEST:
133 OS << "%highest";
134 break;
135 case Mips::S_LO:
136 OS << "%lo";
137 break;
138 case Mips::S_NEG:
139 OS << "%neg";
140 break;
142 OS << "%pcrel_hi";
143 break;
145 OS << "%pcrel_lo";
146 break;
147 case Mips::S_TLSGD:
148 OS << "%tlsgd";
149 break;
150 case Mips::S_TLSLDM:
151 OS << "%tlsldm";
152 break;
153 case Mips::S_TPREL_HI:
154 OS << "%tprel_hi";
155 break;
156 case Mips::S_TPREL_LO:
157 OS << "%tprel_lo";
158 break;
159 }
160
161 OS << '(';
162 if (Expr.evaluateAsAbsolute(AbsVal))
163 OS << AbsVal;
164 else
165 MAI.printExpr(OS, *Expr.getSubExpr());
166 OS << ')';
167}
168
170 if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
171 if (const auto *S1 = dyn_cast<const MCSpecifierExpr>(E.getSubExpr())) {
172 if (const auto *S2 = dyn_cast<const MCSpecifierExpr>(S1->getSubExpr())) {
173 if (S1->getSpecifier() == Mips::S_NEG &&
174 S2->getSpecifier() == Mips::S_GPREL) {
175 // S = E.getSpecifier();
176 return true;
177 }
178 }
179 }
180 }
181 return false;
182}
183
184static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
185 const MCAssembler *Asm) {
186 // Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
187 // special cases.
188 if (Mips::isGpOff(Expr)) {
189 const MCExpr *SubExpr =
191 cast<MCSpecifierExpr>(Expr.getSubExpr())->getSubExpr())
192 ->getSubExpr();
193 if (!SubExpr->evaluateAsRelocatable(Res, Asm))
194 return false;
195
197 return true;
198 }
199
200 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
201 return false;
202 Res.setSpecifier(Expr.getSpecifier());
203 return !Res.getSubSym();
204}
205
207 const MCSpecifierExpr &Expr) const {
208 printImpl(*this, OS, Expr);
209}
210
212 MCValue &Res,
213 const MCAssembler *Asm) const {
214 return evaluate(Expr, Res, Asm);
215}
216
218 const MCSpecifierExpr &Expr) const {
219 printImpl(*this, OS, Expr);
220}
221
223 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
224 return evaluate(Expr, Res, Asm);
225}
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)
MCAsmInfoELF(const MCTargetOptions &Options)
MCAsmInfoGNUCOFF(const MCTargetOptions &Options)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:160
const char * Data16bitsDirective
Definition MCAsmInfo.h:247
const char * Data64bitsDirective
Definition MCAsmInfo.h:249
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:361
const char * Data32bitsDirective
Definition MCAsmInfo.h:248
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:368
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks. Defaults to "L".
Definition MCAsmInfo.h:163
void printExpr(raw_ostream &, const MCExpr &) const
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition MCAsmInfo.h:181
bool UseAssignmentForEHBegin
Definition MCAsmInfo.h:152
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:358
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition MCAsmInfo.h:312
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:272
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:225
bool DwarfRegNumForCFI
True if dwarf register numbers are printed instead of symbolic register names in ....
Definition MCAsmInfo.h:384
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 ABIName)
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
MipsCOFFMCAsmInfo(const MCTargetOptions &Options)
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:2439
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition Triple.h:1039
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 Specifier
bool isGpOff(const MCSpecifierExpr &E)
const MCSpecifierExpr * createGpOff(const MCExpr *Expr, Specifier S, MCContext &Ctx)
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
Definition MCAsmInfo.h:49
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:58
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559