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
27 MipsABIInfo ABI =
28 MipsABIInfo::computeTargetABI(TheTriple, Options.getABIName());
29
30 if (TheTriple.isMIPS64() && !ABI.IsN32())
32
33 if (ABI.IsO32())
35 else if (ABI.IsN32() || ABI.IsN64())
38
39 AlignmentIsInBytes = false;
40 Data16bitsDirective = "\t.2byte\t";
41 Data32bitsDirective = "\t.4byte\t";
42 Data64bitsDirective = "\t.8byte\t";
43 CommentString = "#";
45 ZeroDirective = "\t.space\t";
49 DwarfRegNumForCFI = true;
50}
51
52void MipsCOFFMCAsmInfo::anchor() {}
53
64
66 MCContext &Ctx) {
67 Expr = MCSpecifierExpr::create(Expr, Mips::S_GPREL, Ctx);
68 Expr = MCSpecifierExpr::create(Expr, Mips::S_NEG, Ctx);
69 return MCSpecifierExpr::create(Expr, S, Ctx);
70}
71
72static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
73 const MCSpecifierExpr &Expr) {
74 int64_t AbsVal;
75
76 switch (Expr.getSpecifier()) {
77 case Mips::S_None:
78 case Mips::S_Special:
79 llvm_unreachable("Mips::S_None and MEK_Special are invalid");
80 break;
81 case Mips::S_DTPREL:
82 // Mips::S_DTPREL is used for marking TLS DIEExpr only
83 // and contains a regular sub-expression.
84 MAI.printExpr(OS, *Expr.getSubExpr());
85 return;
87 OS << "%call_hi";
88 break;
90 OS << "%call_lo";
91 break;
93 OS << "%dtprel_hi";
94 break;
96 OS << "%dtprel_lo";
97 break;
98 case Mips::S_GOT:
99 OS << "%got";
100 break;
101 case Mips::S_GOTTPREL:
102 OS << "%gottprel";
103 break;
104 case Mips::S_GOT_CALL:
105 OS << "%call16";
106 break;
107 case Mips::S_GOT_DISP:
108 OS << "%got_disp";
109 break;
110 case Mips::S_GOT_HI16:
111 OS << "%got_hi";
112 break;
113 case Mips::S_GOT_LO16:
114 OS << "%got_lo";
115 break;
116 case Mips::S_GOT_PAGE:
117 OS << "%got_page";
118 break;
119 case Mips::S_GOT_OFST:
120 OS << "%got_ofst";
121 break;
122 case Mips::S_GPREL:
123 OS << "%gp_rel";
124 break;
125 case Mips::S_HI:
126 OS << "%hi";
127 break;
128 case Mips::S_HIGHER:
129 OS << "%higher";
130 break;
131 case Mips::S_HIGHEST:
132 OS << "%highest";
133 break;
134 case Mips::S_LO:
135 OS << "%lo";
136 break;
137 case Mips::S_NEG:
138 OS << "%neg";
139 break;
141 OS << "%pcrel_hi";
142 break;
144 OS << "%pcrel_lo";
145 break;
146 case Mips::S_TLSGD:
147 OS << "%tlsgd";
148 break;
149 case Mips::S_TLSLDM:
150 OS << "%tlsldm";
151 break;
152 case Mips::S_TPREL_HI:
153 OS << "%tprel_hi";
154 break;
155 case Mips::S_TPREL_LO:
156 OS << "%tprel_lo";
157 break;
158 }
159
160 OS << '(';
161 if (Expr.evaluateAsAbsolute(AbsVal))
162 OS << AbsVal;
163 else
164 MAI.printExpr(OS, *Expr.getSubExpr());
165 OS << ')';
166}
167
169 if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
170 if (const auto *S1 = dyn_cast<const MCSpecifierExpr>(E.getSubExpr())) {
171 if (const auto *S2 = dyn_cast<const MCSpecifierExpr>(S1->getSubExpr())) {
172 if (S1->getSpecifier() == Mips::S_NEG &&
173 S2->getSpecifier() == Mips::S_GPREL) {
174 // S = E.getSpecifier();
175 return true;
176 }
177 }
178 }
179 }
180 return false;
181}
182
183static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
184 const MCAssembler *Asm) {
185 // Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
186 // special cases.
187 if (Mips::isGpOff(Expr)) {
188 const MCExpr *SubExpr =
190 cast<MCSpecifierExpr>(Expr.getSubExpr())->getSubExpr())
191 ->getSubExpr();
192 if (!SubExpr->evaluateAsRelocatable(Res, Asm))
193 return false;
194
196 return true;
197 }
198
199 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
200 return false;
201 Res.setSpecifier(Expr.getSpecifier());
202 return !Res.getSubSym();
203}
204
206 const MCSpecifierExpr &Expr) const {
207 printImpl(*this, OS, Expr);
208}
209
211 MCValue &Res,
212 const MCAssembler *Asm) const {
213 return evaluate(Expr, Res, Asm);
214}
215
217 const MCSpecifierExpr &Expr) const {
218 printImpl(*this, OS, Expr);
219}
220
222 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
223 return evaluate(Expr, Res, Asm);
224}
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)
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
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 ABIName)
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:2075
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition Triple.h:1030
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:649
@ 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:565