LLVM 24.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 "MipsMCTargetDesc.h"
17#include "llvm/MC/MCValue.h"
20
21using namespace llvm;
22
23void MipsELFMCAsmInfo::anchor() {}
24
28 IsLittleEndian = TheTriple.isLittleEndian();
29
30 MipsABIInfo ABI =
31 MipsABIInfo::computeTargetABI(TheTriple, Options.getABIName());
32
33 if (TheTriple.isMIPS64() && !ABI.IsN32())
35
36 if (ABI.IsO32())
38 else if (ABI.IsN32() || ABI.IsN64())
40
41 AlignmentIsInBytes = false;
42 Data16bitsDirective = "\t.2byte\t";
43 Data32bitsDirective = "\t.4byte\t";
44 Data64bitsDirective = "\t.8byte\t";
45 CommentString = "#";
46 ZeroDirective = "\t.space\t";
49 DwarfRegNumForCFI = true;
50}
51
52void MipsCOFFMCAsmInfo::anchor() {}
53
62
64 MCContext &Ctx) {
65 Expr = MCSpecifierExpr::create(Expr, Mips::S_GPREL, Ctx);
66 Expr = MCSpecifierExpr::create(Expr, Mips::S_NEG, Ctx);
67 return MCSpecifierExpr::create(Expr, S, Ctx);
68}
69
70static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
71 const MCSpecifierExpr &Expr) {
72 int64_t AbsVal;
73
74 switch (Expr.getSpecifier()) {
75 case Mips::S_None:
76 case Mips::S_Special:
77 llvm_unreachable("Mips::S_None and MEK_Special are invalid");
78 break;
79 case Mips::S_DTPREL:
80 // Mips::S_DTPREL is used for marking TLS DIEExpr only
81 // and contains a regular sub-expression.
82 MAI.printExpr(OS, *Expr.getSubExpr());
83 return;
85 OS << "%call_hi";
86 break;
88 OS << "%call_lo";
89 break;
91 OS << "%dtprel_hi";
92 break;
94 OS << "%dtprel_lo";
95 break;
96 case Mips::S_GOT:
97 OS << "%got";
98 break;
100 OS << "%gottprel";
101 break;
102 case Mips::S_GOT_CALL:
103 OS << "%call16";
104 break;
105 case Mips::S_GOT_DISP:
106 OS << "%got_disp";
107 break;
108 case Mips::S_GOT_HI16:
109 OS << "%got_hi";
110 break;
111 case Mips::S_GOT_LO16:
112 OS << "%got_lo";
113 break;
114 case Mips::S_GOT_PAGE:
115 OS << "%got_page";
116 break;
117 case Mips::S_GOT_OFST:
118 OS << "%got_ofst";
119 break;
120 case Mips::S_GPREL:
121 OS << "%gp_rel";
122 break;
123 case Mips::S_HI:
124 OS << "%hi";
125 break;
126 case Mips::S_HIGHER:
127 OS << "%higher";
128 break;
129 case Mips::S_HIGHEST:
130 OS << "%highest";
131 break;
132 case Mips::S_LO:
133 OS << "%lo";
134 break;
135 case Mips::S_NEG:
136 OS << "%neg";
137 break;
139 OS << "%pcrel_hi";
140 break;
142 OS << "%pcrel_lo";
143 break;
144 case Mips::S_TLSGD:
145 OS << "%tlsgd";
146 break;
147 case Mips::S_TLSLDM:
148 OS << "%tlsldm";
149 break;
150 case Mips::S_TPREL_HI:
151 OS << "%tprel_hi";
152 break;
153 case Mips::S_TPREL_LO:
154 OS << "%tprel_lo";
155 break;
156 }
157
158 OS << '(';
159 if (Expr.evaluateAsAbsolute(AbsVal))
160 OS << AbsVal;
161 else
162 MAI.printExpr(OS, *Expr.getSubExpr());
163 OS << ')';
164}
165
167 if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
168 if (const auto *S1 = dyn_cast<const MCSpecifierExpr>(E.getSubExpr())) {
169 if (const auto *S2 = dyn_cast<const MCSpecifierExpr>(S1->getSubExpr())) {
170 if (S1->getSpecifier() == Mips::S_NEG &&
171 S2->getSpecifier() == Mips::S_GPREL) {
172 // S = E.getSpecifier();
173 return true;
174 }
175 }
176 }
177 }
178 return false;
179}
180
181static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
182 const MCAssembler *Asm) {
183 // Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
184 // special cases.
185 if (Mips::isGpOff(Expr)) {
186 const MCExpr *SubExpr =
188 cast<MCSpecifierExpr>(Expr.getSubExpr())->getSubExpr())
189 ->getSubExpr();
190 if (!SubExpr->evaluateAsRelocatable(Res, Asm))
191 return false;
192
194 return true;
195 }
196
197 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
198 return false;
199 Res.setSpecifier(Expr.getSpecifier());
200 return !Res.getSubSym();
201}
202
204 const MCSpecifierExpr &Expr) const {
205 printImpl(*this, OS, Expr);
206}
207
209 MCValue &Res,
210 const MCAssembler *Asm) const {
211 return evaluate(Expr, Res, Asm);
212}
213
215 // microMIPS encoding uses compressed intruction byte-order
216 return STI.hasFeature(Mips::FeatureMicroMips);
217}
218
220 const MCSpecifierExpr &Expr) const {
221 printImpl(*this, OS, Expr);
222}
223
225 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
226 return evaluate(Expr, Res, Asm);
227}
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:67
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:159
const char * Data16bitsDirective
Definition MCAsmInfo.h:246
const char * Data64bitsDirective
Definition MCAsmInfo.h:248
const char * Data32bitsDirective
Definition MCAsmInfo.h:247
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:365
void printExpr(raw_ostream &, const MCExpr &) const
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition MCAsmInfo.h:177
bool UseAssignmentForEHBegin
Definition MCAsmInfo.h:151
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:357
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition MCAsmInfo.h:311
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:271
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:224
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:93
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:86
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:90
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:134
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:494
const MCExpr * getSubExpr() const
Definition MCExpr.h:508
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Spec getSpecifier() const
Definition MCExpr.h:507
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
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
bool usesCompInstByteOrder(const MCSubtargetInfo &STI) const override
True if the instruction is stored in multiple halfwords, with the high-order half appearing first in ...
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:48
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition Triple.cpp:2213
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition Triple.h:1133
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:52
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
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559