Skip to content

Commit f23b841

Browse files
committed
MIPS: Move MipsMCExpr functions to MipsMCAsmInfo
1 parent 1506ba9 commit f23b841

File tree

5 files changed

+56
-25
lines changed

5 files changed

+56
-25
lines changed

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

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,19 @@ MipsCOFFMCAsmInfo::MipsCOFFMCAsmInfo() {
5959
AllowAtInName = true;
6060
}
6161

62-
void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
62+
static void printImpl(const MCAsmInfo &MAI, raw_ostream &OS,
63+
const MCSpecifierExpr &Expr) {
6364
int64_t AbsVal;
6465

65-
switch (specifier) {
66+
switch (Expr.getSpecifier()) {
6667
case Mips::S_None:
6768
case Mips::S_Special:
6869
llvm_unreachable("Mips::S_None and MEK_Special are invalid");
6970
break;
7071
case Mips::S_DTPREL:
7172
// Mips::S_DTPREL is used for marking TLS DIEExpr only
7273
// and contains a regular sub-expression.
73-
MAI->printExpr(OS, *getSubExpr());
74+
MAI.printExpr(OS, *Expr.getSubExpr());
7475
return;
7576
case Mips::S_CALL_HI16:
7677
OS << "%call_hi";
@@ -147,20 +148,20 @@ void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
147148
}
148149

149150
OS << '(';
150-
if (Expr->evaluateAsAbsolute(AbsVal))
151+
if (Expr.evaluateAsAbsolute(AbsVal))
151152
OS << AbsVal;
152153
else
153-
Expr->print(OS, MAI);
154+
MAI.printExpr(OS, *Expr.getSubExpr());
154155
OS << ')';
155156
}
156157

157-
bool MipsMCExpr::isGpOff(Specifier &S) const {
158-
if (getSpecifier() == Mips::S_HI || getSpecifier() == Mips::S_LO) {
159-
if (const MipsMCExpr *S1 = dyn_cast<const MipsMCExpr>(getSubExpr())) {
158+
bool Mips::isGpOff(const MCSpecifierExpr &E) {
159+
if (E.getSpecifier() == Mips::S_HI || E.getSpecifier() == Mips::S_LO) {
160+
if (const MipsMCExpr *S1 = dyn_cast<const MipsMCExpr>(E.getSubExpr())) {
160161
if (const MipsMCExpr *S2 = dyn_cast<const MipsMCExpr>(S1->getSubExpr())) {
161162
if (S1->getSpecifier() == Mips::S_NEG &&
162163
S2->getSpecifier() == Mips::S_GPREL) {
163-
S = getSpecifier();
164+
// S = E.getSpecifier();
164165
return true;
165166
}
166167
}
@@ -169,13 +170,13 @@ bool MipsMCExpr::isGpOff(Specifier &S) const {
169170
return false;
170171
}
171172

172-
bool MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
173-
const MCAssembler *Asm) const {
173+
static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
174+
const MCAssembler *Asm) {
174175
// Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X)))
175176
// special cases.
176-
if (isGpOff()) {
177+
if (Mips::isGpOff(Expr)) {
177178
const MCExpr *SubExpr =
178-
cast<MipsMCExpr>(cast<MipsMCExpr>(getSubExpr())->getSubExpr())
179+
cast<MipsMCExpr>(cast<MipsMCExpr>(Expr.getSubExpr())->getSubExpr())
179180
->getSubExpr();
180181
if (!SubExpr->evaluateAsRelocatable(Res, Asm))
181182
return false;
@@ -184,8 +185,29 @@ bool MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
184185
return true;
185186
}
186187

187-
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
188+
if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
188189
return false;
189-
Res.setSpecifier(specifier);
190+
Res.setSpecifier(Expr.getSpecifier());
190191
return !Res.getSubSym();
191192
}
193+
194+
void MipsELFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
195+
const MCSpecifierExpr &Expr) const {
196+
printImpl(*this, OS, Expr);
197+
}
198+
199+
bool MipsELFMCAsmInfo::evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr,
200+
MCValue &Res,
201+
const MCAssembler *Asm) const {
202+
return evaluate(Expr, Res, Asm);
203+
}
204+
205+
void MipsCOFFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
206+
const MCSpecifierExpr &Expr) const {
207+
printImpl(*this, OS, Expr);
208+
}
209+
210+
bool MipsCOFFMCAsmInfo::evaluateAsRelocatableImpl(
211+
const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
212+
return evaluate(Expr, Res, Asm);
213+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@ class MipsELFMCAsmInfo : public MCAsmInfoELF {
2727
public:
2828
explicit MipsELFMCAsmInfo(const Triple &TheTriple,
2929
const MCTargetOptions &Options);
30+
void printSpecifierExpr(raw_ostream &OS,
31+
const MCSpecifierExpr &Expr) const override;
32+
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res,
33+
const MCAssembler *Asm) const override;
3034
};
3135

3236
class MipsCOFFMCAsmInfo : public MCAsmInfoGNUCOFF {
3337
void anchor() override;
3438

3539
public:
3640
explicit MipsCOFFMCAsmInfo();
41+
void printSpecifierExpr(raw_ostream &OS,
42+
const MCSpecifierExpr &Expr) const override;
43+
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res,
44+
const MCAssembler *Asm) const override;
3745
};
3846

3947
namespace Mips {
@@ -66,6 +74,8 @@ enum {
6674
S_TPREL_LO,
6775
S_Special,
6876
};
77+
78+
bool isGpOff(const MCSpecifierExpr &E);
6979
}
7080

7181
} // namespace llvm

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
642642
break;
643643
case Mips::S_LO:
644644
// Check for %lo(%neg(%gp_rel(X)))
645-
if (MipsExpr->isGpOff())
645+
if (Mips::isGpOff(*MipsExpr))
646646
FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GPOFF_LO
647647
: Mips::fixup_Mips_GPOFF_LO;
648648
else
@@ -659,7 +659,7 @@ getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
659659
break;
660660
case Mips::S_HI:
661661
// Check for %hi(%neg(%gp_rel(X)))
662-
if (MipsExpr->isGpOff())
662+
if (Mips::isGpOff(*MipsExpr))
663663
FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GPOFF_HI
664664
: Mips::fixup_Mips_GPOFF_HI;
665665
else

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ const MipsMCExpr *MipsMCExpr::createGpOff(MipsMCExpr::Specifier S,
3737
return create(S, create(Mips::S_NEG, create(Mips::S_GPREL, Expr, Ctx), Ctx),
3838
Ctx);
3939
}
40+
41+
void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
42+
if (MAI)
43+
MAI->printExpr(OS, *this);
44+
else // llc -asm-show-inst
45+
MipsELFMCAsmInfo(Triple(), MCTargetOptions()).printExpr(OS, *this);
46+
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ class MipsMCExpr : public MCSpecifierExpr {
3131
MCContext &Ctx);
3232

3333
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
34-
bool evaluateAsRelocatableImpl(MCValue &Res,
35-
const MCAssembler *Asm) const override;
36-
37-
bool isGpOff(Specifier &S) const;
38-
bool isGpOff() const {
39-
Specifier S;
40-
return isGpOff(S);
41-
}
4234
};
4335

4436
} // end namespace llvm

0 commit comments

Comments
 (0)