Skip to content

Commit 944424f

Browse files
MaskRaySchrodingerZhu
authored andcommitted
Move relocation specifiers to AMDGPUMCExpr::Specifier
Similar to previous migration done for all other ELF targets. Switch from the confusing `VariantKind` to `Specifier`, which aligns with Arm and IBM AIX's documentation. Moving forward, relocation specifiers should be integrated into AMDGPUMCExpr rather than MCSymbolRefExpr::SubclassData. (Note: the term AMDGPUMCExpr::VariantKind is for expressions without relocation specifiers: llvm#82022 It's up to AMDGPU maintainers to integrate these constants into Specifier. ) Pull Request: llvm#133608
1 parent 78a60db commit 944424f

File tree

8 files changed

+52
-40
lines changed

8 files changed

+52
-40
lines changed

Diff for: llvm/include/llvm/MC/MCExpr.h

-8
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,6 @@ class MCSymbolRefExpr : public MCExpr {
218218
VK_WASM_GOT_TLS, // Wasm global index of TLS symbol.
219219
VK_WASM_FUNCINDEX, // Wasm function index.
220220

221-
VK_AMDGPU_GOTPCREL32_LO, // symbol@gotpcrel32@lo
222-
VK_AMDGPU_GOTPCREL32_HI, // symbol@gotpcrel32@hi
223-
VK_AMDGPU_REL32_LO, // symbol@rel32@lo
224-
VK_AMDGPU_REL32_HI, // symbol@rel32@hi
225-
VK_AMDGPU_REL64, // symbol@rel64
226-
VK_AMDGPU_ABS32_LO, // symbol@abs32@lo
227-
VK_AMDGPU_ABS32_HI, // symbol@abs32@hi
228-
229221
FirstTargetSpecifier,
230222
};
231223

Diff for: llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "AMDGPUAsmPrinter.h"
1818
#include "AMDGPUMachineFunction.h"
1919
#include "MCTargetDesc/AMDGPUInstPrinter.h"
20+
#include "MCTargetDesc/AMDGPUMCExpr.h"
2021
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
2122
#include "llvm/CodeGen/MachineBasicBlock.h"
2223
#include "llvm/CodeGen/MachineInstr.h"
@@ -43,24 +44,24 @@ AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx,
4344
const AsmPrinter &ap):
4445
Ctx(ctx), ST(st), AP(ap) { }
4546

46-
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned MOFlags) {
47+
static AMDGPUMCExpr::Specifier getSpecifier(unsigned MOFlags) {
4748
switch (MOFlags) {
4849
default:
49-
return MCSymbolRefExpr::VK_None;
50+
return AMDGPUMCExpr::S_None;
5051
case SIInstrInfo::MO_GOTPCREL:
51-
return MCSymbolRefExpr::VK_GOTPCREL;
52+
return AMDGPUMCExpr::S_GOTPCREL;
5253
case SIInstrInfo::MO_GOTPCREL32_LO:
53-
return MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_LO;
54+
return AMDGPUMCExpr::S_GOTPCREL32_LO;
5455
case SIInstrInfo::MO_GOTPCREL32_HI:
55-
return MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_HI;
56+
return AMDGPUMCExpr::S_GOTPCREL32_HI;
5657
case SIInstrInfo::MO_REL32_LO:
57-
return MCSymbolRefExpr::VK_AMDGPU_REL32_LO;
58+
return AMDGPUMCExpr::S_REL32_LO;
5859
case SIInstrInfo::MO_REL32_HI:
59-
return MCSymbolRefExpr::VK_AMDGPU_REL32_HI;
60+
return AMDGPUMCExpr::S_REL32_HI;
6061
case SIInstrInfo::MO_ABS32_LO:
61-
return MCSymbolRefExpr::VK_AMDGPU_ABS32_LO;
62+
return AMDGPUMCExpr::S_ABS32_LO;
6263
case SIInstrInfo::MO_ABS32_HI:
63-
return MCSymbolRefExpr::VK_AMDGPU_ABS32_HI;
64+
return AMDGPUMCExpr::S_ABS32_HI;
6465
}
6566
}
6667

@@ -85,7 +86,7 @@ bool AMDGPUMCInstLower::lowerOperand(const MachineOperand &MO,
8586
AP.getNameWithPrefix(SymbolName, GV);
8687
MCSymbol *Sym = Ctx.getOrCreateSymbol(SymbolName);
8788
const MCExpr *Expr =
88-
MCSymbolRefExpr::create(Sym, getVariantKind(MO.getTargetFlags()),Ctx);
89+
MCSymbolRefExpr::create(Sym, getSpecifier(MO.getTargetFlags()), Ctx);
8990
int64_t Offset = MO.getOffset();
9091
if (Offset != 0) {
9192
Expr = MCBinaryExpr::createAdd(Expr,

Diff for: llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "AMDGPUFixupKinds.h"
1010
#include "AMDGPUMCTargetDesc.h"
11+
#include "MCTargetDesc/AMDGPUMCExpr.h"
1112
#include "llvm/MC/MCContext.h"
1213
#include "llvm/MC/MCELFObjectWriter.h"
1314
#include "llvm/MC/MCValue.h"
@@ -45,24 +46,24 @@ unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx,
4546
return ELF::R_AMDGPU_ABS32_LO;
4647
}
4748

48-
switch (Target.getAccessVariant()) {
49+
switch (AMDGPUMCExpr::Specifier(Target.getAccessVariant())) {
4950
default:
5051
break;
51-
case MCSymbolRefExpr::VK_GOTPCREL:
52+
case AMDGPUMCExpr::S_GOTPCREL:
5253
return ELF::R_AMDGPU_GOTPCREL;
53-
case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_LO:
54+
case AMDGPUMCExpr::S_GOTPCREL32_LO:
5455
return ELF::R_AMDGPU_GOTPCREL32_LO;
55-
case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_HI:
56+
case AMDGPUMCExpr::S_GOTPCREL32_HI:
5657
return ELF::R_AMDGPU_GOTPCREL32_HI;
57-
case MCSymbolRefExpr::VK_AMDGPU_REL32_LO:
58+
case AMDGPUMCExpr::S_REL32_LO:
5859
return ELF::R_AMDGPU_REL32_LO;
59-
case MCSymbolRefExpr::VK_AMDGPU_REL32_HI:
60+
case AMDGPUMCExpr::S_REL32_HI:
6061
return ELF::R_AMDGPU_REL32_HI;
61-
case MCSymbolRefExpr::VK_AMDGPU_REL64:
62+
case AMDGPUMCExpr::S_REL64:
6263
return ELF::R_AMDGPU_REL64;
63-
case MCSymbolRefExpr::VK_AMDGPU_ABS32_LO:
64+
case AMDGPUMCExpr::S_ABS32_LO:
6465
return ELF::R_AMDGPU_ABS32_LO;
65-
case MCSymbolRefExpr::VK_AMDGPU_ABS32_HI:
66+
case AMDGPUMCExpr::S_ABS32_HI:
6667
return ELF::R_AMDGPU_ABS32_HI;
6768
}
6869

Diff for: llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "AMDGPUMCAsmInfo.h"
11+
#include "MCTargetDesc/AMDGPUMCExpr.h"
1112
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
1213
#include "llvm/MC/MCExpr.h"
1314
#include "llvm/MC/MCSubtargetInfo.h"
@@ -16,14 +17,14 @@
1617
using namespace llvm;
1718

1819
const MCAsmInfo::VariantKindDesc variantKindDescs[] = {
19-
{MCSymbolRefExpr::VK_GOTPCREL, "gotpcrel"},
20-
{MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_LO, "gotpcrel32@lo"},
21-
{MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_HI, "gotpcrel32@hi"},
22-
{MCSymbolRefExpr::VK_AMDGPU_REL32_LO, "rel32@lo"},
23-
{MCSymbolRefExpr::VK_AMDGPU_REL32_HI, "rel32@hi"},
24-
{MCSymbolRefExpr::VK_AMDGPU_REL64, "rel64"},
25-
{MCSymbolRefExpr::VK_AMDGPU_ABS32_LO, "abs32@lo"},
26-
{MCSymbolRefExpr::VK_AMDGPU_ABS32_HI, "abs32@hi"},
20+
{AMDGPUMCExpr::S_GOTPCREL, "gotpcrel"},
21+
{AMDGPUMCExpr::S_GOTPCREL32_LO, "gotpcrel32@lo"},
22+
{AMDGPUMCExpr::S_GOTPCREL32_HI, "gotpcrel32@hi"},
23+
{AMDGPUMCExpr::S_REL32_LO, "rel32@lo"},
24+
{AMDGPUMCExpr::S_REL32_HI, "rel32@hi"},
25+
{AMDGPUMCExpr::S_REL64, "rel64"},
26+
{AMDGPUMCExpr::S_ABS32_LO, "abs32@lo"},
27+
{AMDGPUMCExpr::S_ABS32_HI, "abs32@hi"},
2728
};
2829

2930
AMDGPUMCAsmInfo::AMDGPUMCAsmInfo(const Triple &TT,

Diff for: llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCCodeEmitter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "MCTargetDesc/AMDGPUFixupKinds.h"
16+
#include "MCTargetDesc/AMDGPUMCExpr.h"
1617
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
1718
#include "SIDefines.h"
1819
#include "Utils/AMDGPUBaseInfo.h"
@@ -546,9 +547,8 @@ static bool needsPCRel(const MCExpr *Expr) {
546547
switch (Expr->getKind()) {
547548
case MCExpr::SymbolRef: {
548549
auto *SE = cast<MCSymbolRefExpr>(Expr);
549-
MCSymbolRefExpr::VariantKind Kind = SE->getKind();
550-
return Kind != MCSymbolRefExpr::VK_AMDGPU_ABS32_LO &&
551-
Kind != MCSymbolRefExpr::VK_AMDGPU_ABS32_HI;
550+
auto Spec = AMDGPU::getSpecifier(SE);
551+
return Spec != AMDGPUMCExpr::S_ABS32_LO && Spec != AMDGPUMCExpr::S_ABS32_HI;
552552
}
553553
case MCExpr::Binary: {
554554
auto *BE = cast<MCBinaryExpr>(Expr);

Diff for: llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ class AMDGPUMCExpr : public MCTargetExpr {
3939
AGVK_Occupancy
4040
};
4141

42+
// Relocation specifiers.
43+
enum Specifier {
44+
S_None,
45+
S_GOTPCREL, // symbol@gotpcrel
46+
S_GOTPCREL32_LO, // symbol@gotpcrel32@lo
47+
S_GOTPCREL32_HI, // symbol@gotpcrel32@hi
48+
S_REL32_LO, // symbol@rel32@lo
49+
S_REL32_HI, // symbol@rel32@hi
50+
S_REL64, // symbol@rel64
51+
S_ABS32_LO, // symbol@abs32@lo
52+
S_ABS32_HI, // symbol@abs32@hi
53+
};
54+
4255
private:
4356
VariantKind Kind;
4457
MCContext &Ctx;
@@ -113,6 +126,9 @@ void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS,
113126

114127
const MCExpr *foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx);
115128

129+
static inline AMDGPUMCExpr::Specifier getSpecifier(const MCSymbolRefExpr *SRE) {
130+
return AMDGPUMCExpr::Specifier(SRE->getKind());
131+
}
116132
} // end namespace AMDGPU
117133
} // end namespace llvm
118134

Diff for: llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,8 @@ void AMDGPUTargetELFStreamer::EmitAmdhsaKernelDescriptor(
10051005
// It implies R_AMDGPU_REL64, but ends up being R_AMDGPU_ABS64.
10061006
Streamer.emitValue(
10071007
MCBinaryExpr::createSub(
1008-
MCSymbolRefExpr::create(KernelCodeSymbol,
1009-
MCSymbolRefExpr::VK_AMDGPU_REL64, Context),
1008+
MCSymbolRefExpr::create(KernelCodeSymbol, AMDGPUMCExpr::S_REL64,
1009+
Context),
10101010
MCSymbolRefExpr::create(KernelDescriptorSymbol, Context), Context),
10111011
sizeof(amdhsa::kernel_descriptor_t::kernel_code_entry_byte_offset));
10121012
for (uint32_t i = 0; i < sizeof(amdhsa::kernel_descriptor_t::reserved1); ++i)

Diff for: llvm/lib/Target/AMDGPU/MCTargetDesc/R600MCCodeEmitter.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
#include "MCTargetDesc/AMDGPUMCExpr.h"
1617
#include "MCTargetDesc/R600MCTargetDesc.h"
1718
#include "R600Defines.h"
1819
#include "llvm/MC/MCCodeEmitter.h"

0 commit comments

Comments
 (0)