Skip to content

Commit 2ed0401

Browse files
committed
CSKY: Migrate to the new relocation specifier representation
Use MCSpecifierExpr directly and remove the CSKYMCExpr subclass. Define printImpl within CSKYMCAsmInfo.
1 parent f771d08 commit 2ed0401

14 files changed

+174
-260
lines changed

llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "MCTargetDesc/CSKYInstPrinter.h"
1010
#include "MCTargetDesc/CSKYMCAsmInfo.h"
11-
#include "MCTargetDesc/CSKYMCExpr.h"
1211
#include "MCTargetDesc/CSKYMCTargetDesc.h"
1312
#include "MCTargetDesc/CSKYTargetStreamer.h"
1413
#include "TargetInfo/CSKYTargetInfo.h"
@@ -849,11 +848,11 @@ bool CSKYAsmParser::processLRW(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out) {
849848
}
850849
} else {
851850
const MCExpr *AdjustExpr = nullptr;
852-
if (const CSKYMCExpr *CSKYExpr =
853-
dyn_cast<CSKYMCExpr>(Inst.getOperand(1).getExpr())) {
854-
if (CSKYExpr->getSpecifier() == CSKYMCExpr::VK_TLSGD ||
855-
CSKYExpr->getSpecifier() == CSKYMCExpr::VK_TLSIE ||
856-
CSKYExpr->getSpecifier() == CSKYMCExpr::VK_TLSLDM) {
851+
if (const auto *CSKYExpr =
852+
dyn_cast<MCSpecifierExpr>(Inst.getOperand(1).getExpr())) {
853+
if (CSKYExpr->getSpecifier() == CSKY::S_TLSGD ||
854+
CSKYExpr->getSpecifier() == CSKY::S_TLSIE ||
855+
CSKYExpr->getSpecifier() == CSKY::S_TLSLDM) {
857856
MCSymbol *Dot = getContext().createNamedTempSymbol();
858857
Out.emitLabel(Dot);
859858
AdjustExpr = MCSymbolRefExpr::create(Dot, getContext());
@@ -1173,25 +1172,25 @@ ParseStatus CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
11731172
if (getParser().parseIdentifier(Identifier))
11741173
return Error(getLoc(), "unknown identifier");
11751174

1176-
CSKYMCExpr::Specifier Kind = CSKYMCExpr::VK_None;
1175+
CSKY::Specifier Kind = CSKY::S_None;
11771176
if (Identifier.consume_back("@GOT"))
1178-
Kind = CSKYMCExpr::VK_GOT;
1177+
Kind = CSKY::S_GOT;
11791178
else if (Identifier.consume_back("@GOTOFF"))
1180-
Kind = CSKYMCExpr::VK_GOTOFF;
1179+
Kind = CSKY::S_GOTOFF;
11811180
else if (Identifier.consume_back("@PLT"))
1182-
Kind = CSKYMCExpr::VK_PLT;
1181+
Kind = CSKY::S_PLT;
11831182
else if (Identifier.consume_back("@GOTPC"))
1184-
Kind = CSKYMCExpr::VK_GOTPC;
1183+
Kind = CSKY::S_GOTPC;
11851184
else if (Identifier.consume_back("@TLSGD32"))
1186-
Kind = CSKYMCExpr::VK_TLSGD;
1185+
Kind = CSKY::S_TLSGD;
11871186
else if (Identifier.consume_back("@GOTTPOFF"))
1188-
Kind = CSKYMCExpr::VK_TLSIE;
1187+
Kind = CSKY::S_TLSIE;
11891188
else if (Identifier.consume_back("@TPOFF"))
1190-
Kind = CSKYMCExpr::VK_TLSLE;
1189+
Kind = CSKY::S_TLSLE;
11911190
else if (Identifier.consume_back("@TLSLDM32"))
1192-
Kind = CSKYMCExpr::VK_TLSLDM;
1191+
Kind = CSKY::S_TLSLDM;
11931192
else if (Identifier.consume_back("@TLSLDO32"))
1194-
Kind = CSKYMCExpr::VK_TLSLDO;
1193+
Kind = CSKY::S_TLSLDO;
11951194

11961195
MCSymbol *Sym = getContext().getInlineAsmLabel(Identifier);
11971196

@@ -1211,8 +1210,8 @@ ParseStatus CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
12111210
MCBinaryExpr::Opcode Opcode;
12121211
switch (getLexer().getKind()) {
12131212
default:
1214-
if (Kind != CSKYMCExpr::VK_None)
1215-
Res = CSKYMCExpr::create(Res, Kind, getContext());
1213+
if (Kind != CSKY::S_None)
1214+
Res = MCSpecifierExpr::create(Res, Kind, getContext());
12161215

12171216
Operands.push_back(CSKYOperand::createImm(Res, S, E));
12181217
return ParseStatus::Success;
@@ -1259,11 +1258,11 @@ ParseStatus CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
12591258
if (getParser().parseIdentifier(Identifier))
12601259
return Error(getLoc(), "unknown identifier " + Identifier);
12611260

1262-
CSKYMCExpr::Specifier Kind = CSKYMCExpr::VK_None;
1261+
CSKY::Specifier Kind = CSKY::S_None;
12631262
if (Identifier.consume_back("@GOT"))
1264-
Kind = CSKYMCExpr::VK_GOT_IMM18_BY4;
1263+
Kind = CSKY::S_GOT_IMM18_BY4;
12651264
else if (Identifier.consume_back("@PLT"))
1266-
Kind = CSKYMCExpr::VK_PLT_IMM18_BY4;
1265+
Kind = CSKY::S_PLT_IMM18_BY4;
12671266

12681267
MCSymbol *Sym = getContext().getInlineAsmLabel(Identifier);
12691268

@@ -1289,8 +1288,8 @@ ParseStatus CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
12891288

12901289
getLexer().Lex(); // Eat ']'.
12911290

1292-
if (Kind != CSKYMCExpr::VK_None)
1293-
Res = CSKYMCExpr::create(Res, Kind, getContext());
1291+
if (Kind != CSKY::S_None)
1292+
Res = MCSpecifierExpr::create(Res, Kind, getContext());
12941293

12951294
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
12961295
return ParseStatus::Success;

llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "CSKYConstantPoolValue.h"
1616
#include "CSKYTargetMachine.h"
1717
#include "MCTargetDesc/CSKYInstPrinter.h"
18-
#include "MCTargetDesc/CSKYMCExpr.h"
18+
#include "MCTargetDesc/CSKYMCAsmInfo.h"
1919
#include "MCTargetDesc/CSKYTargetStreamer.h"
2020
#include "TargetInfo/CSKYTargetInfo.h"
2121
#include "llvm/ADT/Statistic.h"
@@ -168,25 +168,24 @@ void CSKYAsmPrinter::emitInstruction(const MachineInstr *MI) {
168168

169169
// Convert a CSKY-specific constant pool modifier into the associated
170170
// MCSymbolRefExpr variant kind.
171-
static CSKYMCExpr::Specifier
172-
getModifierVariantKind(CSKYCP::CSKYCPModifier Modifier) {
171+
static CSKY::Specifier getModifierVariantKind(CSKYCP::CSKYCPModifier Modifier) {
173172
switch (Modifier) {
174173
case CSKYCP::NO_MOD:
175-
return CSKYMCExpr::VK_None;
174+
return CSKY::S_None;
176175
case CSKYCP::ADDR:
177-
return CSKYMCExpr::VK_ADDR;
176+
return CSKY::S_ADDR;
178177
case CSKYCP::GOT:
179-
return CSKYMCExpr::VK_GOT;
178+
return CSKY::S_GOT;
180179
case CSKYCP::GOTOFF:
181-
return CSKYMCExpr::VK_GOTOFF;
180+
return CSKY::S_GOTOFF;
182181
case CSKYCP::PLT:
183-
return CSKYMCExpr::VK_PLT;
182+
return CSKY::S_PLT;
184183
case CSKYCP::TLSGD:
185-
return CSKYMCExpr::VK_TLSGD;
184+
return CSKY::S_TLSGD;
186185
case CSKYCP::TLSLE:
187-
return CSKYMCExpr::VK_TLSLE;
186+
return CSKY::S_TLSLE;
188187
case CSKYCP::TLSIE:
189-
return CSKYMCExpr::VK_TLSIE;
188+
return CSKY::S_TLSIE;
190189
}
191190
llvm_unreachable("Invalid CSKYCPModifier!");
192191
}
@@ -240,8 +239,8 @@ void CSKYAsmPrinter::emitMachineConstantPoolValue(
240239
}
241240

242241
// Create an MCSymbol for the reference.
243-
Expr = CSKYMCExpr::create(Expr, getModifierVariantKind(CCPV->getModifier()),
244-
OutContext);
242+
Expr = MCSpecifierExpr::create(
243+
Expr, getModifierVariantKind(CCPV->getModifier()), OutContext);
245244

246245
OutStreamer->emitValue(Expr, Size);
247246
}

llvm/lib/Target/CSKY/CSKYMCInstLower.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "CSKYMCInstLower.h"
1515
#include "MCTargetDesc/CSKYBaseInfo.h"
16-
#include "MCTargetDesc/CSKYMCExpr.h"
16+
#include "MCTargetDesc/CSKYMCAsmInfo.h"
1717
#include "llvm/CodeGen/AsmPrinter.h"
1818
#include "llvm/MC/MCExpr.h"
1919

@@ -36,38 +36,38 @@ void CSKYMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
3636

3737
MCOperand CSKYMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
3838
MCSymbol *Sym) const {
39-
CSKYMCExpr::Specifier Spec;
39+
CSKY::Specifier Spec;
4040
MCContext &Ctx = Printer.OutContext;
4141

4242
switch (MO.getTargetFlags()) {
4343
default:
4444
llvm_unreachable("Unknown target flag.");
4545
case CSKYII::MO_None:
46-
Spec = CSKYMCExpr::VK_None;
46+
Spec = CSKY::S_None;
4747
break;
4848
case CSKYII::MO_GOT32:
49-
Spec = CSKYMCExpr::VK_GOT;
49+
Spec = CSKY::S_GOT;
5050
break;
5151
case CSKYII::MO_GOTOFF:
52-
Spec = CSKYMCExpr::VK_GOTOFF;
52+
Spec = CSKY::S_GOTOFF;
5353
break;
5454
case CSKYII::MO_ADDR32:
55-
Spec = CSKYMCExpr::VK_ADDR;
55+
Spec = CSKY::S_ADDR;
5656
break;
5757
case CSKYII::MO_PLT32:
58-
Spec = CSKYMCExpr::VK_PLT;
58+
Spec = CSKY::S_PLT;
5959
break;
6060
case CSKYII::MO_ADDR_HI16:
61-
Spec = CSKYMCExpr::VK_ADDR_HI16;
61+
Spec = CSKY::S_ADDR_HI16;
6262
break;
6363
case CSKYII::MO_ADDR_LO16:
64-
Spec = CSKYMCExpr::VK_ADDR_LO16;
64+
Spec = CSKY::S_ADDR_LO16;
6565
break;
6666
}
6767
const MCExpr *ME = MCSymbolRefExpr::create(Sym, Ctx);
6868

69-
if (Spec != CSKYMCExpr::VK_None)
70-
ME = CSKYMCExpr::create(ME, Spec, Ctx);
69+
if (Spec != CSKY::S_None)
70+
ME = MCSpecifierExpr::create(ME, Spec, Ctx);
7171

7272
return MCOperand::createExpr(ME);
7373
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ add_llvm_component_library(LLVMCSKYDesc
44
CSKYELFStreamer.cpp
55
CSKYInstPrinter.cpp
66
CSKYMCAsmInfo.cpp
7-
CSKYMCExpr.cpp
87
CSKYMCTargetDesc.cpp
98
CSKYMCCodeEmitter.cpp
109
CSKYTargetStreamer.cpp

llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "CSKYFixupKinds.h"
10-
#include "CSKYMCExpr.h"
10+
#include "CSKYMCAsmInfo.h"
1111
#include "CSKYMCTargetDesc.h"
12-
#include "MCTargetDesc/CSKYMCExpr.h"
12+
#include "MCTargetDesc/CSKYMCAsmInfo.h"
1313
#include "llvm/MC/MCContext.h"
1414
#include "llvm/MC/MCELFObjectWriter.h"
1515
#include "llvm/MC/MCObjectWriter.h"
@@ -43,11 +43,11 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
4343
uint8_t Modifier = Target.getSpecifier();
4444

4545
switch (Target.getSpecifier()) {
46-
case CSKYMCExpr::VK_TLSIE:
47-
case CSKYMCExpr::VK_TLSLE:
48-
case CSKYMCExpr::VK_TLSGD:
49-
case CSKYMCExpr::VK_TLSLDM:
50-
case CSKYMCExpr::VK_TLSLDO:
46+
case CSKY::S_TLSIE:
47+
case CSKY::S_TLSLE:
48+
case CSKY::S_TLSGD:
49+
case CSKY::S_TLSLDM:
50+
case CSKY::S_TLSLDO:
5151
if (auto *SA = Target.getAddSym())
5252
cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
5353
break;
@@ -93,29 +93,29 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
9393
reportError(Fixup.getLoc(), "2-byte data relocations not supported");
9494
return ELF::R_CKCORE_NONE;
9595
case FK_Data_4:
96-
if (Expr->getKind() == MCExpr::Target) {
97-
auto TK = cast<CSKYMCExpr>(Expr)->getSpecifier();
98-
if (TK == CSKYMCExpr::VK_ADDR)
96+
if (Expr->getKind() == MCExpr::Specifier) {
97+
auto TK = cast<MCSpecifierExpr>(Expr)->getSpecifier();
98+
if (TK == CSKY::S_ADDR)
9999
return ELF::R_CKCORE_ADDR32;
100-
if (TK == CSKYMCExpr::VK_GOT)
100+
if (TK == CSKY::S_GOT)
101101
return ELF::R_CKCORE_GOT32;
102-
if (TK == CSKYMCExpr::VK_GOTOFF)
102+
if (TK == CSKY::S_GOTOFF)
103103
return ELF::R_CKCORE_GOTOFF;
104-
if (TK == CSKYMCExpr::VK_PLT)
104+
if (TK == CSKY::S_PLT)
105105
return ELF::R_CKCORE_PLT32;
106-
if (TK == CSKYMCExpr::VK_TLSIE)
106+
if (TK == CSKY::S_TLSIE)
107107
return ELF::R_CKCORE_TLS_IE32;
108-
if (TK == CSKYMCExpr::VK_TLSLE)
108+
if (TK == CSKY::S_TLSLE)
109109
return ELF::R_CKCORE_TLS_LE32;
110-
if (TK == CSKYMCExpr::VK_TLSGD)
110+
if (TK == CSKY::S_TLSGD)
111111
return ELF::R_CKCORE_TLS_GD32;
112-
if (TK == CSKYMCExpr::VK_TLSLDM)
112+
if (TK == CSKY::S_TLSLDM)
113113
return ELF::R_CKCORE_TLS_LDM32;
114-
if (TK == CSKYMCExpr::VK_TLSLDO)
114+
if (TK == CSKY::S_TLSLDO)
115115
return ELF::R_CKCORE_TLS_LDO32;
116-
if (TK == CSKYMCExpr::VK_GOTPC)
116+
if (TK == CSKY::S_GOTPC)
117117
return ELF::R_CKCORE_GOTPC;
118-
if (TK == CSKYMCExpr::VK_None)
118+
if (TK == CSKY::S_None)
119119
return ELF::R_CKCORE_ADDR32;
120120

121121
LLVM_DEBUG(dbgs() << "Unknown FK_Data_4 TK = " << TK);
@@ -125,19 +125,19 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
125125
default:
126126
reportError(Fixup.getLoc(), "invalid fixup for 4-byte data relocation");
127127
return ELF::R_CKCORE_NONE;
128-
case CSKYMCExpr::VK_GOT:
128+
case CSKY::S_GOT:
129129
return ELF::R_CKCORE_GOT32;
130-
case CSKYMCExpr::VK_GOTOFF:
130+
case CSKY::S_GOTOFF:
131131
return ELF::R_CKCORE_GOTOFF;
132-
case CSKYMCExpr::VK_PLT:
132+
case CSKY::S_PLT:
133133
return ELF::R_CKCORE_PLT32;
134-
case CSKYMCExpr::VK_TLSGD:
134+
case CSKY::S_TLSGD:
135135
return ELF::R_CKCORE_TLS_GD32;
136-
case CSKYMCExpr::VK_TLSLDM:
136+
case CSKY::S_TLSLDM:
137137
return ELF::R_CKCORE_TLS_LDM32;
138-
case CSKYMCExpr::VK_TPOFF:
138+
case CSKY::S_TPOFF:
139139
return ELF::R_CKCORE_TLS_LE32;
140-
case CSKYMCExpr::VK_None:
140+
case CSKY::S_None:
141141
return ELF::R_CKCORE_ADDR32;
142142
}
143143
}
@@ -167,8 +167,8 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
167167
bool CSKYELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
168168
unsigned Type) const {
169169
switch (V.getSpecifier()) {
170-
case CSKYMCExpr::VK_PLT:
171-
case CSKYMCExpr::VK_GOT:
170+
case CSKY::S_PLT:
171+
case CSKY::S_GOT:
172172
return true;
173173
default:
174174
return false;

llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212
#include "CSKYInstPrinter.h"
1313
#include "MCTargetDesc/CSKYBaseInfo.h"
14-
#include "MCTargetDesc/CSKYMCExpr.h"
14+
#include "MCTargetDesc/CSKYMCAsmInfo.h"
1515
#include "llvm/ADT/STLExtras.h"
1616
#include "llvm/ADT/StringExtras.h"
1717
#include "llvm/MC/MCAsmInfo.h"

0 commit comments

Comments
 (0)