Skip to content

Commit a4976ca

Browse files
committed
Move Hexagon-specific MCSymbolRefExpr::VariantKind to HexagonMCExpr
In the future, should try storing the relocation operator in MCTargetExpr and refactor the ELF writer to use MCValue::RefKind, similar to AArch64MCExpr. Also add a MCSymbolRefExpr::create overload that takes an uint16_t argument to help port code.
1 parent b034905 commit a4976ca

File tree

9 files changed

+155
-134
lines changed

9 files changed

+155
-134
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,6 @@ class MCSymbolRefExpr : public MCExpr {
249249

250250
VK_COFF_IMGREL32, // symbol@imgrel (image-relative)
251251

252-
VK_Hexagon_LO16,
253-
VK_Hexagon_HI16,
254-
VK_Hexagon_GPREL,
255-
VK_Hexagon_GD_GOT,
256-
VK_Hexagon_LD_GOT,
257-
VK_Hexagon_GD_PLT,
258-
VK_Hexagon_LD_PLT,
259-
VK_Hexagon_IE,
260-
VK_Hexagon_IE_GOT,
261-
262252
VK_WASM_TYPEINDEX, // Reference to a symbol's type (signature)
263253
VK_WASM_TLSREL, // Memory address relative to __tls_base
264254
VK_WASM_MBREL, // Memory address relative to __memory_base
@@ -310,6 +300,10 @@ class MCSymbolRefExpr : public MCExpr {
310300

311301
static const MCSymbolRefExpr *create(const MCSymbol *Symbol, VariantKind Kind,
312302
MCContext &Ctx, SMLoc Loc = SMLoc());
303+
static const MCSymbolRefExpr *create(const MCSymbol *Symbol, uint16_t Kind,
304+
MCContext &Ctx, SMLoc Loc = SMLoc()) {
305+
return MCSymbolRefExpr::create(Symbol, VariantKind(Kind), Ctx, Loc);
306+
}
313307

314308
/// @}
315309
/// \name Accessors

llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,9 @@ bool HexagonAsmParser::parseInstruction(OperandVector &Operands) {
12491249
MCValue Value;
12501250
if (Expr->evaluateAsRelocatable(Value, nullptr, nullptr)) {
12511251
if (!Value.isAbsolute()) {
1252-
switch (Value.getAccessVariant()) {
1253-
case MCSymbolRefExpr::VariantKind::VK_TPREL:
1254-
case MCSymbolRefExpr::VariantKind::VK_DTPREL:
1252+
switch (HexagonMCExpr::VariantKind(Value.getAccessVariant())) {
1253+
case HexagonMCExpr::VK_TPREL:
1254+
case HexagonMCExpr::VK_DTPREL:
12551255
// Don't lazy extend these expression variants
12561256
MustNotExtend = !MustExtend;
12571257
break;

llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,40 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
4444

4545
// Populate the relocation type based on Hexagon target flags
4646
// set on an operand
47-
MCSymbolRefExpr::VariantKind RelocationType;
47+
HexagonMCExpr::VariantKind RelocationType;
4848
switch (MO.getTargetFlags() & ~HexagonII::HMOTF_ConstExtended) {
4949
default:
50-
RelocationType = MCSymbolRefExpr::VK_None;
50+
RelocationType = HexagonMCExpr::VK_None;
5151
break;
5252
case HexagonII::MO_PCREL:
53-
RelocationType = MCSymbolRefExpr::VK_PCREL;
53+
RelocationType = HexagonMCExpr::VK_PCREL;
5454
break;
5555
case HexagonII::MO_GOT:
56-
RelocationType = MCSymbolRefExpr::VK_GOT;
56+
RelocationType = HexagonMCExpr::VK_GOT;
5757
break;
5858
case HexagonII::MO_LO16:
59-
RelocationType = MCSymbolRefExpr::VK_Hexagon_LO16;
59+
RelocationType = HexagonMCExpr::VK_LO16;
6060
break;
6161
case HexagonII::MO_HI16:
62-
RelocationType = MCSymbolRefExpr::VK_Hexagon_HI16;
62+
RelocationType = HexagonMCExpr::VK_HI16;
6363
break;
6464
case HexagonII::MO_GPREL:
65-
RelocationType = MCSymbolRefExpr::VK_Hexagon_GPREL;
65+
RelocationType = HexagonMCExpr::VK_GPREL;
6666
break;
6767
case HexagonII::MO_GDGOT:
68-
RelocationType = MCSymbolRefExpr::VK_Hexagon_GD_GOT;
68+
RelocationType = HexagonMCExpr::VK_GD_GOT;
6969
break;
7070
case HexagonII::MO_GDPLT:
71-
RelocationType = MCSymbolRefExpr::VK_Hexagon_GD_PLT;
71+
RelocationType = HexagonMCExpr::VK_GD_PLT;
7272
break;
7373
case HexagonII::MO_IE:
74-
RelocationType = MCSymbolRefExpr::VK_Hexagon_IE;
74+
RelocationType = HexagonMCExpr::VK_IE;
7575
break;
7676
case HexagonII::MO_IEGOT:
77-
RelocationType = MCSymbolRefExpr::VK_Hexagon_IE_GOT;
77+
RelocationType = HexagonMCExpr::VK_IE_GOT;
7878
break;
7979
case HexagonII::MO_TPREL:
80-
RelocationType = MCSymbolRefExpr::VK_TPREL;
80+
RelocationType = HexagonMCExpr::VK_TPREL;
8181
break;
8282
}
8383

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp

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

99
#include "MCTargetDesc/HexagonFixupKinds.h"
10+
#include "MCTargetDesc/HexagonMCExpr.h"
1011
#include "MCTargetDesc/HexagonMCTargetDesc.h"
1112
#include "llvm/MC/MCAssembler.h"
1213
#include "llvm/MC/MCELFObjectWriter.h"
@@ -41,32 +42,32 @@ unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
4142
MCValue const &Target,
4243
MCFixup const &Fixup,
4344
bool IsPCRel) const {
44-
MCSymbolRefExpr::VariantKind Variant = Target.getAccessVariant();
45+
auto Variant = HexagonMCExpr::VariantKind(Target.getAccessVariant());
4546
switch (Fixup.getTargetKind()) {
4647
default:
4748
report_fatal_error("Unrecognized relocation type");
4849
break;
4950
case FK_Data_4:
50-
switch(Variant) {
51-
case MCSymbolRefExpr::VariantKind::VK_DTPREL:
51+
switch (Variant) {
52+
case HexagonMCExpr::VK_DTPREL:
5253
return ELF::R_HEX_DTPREL_32;
53-
case MCSymbolRefExpr::VariantKind::VK_GOT:
54+
case HexagonMCExpr::VK_GOT:
5455
return ELF::R_HEX_GOT_32;
55-
case MCSymbolRefExpr::VariantKind::VK_GOTREL:
56+
case HexagonMCExpr::VK_GOTREL:
5657
return ELF::R_HEX_GOTREL_32;
57-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
58+
case HexagonMCExpr::VK_GD_GOT:
5859
return ELF::R_HEX_GD_GOT_32;
59-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE:
60+
case HexagonMCExpr::VK_IE:
6061
return ELF::R_HEX_IE_32;
61-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
62+
case HexagonMCExpr::VK_IE_GOT:
6263
return ELF::R_HEX_IE_GOT_32;
63-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
64+
case HexagonMCExpr::VK_LD_GOT:
6465
return ELF::R_HEX_LD_GOT_32;
65-
case MCSymbolRefExpr::VariantKind::VK_PCREL:
66+
case HexagonMCExpr::VK_PCREL:
6667
return ELF::R_HEX_32_PCREL;
67-
case MCSymbolRefExpr::VariantKind::VK_TPREL:
68+
case HexagonMCExpr::VK_TPREL:
6869
return ELF::R_HEX_TPREL_32;
69-
case MCSymbolRefExpr::VariantKind::VK_None:
70+
case HexagonMCExpr::VK_None:
7071
return IsPCRel ? ELF::R_HEX_32_PCREL : ELF::R_HEX_32;
7172
default:
7273
report_fatal_error("Unrecognized variant type");
@@ -75,19 +76,19 @@ unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
7576
return ELF::R_HEX_32_PCREL;
7677
case FK_Data_2:
7778
switch(Variant) {
78-
case MCSymbolRefExpr::VariantKind::VK_DTPREL:
79+
case HexagonMCExpr::VK_DTPREL:
7980
return ELF::R_HEX_DTPREL_16;
80-
case MCSymbolRefExpr::VariantKind::VK_GOT:
81+
case HexagonMCExpr::VK_GOT:
8182
return ELF::R_HEX_GOT_16;
82-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
83+
case HexagonMCExpr::VK_GD_GOT:
8384
return ELF::R_HEX_GD_GOT_16;
84-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
85+
case HexagonMCExpr::VK_IE_GOT:
8586
return ELF::R_HEX_IE_GOT_16;
86-
case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
87+
case HexagonMCExpr::VK_LD_GOT:
8788
return ELF::R_HEX_LD_GOT_16;
88-
case MCSymbolRefExpr::VariantKind::VK_TPREL:
89+
case HexagonMCExpr::VK_TPREL:
8990
return ELF::R_HEX_TPREL_16;
90-
case MCSymbolRefExpr::VariantKind::VK_None:
91+
case HexagonMCExpr::VK_None:
9192
return ELF::R_HEX_16;
9293
default:
9394
report_fatal_error("Unrecognized variant type");

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "HexagonMCAsmInfo.h"
14+
#include "MCTargetDesc/HexagonMCExpr.h"
1415
#include "llvm/MC/MCExpr.h"
1516

1617
using namespace llvm;
1718

1819
const MCAsmInfo::VariantKindDesc variantKindDescs[] = {
19-
{MCSymbolRefExpr::VK_DTPREL, "DTPREL"},
20-
{MCSymbolRefExpr::VK_Hexagon_GD_GOT, "GDGOT"},
21-
{MCSymbolRefExpr::VK_Hexagon_GD_PLT, "GDPLT"},
22-
{MCSymbolRefExpr::VK_GOT, "GOT"},
23-
{MCSymbolRefExpr::VK_GOTREL, "GOTREL"},
24-
{MCSymbolRefExpr::VK_Hexagon_IE, "IE"},
25-
{MCSymbolRefExpr::VK_Hexagon_IE_GOT, "IEGOT"},
26-
{MCSymbolRefExpr::VK_Hexagon_LD_GOT, "LDGOT"},
27-
{MCSymbolRefExpr::VK_Hexagon_LD_PLT, "LDPLT"},
28-
{MCSymbolRefExpr::VK_PCREL, "PCREL"},
29-
{MCSymbolRefExpr::VK_PLT, "PLT"},
30-
{MCSymbolRefExpr::VK_TPREL, "TPREL"},
20+
{HexagonMCExpr::VK_DTPREL, "DTPREL"}, {HexagonMCExpr::VK_GD_GOT, "GDGOT"},
21+
{HexagonMCExpr::VK_GD_PLT, "GDPLT"}, {HexagonMCExpr::VK_GOT, "GOT"},
22+
{HexagonMCExpr::VK_GOTREL, "GOTREL"}, {HexagonMCExpr::VK_IE, "IE"},
23+
{HexagonMCExpr::VK_IE_GOT, "IEGOT"}, {HexagonMCExpr::VK_LD_GOT, "LDGOT"},
24+
{HexagonMCExpr::VK_LD_PLT, "LDPLT"}, {HexagonMCExpr::VK_PCREL, "PCREL"},
25+
{HexagonMCExpr::VK_PLT, "PLT"}, {HexagonMCExpr::VK_TPREL, "TPREL"},
3126
};
3227

3328
// Pin the vtable to this file.

0 commit comments

Comments
 (0)