Skip to content

Commit 91aa0b6

Browse files
authored
merge main into amd-staging (llvm#1972)
2 parents de00d8c + c794cdc commit 91aa0b6

27 files changed

+269
-250
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
418418
if (!OffloadBundlerPath)
419419
return OffloadBundlerPath.takeError();
420420

421-
llvm::Triple Triple(
422-
Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
423-
424421
// Create a new file to write the linked device image to.
425422
auto TempFileOrErr =
426423
createOutputFile(sys::path::filename(ExecutableName), "hipfb");
@@ -758,7 +755,6 @@ bundleCuda(ArrayRef<OffloadingImage> Images, const ArgList &Args) {
758755
InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
759756
Image.StringData.lookup("arch")));
760757

761-
Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
762758
auto FileOrErr = nvptx::fatbinary(InputFiles, Args);
763759
if (!FileOrErr)
764760
return FileOrErr.takeError();
@@ -781,7 +777,6 @@ bundleHIP(ArrayRef<OffloadingImage> Images, const ArgList &Args) {
781777
InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
782778
Image.StringData.lookup("arch")));
783779

784-
Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
785780
auto FileOrErr = amdgcn::fatbinary(InputFiles, Args);
786781
if (!FileOrErr)
787782
return FileOrErr.takeError();

llvm/lib/MC/MCAssembler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
203203
if (IsResolved) {
204204
auto TargetVal = Target;
205205
TargetVal.Cst = Value;
206-
if (mc::isRelocation(Fixup.getKind()) ||
206+
if (mc::isRelocRelocation(Fixup.getKind()) ||
207207
getBackend().shouldForceRelocation(*this, Fixup, TargetVal, STI))
208208
IsResolved = false;
209209
}

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "TargetInfo/SparcTargetInfo.h"
1212
#include "llvm/ADT/SmallVector.h"
1313
#include "llvm/ADT/StringRef.h"
14+
#include "llvm/BinaryFormat/ELF.h"
1415
#include "llvm/MC/MCAsmMacro.h"
1516
#include "llvm/MC/MCContext.h"
1617
#include "llvm/MC/MCExpr.h"
@@ -1677,12 +1678,12 @@ SparcAsmParser::adjustPICRelocation(SparcMCExpr::Specifier VK,
16771678
switch(VK) {
16781679
default: break;
16791680
case SparcMCExpr::VK_LO:
1680-
VK = (hasGOTReference(subExpr) ? SparcMCExpr::VK_PC10
1681-
: SparcMCExpr::VK_GOT10);
1681+
VK = SparcMCExpr::Specifier(
1682+
hasGOTReference(subExpr) ? ELF::R_SPARC_PC10 : ELF::R_SPARC_GOT10);
16821683
break;
16831684
case SparcMCExpr::VK_HI:
1684-
VK = (hasGOTReference(subExpr) ? SparcMCExpr::VK_PC22
1685-
: SparcMCExpr::VK_GOT22);
1685+
VK = SparcMCExpr::Specifier(
1686+
hasGOTReference(subExpr) ? ELF::R_SPARC_PC22 : ELF::R_SPARC_GOT22);
16861687
break;
16871688
}
16881689
}

llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
276276
return MCDisassembler::Fail;
277277
}
278278

279+
Size = 4;
279280
Insn = IsLittleEndian
280281
? (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) |
281282
(Bytes[3] << 24)
@@ -306,20 +307,13 @@ DecodeStatus SparcDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
306307
{
307308
Result = decodeInstruction(DecoderTableSparcV832, Instr, Insn, Address, this, STI);
308309
}
309-
if (Result != MCDisassembler::Fail) {
310-
Size = 4;
310+
if (Result != MCDisassembler::Fail)
311311
return Result;
312-
}
313312

314313
Result =
315314
decodeInstruction(DecoderTableSparc32, Instr, Insn, Address, this, STI);
316315

317-
if (Result != MCDisassembler::Fail) {
318-
Size = 4;
319-
return Result;
320-
}
321-
322-
return MCDisassembler::Fail;
316+
return Result;
323317
}
324318

325319
static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,

llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ using namespace llvm;
2424
static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
2525
switch (Kind) {
2626
default:
27-
llvm_unreachable("Unknown fixup kind!");
27+
assert(uint16_t(Kind) < FirstTargetFixupKind && "Unknown fixup kind!");
28+
return Value;
2829
case FK_Data_1:
2930
case FK_Data_2:
3031
case FK_Data_4:
@@ -52,7 +53,7 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
5253
case Sparc::fixup_sparc_hix22:
5354
return (~Value >> 10) & 0x3fffff;
5455

55-
case Sparc::fixup_sparc_pc22:
56+
case ELF::R_SPARC_PC22:
5657
case Sparc::fixup_sparc_hi22:
5758
case Sparc::fixup_sparc_lm:
5859
return (Value >> 10) & 0x3fffff;
@@ -63,19 +64,10 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
6364
case Sparc::fixup_sparc_lox10:
6465
return (Value & 0x3ff) | 0x1c00;
6566

66-
case Sparc::fixup_sparc_pc10:
67+
case ELF::R_SPARC_PC10:
6768
case Sparc::fixup_sparc_lo10:
6869
return Value & 0x3ff;
6970

70-
case Sparc::fixup_sparc_h44:
71-
return (Value >> 22) & 0x3fffff;
72-
73-
case Sparc::fixup_sparc_m44:
74-
return (Value >> 12) & 0x3ff;
75-
76-
case Sparc::fixup_sparc_l44:
77-
return Value & 0xfff;
78-
7971
case Sparc::fixup_sparc_hh:
8072
return (Value >> 42) & 0x3fffff;
8173

@@ -141,14 +133,9 @@ namespace {
141133
{ "fixup_sparc_13", 19, 13, 0 },
142134
{ "fixup_sparc_hi22", 10, 22, 0 },
143135
{ "fixup_sparc_lo10", 22, 10, 0 },
144-
{ "fixup_sparc_h44", 10, 22, 0 },
145-
{ "fixup_sparc_m44", 22, 10, 0 },
146-
{ "fixup_sparc_l44", 20, 12, 0 },
147136
{ "fixup_sparc_hh", 10, 22, 0 },
148137
{ "fixup_sparc_hm", 22, 10, 0 },
149138
{ "fixup_sparc_lm", 10, 22, 0 },
150-
{ "fixup_sparc_pc22", 10, 22, MCFixupKindInfo::FKF_IsPCRel },
151-
{ "fixup_sparc_pc10", 22, 10, MCFixupKindInfo::FKF_IsPCRel },
152139
{ "fixup_sparc_hix22", 10, 22, 0 },
153140
{ "fixup_sparc_lox10", 19, 13, 0 },
154141
};
@@ -162,34 +149,38 @@ namespace {
162149
{ "fixup_sparc_13", 0, 13, 0 },
163150
{ "fixup_sparc_hi22", 0, 22, 0 },
164151
{ "fixup_sparc_lo10", 0, 10, 0 },
165-
{ "fixup_sparc_h44", 0, 22, 0 },
166-
{ "fixup_sparc_m44", 0, 10, 0 },
167-
{ "fixup_sparc_l44", 0, 12, 0 },
168152
{ "fixup_sparc_hh", 0, 22, 0 },
169153
{ "fixup_sparc_hm", 0, 10, 0 },
170154
{ "fixup_sparc_lm", 0, 22, 0 },
171-
{ "fixup_sparc_pc22", 0, 22, MCFixupKindInfo::FKF_IsPCRel },
172-
{ "fixup_sparc_pc10", 0, 10, MCFixupKindInfo::FKF_IsPCRel },
173155
{ "fixup_sparc_hix22", 0, 22, 0 },
174156
{ "fixup_sparc_lox10", 0, 13, 0 },
175157
};
176158
// clang-format on
177159

178-
// Fixup kinds from .reloc directive are like R_SPARC_NONE. They do
179-
// not require any extra processing.
180-
if (mc::isRelocation(Kind))
181-
return MCAsmBackend::getFixupKindInfo(FK_NONE);
160+
if (!mc::isRelocation(Kind)) {
161+
if (Kind < FirstTargetFixupKind)
162+
return MCAsmBackend::getFixupKindInfo(Kind);
163+
assert(unsigned(Kind - FirstTargetFixupKind) <
164+
Sparc::NumTargetFixupKinds &&
165+
"Invalid kind!");
166+
if (Endian == llvm::endianness::little)
167+
return InfosLE[Kind - FirstTargetFixupKind];
182168

183-
if (Kind < FirstTargetFixupKind)
184-
return MCAsmBackend::getFixupKindInfo(Kind);
169+
return InfosBE[Kind - FirstTargetFixupKind];
170+
}
185171

186-
assert(unsigned(Kind - FirstTargetFixupKind) <
187-
Sparc::NumTargetFixupKinds &&
188-
"Invalid kind!");
172+
MCFixupKindInfo Info{};
173+
switch (uint16_t(Kind)) {
174+
case ELF::R_SPARC_PC10:
175+
Info = {"", 22, 10, MCFixupKindInfo::FKF_IsPCRel};
176+
break;
177+
case ELF::R_SPARC_PC22:
178+
Info = {"", 10, 22, MCFixupKindInfo::FKF_IsPCRel};
179+
break;
180+
}
189181
if (Endian == llvm::endianness::little)
190-
return InfosLE[Kind - FirstTargetFixupKind];
191-
192-
return InfosBE[Kind - FirstTargetFixupKind];
182+
Info.TargetOffset = 32 - Info.TargetOffset - Info.TargetSize;
183+
return Info;
193184
}
194185

195186
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
@@ -230,8 +221,7 @@ namespace {
230221
const MCValue &Target, MutableArrayRef<char> Data,
231222
uint64_t Value, bool IsResolved,
232223
const MCSubtargetInfo *STI) const override {
233-
234-
if (mc::isRelocation(Fixup.getKind()))
224+
if (mc::isRelocRelocation(Fixup.getKind()))
235225
return;
236226
Value = adjustFixupValue(Fixup.getKind(), Value);
237227
if (!Value) return; // Doesn't change encoding.

llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,
9595
case Sparc::fixup_sparc_br19: return ELF::R_SPARC_WDISP19;
9696
case Sparc::fixup_sparc_br16:
9797
return ELF::R_SPARC_WDISP16;
98-
case Sparc::fixup_sparc_pc22: return ELF::R_SPARC_PC22;
99-
case Sparc::fixup_sparc_pc10: return ELF::R_SPARC_PC10;
10098
}
10199
}
102100

@@ -122,9 +120,6 @@ unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,
122120

123121
case Sparc::fixup_sparc_hi22: return ELF::R_SPARC_HI22;
124122
case Sparc::fixup_sparc_lo10: return ELF::R_SPARC_LO10;
125-
case Sparc::fixup_sparc_h44: return ELF::R_SPARC_H44;
126-
case Sparc::fixup_sparc_m44: return ELF::R_SPARC_M44;
127-
case Sparc::fixup_sparc_l44: return ELF::R_SPARC_L44;
128123
case Sparc::fixup_sparc_hh: return ELF::R_SPARC_HH22;
129124
case Sparc::fixup_sparc_hm: return ELF::R_SPARC_HM10;
130125
case Sparc::fixup_sparc_lm: return ELF::R_SPARC_LM22;

llvm/lib/Target/Sparc/MCTargetDesc/SparcFixupKinds.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ namespace llvm {
3939
/// fixup_sparc_lo10 - 10-bit fixup corresponding to %lo(foo)
4040
fixup_sparc_lo10,
4141

42-
/// fixup_sparc_h44 - 22-bit fixup corresponding to %h44(foo)
43-
fixup_sparc_h44,
44-
45-
/// fixup_sparc_m44 - 10-bit fixup corresponding to %m44(foo)
46-
fixup_sparc_m44,
47-
48-
/// fixup_sparc_l44 - 12-bit fixup corresponding to %l44(foo)
49-
fixup_sparc_l44,
50-
5142
/// fixup_sparc_hh - 22-bit fixup corresponding to %hh(foo)
5243
fixup_sparc_hh,
5344

@@ -57,12 +48,6 @@ namespace llvm {
5748
/// fixup_sparc_lm - 22-bit fixup corresponding to %lm(foo)
5849
fixup_sparc_lm,
5950

60-
/// fixup_sparc_pc22 - 22-bit fixup corresponding to %pc22(foo)
61-
fixup_sparc_pc22,
62-
63-
/// fixup_sparc_pc10 - 10-bit fixup corresponding to %pc10(foo)
64-
fixup_sparc_pc10,
65-
6651
/// 22-bit fixup corresponding to %hix(foo)
6752
fixup_sparc_hix22,
6853
/// 13-bit fixup corresponding to %lox(foo)

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ void SparcMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
4040

4141
StringRef SparcMCExpr::getSpecifierName(SparcMCExpr::Specifier S) {
4242
// clang-format off
43-
switch (S) {
43+
switch (uint16_t(S)) {
4444
case VK_None: return {};
4545
case VK_LO: return "lo";
4646
case VK_HI: return "hi";
47-
case VK_H44: return "h44";
48-
case VK_M44: return "m44";
49-
case VK_L44: return "l44";
47+
case ELF::R_SPARC_H44: return "h44";
48+
case ELF::R_SPARC_M44: return "m44";
49+
case ELF::R_SPARC_L44: return "l44";
5050
case VK_HH: return "hh";
5151
case VK_HM: return "hm";
5252
case VK_LM: return "lm";
5353
// FIXME: use %pc22/%pc10, if system assembler supports them.
54-
case VK_PC22: return "hi";
55-
case VK_PC10: return "lo";
56-
case VK_GOT22: return "hi";
57-
case VK_GOT10: return "lo";
58-
case VK_GOT13: return {};
54+
case ELF::R_SPARC_PC22: return "hi";
55+
case ELF::R_SPARC_PC10: return "lo";
56+
case ELF::R_SPARC_GOT22: return "hi";
57+
case ELF::R_SPARC_GOT10: return "lo";
58+
case ELF::R_SPARC_GOT13: return {};
5959
case VK_R_DISP32: return "r_disp32";
6060
case VK_TLS_GD_HI22: return "tgd_hi22";
6161
case VK_TLS_GD_LO10: return "tgd_lo10";
@@ -89,19 +89,19 @@ SparcMCExpr::Specifier SparcMCExpr::parseSpecifier(StringRef name) {
8989
return StringSwitch<SparcMCExpr::Specifier>(name)
9090
.Case("lo", VK_LO)
9191
.Case("hi", VK_HI)
92-
.Case("h44", VK_H44)
93-
.Case("m44", VK_M44)
94-
.Case("l44", VK_L44)
92+
.Case("h44", (SparcMCExpr::Specifier)ELF::R_SPARC_H44)
93+
.Case("m44", (SparcMCExpr::Specifier)ELF::R_SPARC_M44)
94+
.Case("l44", (SparcMCExpr::Specifier)ELF::R_SPARC_L44)
9595
.Case("hh", VK_HH)
9696
.Case("uhi", VK_HH) // Nonstandard GNU extension
9797
.Case("hm", VK_HM)
9898
.Case("ulo", VK_HM) // Nonstandard GNU extension
9999
.Case("lm", VK_LM)
100-
.Case("pc22", VK_PC22)
101-
.Case("pc10", VK_PC10)
102-
.Case("got22", VK_GOT22)
103-
.Case("got10", VK_GOT10)
104-
.Case("got13", VK_GOT13)
100+
.Case("pc22", (SparcMCExpr::Specifier)ELF::R_SPARC_PC22)
101+
.Case("pc10", (SparcMCExpr::Specifier)ELF::R_SPARC_PC10)
102+
.Case("got22", (SparcMCExpr::Specifier)ELF::R_SPARC_GOT22)
103+
.Case("got10", (SparcMCExpr::Specifier)ELF::R_SPARC_GOT10)
104+
.Case("got13", (SparcMCExpr::Specifier)ELF::R_SPARC_GOT13)
105105
.Case("r_disp32", VK_R_DISP32)
106106
.Case("tgd_hi22", VK_TLS_GD_HI22)
107107
.Case("tgd_lo10", VK_TLS_GD_LO10)
@@ -132,20 +132,14 @@ SparcMCExpr::Specifier SparcMCExpr::parseSpecifier(StringRef name) {
132132
uint16_t SparcMCExpr::getFixupKind() const {
133133
// clang-format off
134134
switch (specifier) {
135-
default: llvm_unreachable("Unhandled SparcMCExpr::Specifier");
135+
default:
136+
assert(uint16_t(specifier) < FirstTargetFixupKind);
137+
return specifier;
136138
case VK_LO: return Sparc::fixup_sparc_lo10;
137139
case VK_HI: return Sparc::fixup_sparc_hi22;
138-
case VK_H44: return Sparc::fixup_sparc_h44;
139-
case VK_M44: return Sparc::fixup_sparc_m44;
140-
case VK_L44: return Sparc::fixup_sparc_l44;
141140
case VK_HH: return Sparc::fixup_sparc_hh;
142141
case VK_HM: return Sparc::fixup_sparc_hm;
143142
case VK_LM: return Sparc::fixup_sparc_lm;
144-
case VK_PC22: return Sparc::fixup_sparc_pc22;
145-
case VK_PC10: return Sparc::fixup_sparc_pc10;
146-
case VK_GOT22: return ELF::R_SPARC_GOT22;
147-
case VK_GOT10: return ELF::R_SPARC_GOT10;
148-
case VK_GOT13: return ELF::R_SPARC_GOT13;
149143
case VK_TLS_GD_HI22: return ELF::R_SPARC_TLS_GD_HI22;
150144
case VK_TLS_GD_LO10: return ELF::R_SPARC_TLS_GD_LO10;
151145
case VK_TLS_GD_ADD: return ELF::R_SPARC_TLS_GD_ADD;
@@ -177,6 +171,27 @@ bool SparcMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
177171
const MCAssembler *Asm) const {
178172
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
179173
return false;
174+
175+
if (Res.isAbsolute()) {
176+
std::optional<int64_t> V;
177+
auto C = (uint64_t)Res.getConstant();
178+
switch (uint16_t(specifier)) {
179+
case ELF::R_SPARC_H44:
180+
V = (C >> 22) & 0x3fffff;
181+
break;
182+
case ELF::R_SPARC_M44:
183+
V = (C >> 12) & 0x3ff;
184+
break;
185+
case ELF::R_SPARC_L44:
186+
V = C & 0xfff;
187+
break;
188+
}
189+
if (V) {
190+
Res = MCValue::get(*V);
191+
return true;
192+
}
193+
}
194+
180195
Res.setSpecifier(specifier);
181196
return true;
182197
}

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,11 @@ class SparcMCExpr : public MCTargetExpr {
2424
public:
2525
enum Specifier {
2626
VK_None,
27-
VK_LO,
27+
VK_LO = 200, // larger than any relocation type
2828
VK_HI,
29-
VK_H44,
30-
VK_M44,
31-
VK_L44,
3229
VK_HH,
3330
VK_HM,
3431
VK_LM,
35-
VK_PC22,
36-
VK_PC10,
37-
VK_GOT22,
38-
VK_GOT10,
39-
VK_GOT13,
4032
VK_R_DISP32,
4133
VK_TLS_GD_HI22,
4234
VK_TLS_GD_LO10,

0 commit comments

Comments
 (0)