Skip to content

Commit 9ec75a5

Browse files
committed
MIPS: Replace MipsMCExpr with MCSpecifierExpr
1 parent c66be28 commit 9ec75a5

12 files changed

+58
-125
lines changed

llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,9 +2965,9 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
29652965
Res.getConstant() == 0 && !IsLocalSym) {
29662966
if (UseXGOT) {
29672967
const MCExpr *CallHiExpr =
2968-
MipsMCExpr::create(Mips::S_CALL_HI16, SymExpr, getContext());
2968+
MCSpecifierExpr::create(SymExpr, Mips::S_CALL_HI16, getContext());
29692969
const MCExpr *CallLoExpr =
2970-
MipsMCExpr::create(Mips::S_CALL_LO16, SymExpr, getContext());
2970+
MCSpecifierExpr::create(SymExpr, Mips::S_CALL_LO16, getContext());
29712971
TOut.emitRX(Mips::LUi, DstReg, MCOperand::createExpr(CallHiExpr), IDLoc,
29722972
STI);
29732973
TOut.emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, DstReg, GPReg,
@@ -2976,7 +2976,7 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
29762976
MCOperand::createExpr(CallLoExpr), IDLoc, STI);
29772977
} else {
29782978
const MCExpr *CallExpr =
2979-
MipsMCExpr::create(Mips::S_GOT_CALL, SymExpr, getContext());
2979+
MCSpecifierExpr::create(SymExpr, Mips::S_GOT_CALL, getContext());
29802980
TOut.emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, GPReg,
29812981
MCOperand::createExpr(CallExpr), IDLoc, STI);
29822982
}
@@ -3009,9 +3009,9 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
30093009
// this happens then the last instruction must use $rd as the result
30103010
// register.
30113011
const MCExpr *CallHiExpr =
3012-
MipsMCExpr::create(Mips::S_GOT_HI16, SymExpr, getContext());
3013-
const MCExpr *CallLoExpr =
3014-
MipsMCExpr::create(Res.getAddSym(), Mips::S_GOT_LO16, getContext());
3012+
MCSpecifierExpr::create(SymExpr, Mips::S_GOT_HI16, getContext());
3013+
const MCExpr *CallLoExpr = MCSpecifierExpr::create(
3014+
Res.getAddSym(), Mips::S_GOT_LO16, getContext());
30153015

30163016
TOut.emitRX(Mips::LUi, TmpReg, MCOperand::createExpr(CallHiExpr), IDLoc,
30173017
STI);
@@ -3042,8 +3042,8 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
30423042
// The daddiu's marked with a '>' may be omitted if they are redundant. If
30433043
// this happens then the last instruction must use $rd as the result
30443044
// register.
3045-
GotExpr =
3046-
MipsMCExpr::create(Res.getAddSym(), Mips::S_GOT_DISP, getContext());
3045+
GotExpr = MCSpecifierExpr::create(Res.getAddSym(), Mips::S_GOT_DISP,
3046+
getContext());
30473047
if (Res.getConstant() != 0) {
30483048
// Symbols fully resolve with just the %got_disp(symbol) but we
30493049
// must still account for any offset to the symbol for
@@ -3070,14 +3070,14 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
30703070
// this happens then the last instruction must use $rd as the result
30713071
// register.
30723072
if (IsLocalSym) {
3073-
GotExpr = MipsMCExpr::create(Mips::S_GOT, SymExpr, getContext());
3074-
LoExpr = MipsMCExpr::create(Mips::S_LO, SymExpr, getContext());
3073+
GotExpr = MCSpecifierExpr::create(SymExpr, Mips::S_GOT, getContext());
3074+
LoExpr = MCSpecifierExpr::create(SymExpr, Mips::S_LO, getContext());
30753075
} else {
30763076
// External symbols fully resolve the symbol with just the %got(symbol)
30773077
// but we must still account for any offset to the symbol for
30783078
// expressions like symbol+8.
30793079
GotExpr =
3080-
MipsMCExpr::create(Res.getAddSym(), Mips::S_GOT, getContext());
3080+
MCSpecifierExpr::create(Res.getAddSym(), Mips::S_GOT, getContext());
30813081
if (Res.getConstant() != 0)
30823082
LoExpr = MCConstantExpr::create(Res.getConstant(), getContext());
30833083
}
@@ -3097,8 +3097,10 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
30973097
return false;
30983098
}
30993099

3100-
const auto *HiExpr = MipsMCExpr::create(Mips::S_HI, SymExpr, getContext());
3101-
const auto *LoExpr = MipsMCExpr::create(Mips::S_LO, SymExpr, getContext());
3100+
const auto *HiExpr =
3101+
MCSpecifierExpr::create(SymExpr, Mips::S_HI, getContext());
3102+
const auto *LoExpr =
3103+
MCSpecifierExpr::create(SymExpr, Mips::S_LO, getContext());
31023104

31033105
// This is the 64-bit symbol address expansion.
31043106
if (ABI.ArePtrs64bit() && isGP64bit()) {
@@ -3110,9 +3112,9 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
31103112
// source register.
31113113

31123114
const auto *HighestExpr =
3113-
MipsMCExpr::create(Mips::S_HIGHEST, SymExpr, getContext());
3115+
MCSpecifierExpr::create(SymExpr, Mips::S_HIGHEST, getContext());
31143116
const auto *HigherExpr =
3115-
MipsMCExpr::create(Mips::S_HIGHER, SymExpr, getContext());
3117+
MCSpecifierExpr::create(SymExpr, Mips::S_HIGHER, getContext());
31163118

31173119
bool RdRegIsRsReg =
31183120
UseSrcReg &&
@@ -3310,7 +3312,8 @@ bool MipsAsmParser::emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc,
33103312

33113313
if(IsPicEnabled) {
33123314
const MCExpr *GotSym = MCSymbolRefExpr::create(Sym, getContext());
3313-
const auto *GotExpr = MipsMCExpr::create(Mips::S_GOT, GotSym, getContext());
3315+
const auto *GotExpr =
3316+
MCSpecifierExpr::create(GotSym, Mips::S_GOT, getContext());
33143317

33153318
if(isABI_O32() || isABI_N32()) {
33163319
TOut.emitRRX(Mips::LW, ATReg, GPReg, MCOperand::createExpr(GotExpr),
@@ -3321,7 +3324,8 @@ bool MipsAsmParser::emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc,
33213324
}
33223325
} else { //!IsPicEnabled
33233326
const MCExpr *HiSym = MCSymbolRefExpr::create(Sym, getContext());
3324-
const auto *HiExpr = MipsMCExpr::create(Mips::S_HI, HiSym, getContext());
3327+
const auto *HiExpr =
3328+
MCSpecifierExpr::create(HiSym, Mips::S_HI, getContext());
33253329

33263330
// FIXME: This is technically correct but gives a different result to gas,
33273331
// but gas is incomplete there (it has a fixme noting it doesn't work with
@@ -3334,10 +3338,10 @@ bool MipsAsmParser::emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc,
33343338
} else { //isABI_N64()
33353339
const MCExpr *HighestSym = MCSymbolRefExpr::create(Sym, getContext());
33363340
const auto *HighestExpr =
3337-
MipsMCExpr::create(Mips::S_HIGHEST, HighestSym, getContext());
3341+
MCSpecifierExpr::create(HighestSym, Mips::S_HIGHEST, getContext());
33383342
const MCExpr *HigherSym = MCSymbolRefExpr::create(Sym, getContext());
33393343
const auto *HigherExpr =
3340-
MipsMCExpr::create(Mips::S_HIGHER, HigherSym, getContext());
3344+
MCSpecifierExpr::create(HigherSym, Mips::S_HIGHER, getContext());
33413345

33423346
TOut.emitRX(Mips::LUi, ATReg, MCOperand::createExpr(HighestExpr), IDLoc,
33433347
STI);
@@ -3424,7 +3428,7 @@ bool MipsAsmParser::expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc,
34243428

34253429
MCSymbol *Sym = getContext().createTempSymbol();
34263430
const MCExpr *LoSym = MCSymbolRefExpr::create(Sym, getContext());
3427-
const auto *LoExpr = MipsMCExpr::create(Mips::S_LO, LoSym, getContext());
3431+
const auto *LoExpr = MCSpecifierExpr::create(LoSym, Mips::S_LO, getContext());
34283432

34293433
getStreamer().switchSection(ReadOnlySection);
34303434
getStreamer().emitLabel(Sym, IDLoc);
@@ -3474,7 +3478,7 @@ bool MipsAsmParser::expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc,
34743478

34753479
MCSymbol *Sym = getContext().createTempSymbol();
34763480
const MCExpr *LoSym = MCSymbolRefExpr::create(Sym, getContext());
3477-
const auto *LoExpr = MipsMCExpr::create(Mips::S_LO, LoSym, getContext());
3481+
const auto *LoExpr = MCSpecifierExpr::create(LoSym, Mips::S_LO, getContext());
34783482

34793483
getStreamer().switchSection(ReadOnlySection);
34803484
getStreamer().emitLabel(Sym, IDLoc);
@@ -3554,7 +3558,7 @@ bool MipsAsmParser::expandLoadDoubleImmToFPR(MCInst &Inst, bool Is64FPU,
35543558

35553559
MCSymbol *Sym = getContext().createTempSymbol();
35563560
const MCExpr *LoSym = MCSymbolRefExpr::create(Sym, getContext());
3557-
const auto *LoExpr = MipsMCExpr::create(Mips::S_LO, LoSym, getContext());
3561+
const auto *LoExpr = MCSpecifierExpr::create(LoSym, Mips::S_LO, getContext());
35583562

35593563
getStreamer().switchSection(ReadOnlySection);
35603564
getStreamer().emitLabel(Sym, IDLoc);
@@ -3777,15 +3781,15 @@ void MipsAsmParser::expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
37773781
// sw $8, %lo(sym)($at)
37783782
const MCExpr *OffExpr = OffsetOp.getExpr();
37793783
MCOperand LoOperand = MCOperand::createExpr(
3780-
MipsMCExpr::create(Mips::S_LO, OffExpr, getContext()));
3784+
MCSpecifierExpr::create(OffExpr, Mips::S_LO, getContext()));
37813785
MCOperand HiOperand = MCOperand::createExpr(
3782-
MipsMCExpr::create(Mips::S_HI, OffExpr, getContext()));
3786+
MCSpecifierExpr::create(OffExpr, Mips::S_HI, getContext()));
37833787

37843788
if (ABI.IsN64()) {
37853789
MCOperand HighestOperand = MCOperand::createExpr(
3786-
MipsMCExpr::create(Mips::S_HIGHEST, OffExpr, getContext()));
3790+
MCSpecifierExpr::create(OffExpr, Mips::S_HIGHEST, getContext()));
37873791
MCOperand HigherOperand = MCOperand::createExpr(
3788-
MipsMCExpr::create(Mips::S_HIGHER, OffExpr, getContext()));
3792+
MCSpecifierExpr::create(OffExpr, Mips::S_HIGHER, getContext()));
37893793

37903794
TOut.emitRX(Mips::LUi, TmpReg, HighestOperand, IDLoc, STI);
37913795
TOut.emitRRX(Mips::DADDiu, TmpReg, TmpReg, HigherOperand, IDLoc, STI);
@@ -6394,7 +6398,7 @@ const MCExpr *MipsAsmParser::parseRelocExpr() {
63946398
while (Ops.size()) {
63956399
if (Parser.parseToken(AsmToken::RParen, "expected ')'"))
63966400
return nullptr;
6397-
Res = MipsMCExpr::create(Ops.pop_back_val(), Res, getContext());
6401+
Res = MCSpecifierExpr::create(Res, Ops.pop_back_val(), getContext());
63986402
}
63996403
return Res;
64006404
}

llvm/lib/Target/Mips/MCTargetDesc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_llvm_component_library(LLVMMipsDesc
77
MipsInstPrinter.cpp
88
MipsMCAsmInfo.cpp
99
MipsMCCodeEmitter.cpp
10-
MipsMCExpr.cpp
1110
MipsMCTargetDesc.cpp
1211
MipsNaClELFStreamer.cpp
1312
MipsOptionRecord.cpp

llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/MC/MCFixup.h"
1717
#include "llvm/MC/MCObjectWriter.h"
1818
#include "llvm/MC/MCSymbolELF.h"
19+
#include "llvm/MC/MCValue.h"
1920
#include "llvm/Support/Casting.h"
2021
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/Debug.h"

llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "MipsMCAsmInfo.h"
1414
#include "MipsABIInfo.h"
15+
#include "llvm/MC/MCValue.h"
1516
#include "llvm/Support/Casting.h"
1617
#include "llvm/TargetParser/Triple.h"
1718

@@ -59,6 +60,13 @@ MipsCOFFMCAsmInfo::MipsCOFFMCAsmInfo() {
5960
AllowAtInName = true;
6061
}
6162

63+
const MCSpecifierExpr *Mips::createGpOff(const MCExpr *Expr, Mips::Specifier S,
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+
6270
static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
6371
const MCSpecifierExpr &Expr) {
6472
int64_t AbsVal;

llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCASMINFO_H
1414
#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCASMINFO_H
1515

16-
#include "MCTargetDesc/MipsMCExpr.h"
1716
#include "llvm/MC/MCAsmInfoCOFF.h"
1817
#include "llvm/MC/MCAsmInfoELF.h"
1918
#include "llvm/MC/MCFixup.h"
@@ -77,6 +76,8 @@ enum {
7776
};
7877

7978
bool isGpOff(const MCSpecifierExpr &E);
79+
const MCSpecifierExpr *createGpOff(const MCExpr *Expr, Specifier S,
80+
MCContext &Ctx);
8081
}
8182

8283
} // namespace llvm

llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
581581
const MCSubtargetInfo &STI) const {
582582
MCExpr::ExprKind Kind = Expr->getKind();
583583
if (Kind == MCExpr::Specifier) {
584-
const MipsMCExpr *MipsExpr = cast<MipsMCExpr>(Expr);
584+
const auto *MipsExpr = cast<MCSpecifierExpr>(Expr);
585585

586586
Mips::Fixups FixupKind = Mips::Fixups(0);
587587
switch (MipsExpr->getSpecifier()) {

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "MipsBaseInfo.h"
1717
#include "MipsELFStreamer.h"
1818
#include "MipsInstPrinter.h"
19-
#include "MipsMCExpr.h"
2019
#include "MipsMCTargetDesc.h"
2120
#include "llvm/BinaryFormat/ELF.h"
2221
#include "llvm/MC/MCAsmInfo.h"
@@ -1266,9 +1265,7 @@ void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
12661265
MCInst TmpInst;
12671266
TmpInst.setOpcode(Mips::LUi);
12681267
TmpInst.addOperand(MCOperand::createReg(GPReg));
1269-
const MCExpr *HiSym = MipsMCExpr::create(
1270-
Mips::S_HI, MCSymbolRefExpr::create(GP_Disp, MCA.getContext()),
1271-
MCA.getContext());
1268+
auto *HiSym = MCSpecifierExpr::create(GP_Disp, Mips::S_HI, MCA.getContext());
12721269
TmpInst.addOperand(MCOperand::createExpr(HiSym));
12731270
getStreamer().emitInstruction(TmpInst, STI);
12741271

@@ -1277,9 +1274,7 @@ void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
12771274
TmpInst.setOpcode(Mips::ADDiu);
12781275
TmpInst.addOperand(MCOperand::createReg(GPReg));
12791276
TmpInst.addOperand(MCOperand::createReg(GPReg));
1280-
const MCExpr *LoSym = MipsMCExpr::create(
1281-
Mips::S_LO, MCSymbolRefExpr::create(GP_Disp, MCA.getContext()),
1282-
MCA.getContext());
1277+
auto *LoSym = MCSpecifierExpr::create(GP_Disp, Mips::S_LO, MCA.getContext());
12831278
TmpInst.addOperand(MCOperand::createExpr(LoSym));
12841279
getStreamer().emitInstruction(TmpInst, STI);
12851280

@@ -1342,12 +1337,12 @@ void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
13421337
emitRRI(Mips::SD, GPReg, Mips::SP, RegOrOffset, SMLoc(), &STI);
13431338
}
13441339

1345-
const MipsMCExpr *HiExpr = MipsMCExpr::createGpOff(
1346-
Mips::S_HI, MCSymbolRefExpr::create(&Sym, MCA.getContext()),
1347-
MCA.getContext());
1348-
const MipsMCExpr *LoExpr = MipsMCExpr::createGpOff(
1349-
Mips::S_LO, MCSymbolRefExpr::create(&Sym, MCA.getContext()),
1350-
MCA.getContext());
1340+
auto *HiExpr =
1341+
Mips::createGpOff(MCSymbolRefExpr::create(&Sym, MCA.getContext()),
1342+
Mips::S_HI, MCA.getContext());
1343+
auto *LoExpr =
1344+
Mips::createGpOff(MCSymbolRefExpr::create(&Sym, MCA.getContext()),
1345+
Mips::S_LO, MCA.getContext());
13511346

13521347
// lui $gp, %hi(%neg(%gp_rel(funcSym)))
13531348
emitRX(Mips::LUi, GPReg, MCOperand::createExpr(HiExpr), SMLoc(), &STI);

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
12441244
// Emit .dtprelword or .dtpreldword directive
12451245
// and value for debug thread local expression.
12461246
void MipsAsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const {
1247-
if (auto *MipsExpr = dyn_cast<MipsMCExpr>(Value)) {
1247+
if (auto *MipsExpr = dyn_cast<MCSpecifierExpr>(Value)) {
12481248
if (MipsExpr && MipsExpr->getSpecifier() == Mips::S_DTPREL) {
12491249
switch (Size) {
12501250
case 4:

0 commit comments

Comments
 (0)