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
23static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
24 const MCSpecifierExpr &Expr) {
25 int64_t AbsVal;
26
27 switch (Expr.getSpecifier()) {
28 case Mips::S_None:
29 case Mips::S_Special:
30 llvm_unreachable("Mips::S_None and MEK_Special are invalid");
31 break;
32 case Mips::S_DTPREL:
33 // Mips::S_DTPREL is used for marking TLS DIEExpr only
34 // and contains a regular sub-expression.
35 MAI.printExpr(OS, *Expr.getSubExpr());
36 return;
38 OS << "%call_hi";
39 break;
41 OS << "%call_lo";
42 break;
44 OS << "%dtprel_hi";
45 break;
47 OS << "%dtprel_lo";
48 break;
49 case Mips::S_GOT:
50 OS << "%got";
51 break;
53 OS << "%gottprel";
54 break;
56 OS << "%call16";
57 break;
59 OS << "%got_disp";
60 break;
62 OS << "%got_hi";
63 break;
65 OS << "%got_lo";
66 break;
68 OS << "%got_page";
69 break;
71 OS << "%got_ofst";
72 break;
73 case Mips::S_GPREL:
74 OS << "%gp_rel";
75 break;
76 case Mips::S_HI:
77 OS << "%hi";
78 break;
79 case Mips::S_HIGHER:
80 OS << "%higher";
81 break;
82 case Mips::S_HIGHEST:
83 OS << "%highest";
84 break;
85 case Mips::S_LO:
86 OS << "%lo";
87 break;
88 case Mips::S_NEG:
89 OS << "%neg";
90 break;
92 OS << "%pcrel_hi";
93 break;
95 OS << "%pcrel_lo";
96 break;
97 case Mips::S_TLSGD:
98 OS << "%tlsgd";
99 break;
100 case Mips::S_TLSLDM:
101 OS << "%tlsldm";
102 break;
103 case Mips::S_TPREL_HI:
104 OS << "%tprel_hi";
105 break;
106 case Mips::S_TPREL_LO:
107 OS << "%tprel_lo";
108 break;
109 }
110
111 OS << '(';
112 if (Expr.evaluateAsAbsolute(AbsVal))
113 OS << AbsVal;
114 else
115 MAI.printExpr(OS, *Expr.getSubExpr());
116 OS << ')';
117}
118
119static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
120 const MCAssembler *Asm) {
121 // Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
122 // special cases.
123 if (Mips::isGpOff(Expr)) {
124 const MCExpr *SubExpr =
126 cast<MCSpecifierExpr>(Expr.getSubExpr())->getSubExpr())
127 ->getSubExpr();
128 if (!SubExpr->evaluateAsRelocatable(Res, Asm))
129 return false;
130
132 return true;
133 }
134
135 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
136 return false;
137 Res.setSpecifier(Expr.getSpecifier());
138 return !Res.getSubSym();
139}
140
143 : MCAsmInfoELF(TheTriple, Options) {
144 IsLittleEndian = TheTriple.isLittleEndian();
145 // microMIPS encoding uses compressed intruction byte-order
146 CompInstByteOrderFeature = Mips::FeatureMicroMips;
147
148 MipsABIInfo ABI =
149 MipsABIInfo::computeTargetABI(TheTriple, Options.getABIName());
150
151 if (TheTriple.isMIPS64() && !ABI.IsN32())
153
154 if (ABI.IsO32())
156 else if (ABI.IsN32() || ABI.IsN64())
158
159 AlignmentIsInBytes = false;
160 Data16bitsDirective = "\t.2byte\t";
161 Data32bitsDirective = "\t.4byte\t";
162 Data64bitsDirective = "\t.8byte\t";
163 CommentString = "#";
164 ZeroDirective = "\t.space\t";
167 DwarfRegNumForCFI = true;
168
169 // .bss is supported without .section.
170 SectionDirectives.insert(".bss");
171
174}
175
187
189 MCContext &Ctx) {
190 Expr = MCSpecifierExpr::create(Expr, Mips::S_GPREL, Ctx);
191 Expr = MCSpecifierExpr::create(Expr, Mips::S_NEG, Ctx);
192 return MCSpecifierExpr::create(Expr, S, Ctx);
193}
194
196 if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
197 if (const auto *S1 = dyn_cast<const MCSpecifierExpr>(E.getSubExpr())) {
198 if (const auto *S2 = dyn_cast<const MCSpecifierExpr>(S1->getSubExpr())) {
199 if (S1->getSpecifier() == Mips::S_NEG &&
200 S2->getSpecifier() == Mips::S_GPREL) {
201 // S = E.getSpecifier();
202 return true;
203 }
204 }
205 }
206 }
207 return false;
208}
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)
static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm)
MCAsmInfoELF(const Triple &TT, 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:69
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:169
const char * Data16bitsDirective
Definition MCAsmInfo.h:262
bool(* SpecifierExprEvaluateFn)(const MCSpecifierExpr &E, MCValue &Res, const MCAssembler *Asm)
Definition MCAsmInfo.h:231
std::optional< unsigned > CompInstByteOrderFeature
Feature that indicates mixed-endian byte order.
Definition MCAsmInfo.h:99
const char * Data64bitsDirective
Definition MCAsmInfo.h:264
const char * Data32bitsDirective
Definition MCAsmInfo.h:263
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:380
void printExpr(raw_ostream &, const MCExpr &) const
SmallDenseSet< StringRef, 8 > SectionDirectives
Sections whose name also is supported as a directive without an explicit ".section" directive.
Definition MCAsmInfo.h:475
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition MCAsmInfo.h:187
bool UseAssignmentForEHBegin
Definition MCAsmInfo.h:161
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:372
void(* SpecifierExprPrintFn)(const MCAsmInfo &, raw_ostream &, const MCSpecifierExpr &)
Definition MCAsmInfo.h:228
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition MCAsmInfo.h:326
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:286
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:240
bool DwarfRegNumForCFI
True if dwarf register numbers are printed instead of symbolic register names in ....
Definition MCAsmInfo.h:408
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:95
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:88
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:92
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:144
Context object for machine code objects.
Definition MCContext.h:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
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:491
const MCExpr * getSubExpr() const
Definition MCExpr.h:505
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Spec getSpecifier() const
Definition MCExpr.h:504
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)
MipsCOFFMCAsmInfo(const MCTargetOptions &Options)
MipsELFMCAsmInfo(const Triple &TheTriple, const MCTargetOptions &Options)
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:2228
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition Triple.h:1135
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