1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
//===-- MipsMCAsmInfo.cpp - Mips Asm Properties ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the declarations of the MipsMCAsmInfo properties.
//
//===----------------------------------------------------------------------===//
#include "MipsMCAsmInfo.h"
#include "MipsABIInfo.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Casting.h"
#include "llvm/TargetParser/Triple.h"
using namespace llvm;
void MipsELFMCAsmInfo::anchor() {}
MipsELFMCAsmInfo::MipsELFMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options) {
IsLittleEndian = TheTriple.isLittleEndian();
MipsABIInfo ABI = MipsABIInfo::computeTargetABI(TheTriple, "", Options);
if (TheTriple.isMIPS64() && !ABI.IsN32())
CodePointerSize = CalleeSaveStackSlotSize = 8;
if (ABI.IsO32())
PrivateGlobalPrefix = "$";
else if (ABI.IsN32() || ABI.IsN64())
PrivateGlobalPrefix = ".L";
PrivateLabelPrefix = PrivateGlobalPrefix;
AlignmentIsInBytes = false;
Data16bitsDirective = "\t.2byte\t";
Data32bitsDirective = "\t.4byte\t";
Data64bitsDirective = "\t.8byte\t";
CommentString = "#";
AllowDollarAtStartOfIdentifier = false;
ZeroDirective = "\t.space\t";
UseAssignmentForEHBegin = true;
SupportsDebugInformation = true;
ExceptionsType = ExceptionHandling::DwarfCFI;
DwarfRegNumForCFI = true;
}
void MipsCOFFMCAsmInfo::anchor() {}
MipsCOFFMCAsmInfo::MipsCOFFMCAsmInfo() {
HasSingleParameterDotFile = true;
WinEHEncodingType = WinEH::EncodingType::Itanium;
ExceptionsType = ExceptionHandling::WinEH;
PrivateGlobalPrefix = ".L";
PrivateLabelPrefix = ".L";
AllowAtInName = true;
}
const MCSpecifierExpr *Mips::createGpOff(const MCExpr *Expr, Mips::Specifier S,
MCContext &Ctx) {
Expr = MCSpecifierExpr::create(Expr, Mips::S_GPREL, Ctx);
Expr = MCSpecifierExpr::create(Expr, Mips::S_NEG, Ctx);
return MCSpecifierExpr::create(Expr, S, Ctx);
}
static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
const MCSpecifierExpr &Expr) {
int64_t AbsVal;
switch (Expr.getSpecifier()) {
case Mips::S_None:
case Mips::S_Special:
llvm_unreachable("Mips::S_None and MEK_Special are invalid");
break;
case Mips::S_DTPREL:
// Mips::S_DTPREL is used for marking TLS DIEExpr only
// and contains a regular sub-expression.
MAI.printExpr(OS, *Expr.getSubExpr());
return;
case Mips::S_CALL_HI16:
OS << "%call_hi";
break;
case Mips::S_CALL_LO16:
OS << "%call_lo";
break;
case Mips::S_DTPREL_HI:
OS << "%dtprel_hi";
break;
case Mips::S_DTPREL_LO:
OS << "%dtprel_lo";
break;
case Mips::S_GOT:
OS << "%got";
break;
case Mips::S_GOTTPREL:
OS << "%gottprel";
break;
case Mips::S_GOT_CALL:
OS << "%call16";
break;
case Mips::S_GOT_DISP:
OS << "%got_disp";
break;
case Mips::S_GOT_HI16:
OS << "%got_hi";
break;
case Mips::S_GOT_LO16:
OS << "%got_lo";
break;
case Mips::S_GOT_PAGE:
OS << "%got_page";
break;
case Mips::S_GOT_OFST:
OS << "%got_ofst";
break;
case Mips::S_GPREL:
OS << "%gp_rel";
break;
case Mips::S_HI:
OS << "%hi";
break;
case Mips::S_HIGHER:
OS << "%higher";
break;
case Mips::S_HIGHEST:
OS << "%highest";
break;
case Mips::S_LO:
OS << "%lo";
break;
case Mips::S_NEG:
OS << "%neg";
break;
case Mips::S_PCREL_HI16:
OS << "%pcrel_hi";
break;
case Mips::S_PCREL_LO16:
OS << "%pcrel_lo";
break;
case Mips::S_TLSGD:
OS << "%tlsgd";
break;
case Mips::S_TLSLDM:
OS << "%tlsldm";
break;
case Mips::S_TPREL_HI:
OS << "%tprel_hi";
break;
case Mips::S_TPREL_LO:
OS << "%tprel_lo";
break;
}
OS << '(';
if (Expr.evaluateAsAbsolute(AbsVal))
OS << AbsVal;
else
MAI.printExpr(OS, *Expr.getSubExpr());
OS << ')';
}
bool Mips::isGpOff(const MCSpecifierExpr &E) {
if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
if (const auto *S1 = dyn_cast<const MCSpecifierExpr>(E.getSubExpr())) {
if (const auto *S2 = dyn_cast<const MCSpecifierExpr>(S1->getSubExpr())) {
if (S1->getSpecifier() == Mips::S_NEG &&
S2->getSpecifier() == Mips::S_GPREL) {
// S = E.getSpecifier();
return true;
}
}
}
}
return false;
}
static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
const MCAssembler *Asm) {
// Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
// special cases.
if (Mips::isGpOff(Expr)) {
const MCExpr *SubExpr =
cast<MCSpecifierExpr>(
cast<MCSpecifierExpr>(Expr.getSubExpr())->getSubExpr())
->getSubExpr();
if (!SubExpr->evaluateAsRelocatable(Res, Asm))
return false;
Res.setSpecifier(Mips::S_Special);
return true;
}
if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
return false;
Res.setSpecifier(Expr.getSpecifier());
return !Res.getSubSym();
}
void MipsELFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
const MCSpecifierExpr &Expr) const {
printImpl(*this, OS, Expr);
}
bool MipsELFMCAsmInfo::evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr,
MCValue &Res,
const MCAssembler *Asm) const {
return evaluate(Expr, Res, Asm);
}
void MipsCOFFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
const MCSpecifierExpr &Expr) const {
printImpl(*this, OS, Expr);
}
bool MipsCOFFMCAsmInfo::evaluateAsRelocatableImpl(
const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
return evaluate(Expr, Res, Asm);
}
|