Skip to content

Commit e448c3e

Browse files
committed
LoongArch: Migrate to MCAsmInfo::printExpr
1 parent 34c85ed commit e448c3e

File tree

7 files changed

+32
-24
lines changed

7 files changed

+32
-24
lines changed

llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "MCTargetDesc/LoongArchBaseInfo.h"
1010
#include "MCTargetDesc/LoongArchInstPrinter.h"
11+
#include "MCTargetDesc/LoongArchMCAsmInfo.h"
1112
#include "MCTargetDesc/LoongArchMCExpr.h"
1213
#include "MCTargetDesc/LoongArchMCTargetDesc.h"
1314
#include "MCTargetDesc/LoongArchMatInt.h"
@@ -755,7 +756,7 @@ LoongArchAsmParser::parseOperandWithModifier(OperandVector &Operands) {
755756
if (getLexer().getKind() != AsmToken::Identifier)
756757
return Error(getLoc(), "expected valid identifier for operand modifier");
757758
StringRef Identifier = getParser().getTok().getIdentifier();
758-
LoongArchMCExpr::Specifier VK = LoongArchMCExpr::parseSpecifier(Identifier);
759+
auto VK = LoongArch::parseSpecifier(Identifier);
759760
if (VK == LoongArchMCExpr::VK_None)
760761
return Error(getLoc(), "invalid relocation specifier");
761762

llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/CodeGen/AsmPrinter.h"
2121
#include "llvm/CodeGen/MachineJumpTableInfo.h"
2222
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
23+
#include "llvm/MC/MCAsmInfo.h"
2324
#include "llvm/MC/MCContext.h"
2425
#include "llvm/MC/MCInstBuilder.h"
2526
#include "llvm/MC/MCSectionELF.h"
@@ -160,9 +161,10 @@ bool LoongArchAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
160161
else if (OffsetMO.isImm())
161162
OS << ", " << OffsetMO.getImm();
162163
else if (OffsetMO.isGlobal() || OffsetMO.isBlockAddress() ||
163-
OffsetMO.isMCSymbol())
164-
OS << ", " << *MCO.getExpr();
165-
else
164+
OffsetMO.isMCSymbol()) {
165+
OS << ", ";
166+
MAI->printExpr(OS, *MCO.getExpr());
167+
} else
166168
return true;
167169

168170
return false;

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void LoongArchInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
8484
}
8585

8686
assert(MO.isExpr() && "Unknown operand kind in printOperand");
87-
MO.getExpr()->print(O, &MAI);
87+
MAI.printExpr(O, *MO.getExpr());
8888
}
8989

9090
void LoongArchInstPrinter::printAtomicMemOp(const MCInst *MI, unsigned OpNo,

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCAsmInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "LoongArchMCAsmInfo.h"
14+
#include "LoongArchMCExpr.h"
1415
#include "llvm/BinaryFormat/Dwarf.h"
16+
#include "llvm/BinaryFormat/ELF.h"
1517
#include "llvm/MC/MCStreamer.h"
1618
#include "llvm/TargetParser/Triple.h"
1719

@@ -32,3 +34,14 @@ LoongArchMCAsmInfo::LoongArchMCAsmInfo(const Triple &TT) {
3234
DwarfRegNumForCFI = true;
3335
ExceptionsType = ExceptionHandling::DwarfCFI;
3436
}
37+
38+
void LoongArchMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
39+
const MCSpecifierExpr &Expr) const {
40+
auto S = Expr.getSpecifier();
41+
bool HasSpecifier = S != 0 && S != ELF::R_LARCH_B26;
42+
if (HasSpecifier)
43+
OS << '%' << LoongArch::getSpecifierName(S) << '(';
44+
printExpr(OS, *Expr.getSubExpr());
45+
if (HasSpecifier)
46+
OS << ')';
47+
}

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCAsmInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ class LoongArchMCAsmInfo : public MCAsmInfoELF {
2323

2424
public:
2525
explicit LoongArchMCAsmInfo(const Triple &TargetTriple);
26+
void printSpecifierExpr(raw_ostream &OS,
27+
const MCSpecifierExpr &Expr) const override;
2628
};
2729

30+
namespace LoongArch {
31+
StringRef getSpecifierName(uint16_t S);
32+
uint16_t parseSpecifier(StringRef name);
33+
} // namespace LoongArch
34+
2835
} // end namespace llvm
2936

3037
#endif // LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHMCASMINFO_H

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "LoongArchMCExpr.h"
15+
#include "LoongArchMCAsmInfo.h"
1516
#include "llvm/BinaryFormat/ELF.h"
1617
#include "llvm/MC/MCContext.h"
1718
#include "llvm/MC/MCStreamer.h"
@@ -27,18 +28,7 @@ const LoongArchMCExpr *LoongArchMCExpr::create(const MCExpr *Expr, uint16_t S,
2728
return new (Ctx) LoongArchMCExpr(Expr, Specifier(S), Hint);
2829
}
2930

30-
void LoongArchMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
31-
Specifier S = getSpecifier();
32-
bool HasVariant = S != VK_None && S != ELF::R_LARCH_B26;
33-
34-
if (HasVariant)
35-
OS << '%' << getSpecifierName(specifier) << '(';
36-
Expr->print(OS, MAI);
37-
if (HasVariant)
38-
OS << ')';
39-
}
40-
41-
StringRef LoongArchMCExpr::getSpecifierName(uint16_t S) {
31+
StringRef LoongArch::getSpecifierName(uint16_t S) {
4232
switch (S) {
4333
default:
4434
llvm_unreachable("Invalid ELF symbol kind");
@@ -149,7 +139,7 @@ StringRef LoongArchMCExpr::getSpecifierName(uint16_t S) {
149139
}
150140
}
151141

152-
LoongArchMCExpr::Specifier LoongArchMCExpr::parseSpecifier(StringRef name) {
142+
LoongArchMCExpr::Specifier LoongArch::parseSpecifier(StringRef name) {
153143
return StringSwitch<LoongArchMCExpr::Specifier>(name)
154144
.Case("plt", ELF::R_LARCH_B26)
155145
.Case("b16", ELF::R_LARCH_B16)
@@ -205,5 +195,5 @@ LoongArchMCExpr::Specifier LoongArchMCExpr::parseSpecifier(StringRef name) {
205195
.Case("ld_pcrel_20", ELF::R_LARCH_TLS_LD_PCREL20_S2)
206196
.Case("gd_pcrel_20", ELF::R_LARCH_TLS_GD_PCREL20_S2)
207197
.Case("desc_pcrel_20", ELF::R_LARCH_TLS_DESC_PCREL20_S2)
208-
.Default(VK_None);
198+
.Default(0);
209199
}

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ class LoongArchMCExpr : public MCSpecifierExpr {
3636
MCContext &Ctx, bool Hint = false);
3737

3838
bool getRelaxHint() const { return RelaxHint; }
39-
40-
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
41-
42-
static StringRef getSpecifierName(uint16_t S);
43-
static Specifier parseSpecifier(StringRef name);
4439
};
4540

4641
} // end namespace llvm

0 commit comments

Comments
 (0)