Skip to content

Commit 6919131

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.5 [skip ci]
1 parent c34d2fb commit 6919131

File tree

18 files changed

+968
-42
lines changed

18 files changed

+968
-42
lines changed

llvm/include/llvm/BinaryFormat/ELFRelocs/Sparc.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ ELF_RELOC(R_SPARC_GOTDATA_LOX10, 81)
8787
ELF_RELOC(R_SPARC_GOTDATA_OP_HIX22, 82)
8888
ELF_RELOC(R_SPARC_GOTDATA_OP_LOX10, 83)
8989
ELF_RELOC(R_SPARC_GOTDATA_OP, 84)
90+
ELF_RELOC(R_SPARC_WDISP10, 88)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ DecodeCoprocPairRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
261261

262262
static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn, uint64_t Address,
263263
const MCDisassembler *Decoder);
264+
static DecodeStatus DecodeSIMM5(MCInst &Inst, unsigned insn, uint64_t Address,
265+
const MCDisassembler *Decoder);
264266
static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn, uint64_t Address,
265267
const MCDisassembler *Decoder);
266268

@@ -340,6 +342,13 @@ static DecodeStatus DecodeCall(MCInst &MI, unsigned insn, uint64_t Address,
340342
return MCDisassembler::Success;
341343
}
342344

345+
static DecodeStatus DecodeSIMM5(MCInst &MI, unsigned insn, uint64_t Address,
346+
const MCDisassembler *Decoder) {
347+
assert(isUInt<5>(insn));
348+
MI.addOperand(MCOperand::createImm(SignExtend64<5>(insn)));
349+
return MCDisassembler::Success;
350+
}
351+
343352
static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, uint64_t Address,
344353
const MCDisassembler *Decoder) {
345354
assert(isUInt<13>(insn));

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
5050
return (d16hi << 20) | d16lo;
5151
}
5252

53+
case Sparc::fixup_sparc_br10: {
54+
// 7.17 Compare and Branch
55+
// Inst{20-19} = d10hi;
56+
// Inst{12-5} = d10lo;
57+
unsigned d10hi = (Value >> 10) & 0x3;
58+
unsigned d10lo = (Value >> 2) & 0xff;
59+
return (d10hi << 19) | (d10lo << 5);
60+
}
61+
5362
case Sparc::fixup_sparc_hix22:
5463
return (~Value >> 10) & 0x3fffff;
5564

@@ -138,11 +147,13 @@ namespace {
138147

139148
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override {
140149
const static MCFixupKindInfo InfosBE[Sparc::NumTargetFixupKinds] = {
150+
// clang-format off
141151
// name offset bits flags
142152
{ "fixup_sparc_call30", 2, 30, MCFixupKindInfo::FKF_IsPCRel },
143153
{ "fixup_sparc_br22", 10, 22, MCFixupKindInfo::FKF_IsPCRel },
144154
{ "fixup_sparc_br19", 13, 19, MCFixupKindInfo::FKF_IsPCRel },
145155
{ "fixup_sparc_br16", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
156+
{ "fixup_sparc_br10", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
146157
{ "fixup_sparc_13", 19, 13, 0 },
147158
{ "fixup_sparc_hi22", 10, 22, 0 },
148159
{ "fixup_sparc_lo10", 22, 10, 0 },
@@ -160,14 +171,17 @@ namespace {
160171
{ "fixup_sparc_gotdata_hix22", 0, 0, 0 },
161172
{ "fixup_sparc_gotdata_lox10", 0, 0, 0 },
162173
{ "fixup_sparc_gotdata_op", 0, 0, 0 },
174+
// clang-format on
163175
};
164176

165177
const static MCFixupKindInfo InfosLE[Sparc::NumTargetFixupKinds] = {
178+
// clang-format off
166179
// name offset bits flags
167180
{ "fixup_sparc_call30", 0, 30, MCFixupKindInfo::FKF_IsPCRel },
168181
{ "fixup_sparc_br22", 0, 22, MCFixupKindInfo::FKF_IsPCRel },
169182
{ "fixup_sparc_br19", 0, 19, MCFixupKindInfo::FKF_IsPCRel },
170183
{ "fixup_sparc_br16", 32, 0, MCFixupKindInfo::FKF_IsPCRel },
184+
{ "fixup_sparc_br10", 32, 0, MCFixupKindInfo::FKF_IsPCRel },
171185
{ "fixup_sparc_13", 0, 13, 0 },
172186
{ "fixup_sparc_hi22", 0, 22, 0 },
173187
{ "fixup_sparc_lo10", 0, 10, 0 },
@@ -185,6 +199,7 @@ namespace {
185199
{ "fixup_sparc_gotdata_hix22", 0, 0, 0 },
186200
{ "fixup_sparc_gotdata_lox10", 0, 0, 0 },
187201
{ "fixup_sparc_gotdata_op", 0, 0, 0 },
202+
// clang-format on
188203
};
189204

190205
// Fixup kinds from .reloc directive are like R_SPARC_NONE. They do

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,
9090
case Sparc::fixup_sparc_br19: return ELF::R_SPARC_WDISP19;
9191
case Sparc::fixup_sparc_br16:
9292
return ELF::R_SPARC_WDISP16;
93+
case Sparc::fixup_sparc_br10:
94+
return ELF::R_SPARC_WDISP10;
9395
case Sparc::fixup_sparc_pc22: return ELF::R_SPARC_PC22;
9496
case Sparc::fixup_sparc_pc10: return ELF::R_SPARC_PC10;
9597
case Sparc::fixup_sparc_wplt30: return ELF::R_SPARC_WPLT30;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "llvm/MC/MCFixup.h"
1313

14+
// clang-format off
1415
namespace llvm {
1516
namespace Sparc {
1617
enum Fixups {
@@ -28,6 +29,9 @@ namespace llvm {
2829
/// fixup_sparc_bpr - 16-bit fixup for bpr
2930
fixup_sparc_br16,
3031

32+
/// fixup_sparc_br10 - 10-bit fixup for cbcond
33+
fixup_sparc_br10,
34+
3135
/// fixup_sparc_13 - 13-bit fixup
3236
fixup_sparc_13,
3337

@@ -83,5 +87,5 @@ namespace llvm {
8387
};
8488
}
8589
}
86-
90+
// clang-format on
8791
#endif

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
192192
// Make sure CC is a fp conditional flag.
193193
CC = (CC < SPCC::FCC_BEGIN) ? (CC + SPCC::FCC_BEGIN) : CC;
194194
break;
195-
case SP::CBCOND:
196-
case SP::CBCONDA:
195+
case SP::CPBCOND:
196+
case SP::CPBCONDA:
197197
// Make sure CC is a cp conditional flag.
198198
CC = (CC < SPCC::CPCC_BEGIN) ? (CC + SPCC::CPCC_BEGIN) : CC;
199199
break;

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class SparcMCCodeEmitter : public MCCodeEmitter {
7272
unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
7373
SmallVectorImpl<MCFixup> &Fixups,
7474
const MCSubtargetInfo &STI) const;
75+
unsigned getSImm5OpValue(const MCInst &MI, unsigned OpNo,
76+
SmallVectorImpl<MCFixup> &Fixups,
77+
const MCSubtargetInfo &STI) const;
7578
unsigned getSImm13OpValue(const MCInst &MI, unsigned OpNo,
7679
SmallVectorImpl<MCFixup> &Fixups,
7780
const MCSubtargetInfo &STI) const;
@@ -81,6 +84,9 @@ class SparcMCCodeEmitter : public MCCodeEmitter {
8184
unsigned getBranchOnRegTargetOpValue(const MCInst &MI, unsigned OpNo,
8285
SmallVectorImpl<MCFixup> &Fixups,
8386
const MCSubtargetInfo &STI) const;
87+
unsigned getCompareAndBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
88+
SmallVectorImpl<MCFixup> &Fixups,
89+
const MCSubtargetInfo &STI) const;
8490
};
8591

8692
} // end anonymous namespace
@@ -141,6 +147,26 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO,
141147
return 0;
142148
}
143149

150+
unsigned SparcMCCodeEmitter::getSImm5OpValue(const MCInst &MI, unsigned OpNo,
151+
SmallVectorImpl<MCFixup> &Fixups,
152+
const MCSubtargetInfo &STI) const {
153+
const MCOperand &MO = MI.getOperand(OpNo);
154+
155+
if (MO.isImm())
156+
return MO.getImm();
157+
158+
assert(MO.isExpr() &&
159+
"getSImm5OpValue expects only expressions or an immediate");
160+
161+
const MCExpr *Expr = MO.getExpr();
162+
163+
// Constant value, no fixup is needed
164+
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
165+
return CE->getValue();
166+
167+
llvm_unreachable("simm5 operands can only be used with constants!");
168+
}
169+
144170
unsigned
145171
SparcMCCodeEmitter::getSImm13OpValue(const MCInst &MI, unsigned OpNo,
146172
SmallVectorImpl<MCFixup> &Fixups,
@@ -236,6 +262,19 @@ getBranchOnRegTargetOpValue(const MCInst &MI, unsigned OpNo,
236262
return 0;
237263
}
238264

265+
unsigned SparcMCCodeEmitter::getCompareAndBranchTargetOpValue(
266+
const MCInst &MI, unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups,
267+
const MCSubtargetInfo &STI) const {
268+
const MCOperand &MO = MI.getOperand(OpNo);
269+
if (MO.isReg() || MO.isImm())
270+
return getMachineOpValue(MI, MO, Fixups, STI);
271+
272+
Fixups.push_back(
273+
MCFixup::create(0, MO.getExpr(), (MCFixupKind)Sparc::fixup_sparc_br10));
274+
275+
return 0;
276+
}
277+
239278
#include "SparcGenMCCodeEmitter.inc"
240279

241280
MCCodeEmitter *llvm::createSparcMCCodeEmitter(const MCInstrInfo &MCII,

llvm/lib/Target/Sparc/Sparc.td

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def FeatureVIS2
4949
def FeatureVIS3
5050
: SubtargetFeature<"vis3", "IsVIS3", "true",
5151
"Enable Visual Instruction Set extensions III">;
52+
def FeatureUA2005
53+
: SubtargetFeature<"ua2005", "IsUA2005", "true",
54+
"Enable UltraSPARC Architecture 2005 extensions">;
55+
def FeatureUA2007
56+
: SubtargetFeature<"ua2007", "IsUA2007", "true",
57+
"Enable UltraSPARC Architecture 2007 extensions">;
58+
def FeatureOSA2011
59+
: SubtargetFeature<"osa2011", "IsOSA2011", "true",
60+
"Enable Oracle SPARC Architecture 2011 extensions">;
5261
def FeatureLeon
5362
: SubtargetFeature<"leon", "IsLeon", "true",
5463
"Enable LEON extensions">;
@@ -152,13 +161,15 @@ def : Proc<"ultrasparc3", [FeatureV9, FeatureV8Deprecated, FeatureVIS,
152161
FeatureVIS2],
153162
[TuneSlowRDPC]>;
154163
def : Proc<"niagara", [FeatureV9, FeatureV8Deprecated, FeatureVIS,
155-
FeatureVIS2]>;
164+
FeatureVIS2, FeatureUA2005]>;
156165
def : Proc<"niagara2", [FeatureV9, FeatureV8Deprecated, UsePopc,
157-
FeatureVIS, FeatureVIS2]>;
166+
FeatureVIS, FeatureVIS2, FeatureUA2005]>;
158167
def : Proc<"niagara3", [FeatureV9, FeatureV8Deprecated, UsePopc,
159-
FeatureVIS, FeatureVIS2, FeatureVIS3]>;
168+
FeatureVIS, FeatureVIS2, FeatureVIS3,
169+
FeatureUA2005, FeatureUA2007]>;
160170
def : Proc<"niagara4", [FeatureV9, FeatureV8Deprecated, UsePopc,
161-
FeatureVIS, FeatureVIS2, FeatureVIS3]>;
171+
FeatureVIS, FeatureVIS2, FeatureVIS3,
172+
FeatureUA2005, FeatureUA2007, FeatureOSA2011]>;
162173

163174
// LEON 2 FT generic
164175
def : Processor<"leon2", LEON2Itineraries,

llvm/lib/Target/Sparc/SparcInstrAliases.td

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ multiclass cp_cond_alias<string cond, int condVal> {
286286

287287
// cb<cond> $imm
288288
def : InstAlias<!strconcat(!strconcat("cb", cond), " $imm"),
289-
(CBCOND brtarget:$imm, condVal), 0>;
289+
(CPBCOND brtarget:$imm, condVal), 0>;
290290

291291
// cb<cond>,a $imm
292292
def : InstAlias<!strconcat(!strconcat("cb", cond), ",a $imm"),
293-
(CBCONDA brtarget:$imm, condVal), 0>;
293+
(CPBCONDA brtarget:$imm, condVal), 0>;
294294
}
295295

296296
// Instruction aliases for register conditional branches and moves.
@@ -331,6 +331,25 @@ multiclass reg_cond_alias<string rcond, int condVal> {
331331
Requires<[Is64Bit]>;
332332
}
333333

334+
// Instruction aliases for compare-and-branch.
335+
multiclass cwb_cond_alias<string cond, int condVal> {
336+
def : InstAlias<!strconcat(!strconcat("cwb", cond), " $rs1, $rs2, $imm"),
337+
(CWBCONDrr cbtarget:$imm, condVal, IntRegs:$rs1, IntRegs:$rs2)>,
338+
Requires<[HasOSA2011]>;
339+
def : InstAlias<!strconcat(!strconcat("cwb", cond), " $rs1, $simm5, $imm"),
340+
(CWBCONDri cbtarget:$imm, condVal, IntRegs:$rs1, simm5Op:$simm5)>,
341+
Requires<[HasOSA2011]>;
342+
}
343+
344+
multiclass cxb_cond_alias<string cond, int condVal> {
345+
def : InstAlias<!strconcat(!strconcat("cxb", cond), " $rs1, $rs2, $imm"),
346+
(CXBCONDrr cbtarget:$imm, condVal, IntRegs:$rs1, IntRegs:$rs2)>,
347+
Requires<[HasOSA2011]>;
348+
def : InstAlias<!strconcat(!strconcat("cxb", cond), " $rs1, $simm5, $imm"),
349+
(CXBCONDri cbtarget:$imm, condVal, IntRegs:$rs1, simm5Op:$simm5)>,
350+
Requires<[HasOSA2011]>;
351+
}
352+
334353
defm : int_cond_alias<"a", 0b1000>;
335354
defm : int_cond_alias<"n", 0b0000>;
336355
defm : int_cond_alias<"ne", 0b1001>;
@@ -408,6 +427,46 @@ defm : reg_cond_alias<"ne", 0b101>;
408427
defm : reg_cond_alias<"gz", 0b110>;
409428
defm : reg_cond_alias<"gez", 0b111>;
410429

430+
defm : cwb_cond_alias<"ne", 0b1001>;
431+
defm : cwb_cond_alias<"e", 0b0001>;
432+
defm : cwb_cond_alias<"g", 0b1010>;
433+
defm : cwb_cond_alias<"le", 0b0010>;
434+
defm : cwb_cond_alias<"ge", 0b1011>;
435+
defm : cwb_cond_alias<"l", 0b0011>;
436+
defm : cwb_cond_alias<"gu", 0b1100>;
437+
defm : cwb_cond_alias<"leu", 0b0100>;
438+
defm : cwb_cond_alias<"cc", 0b1101>;
439+
defm : cwb_cond_alias<"cs", 0b0101>;
440+
defm : cwb_cond_alias<"pos", 0b1110>;
441+
defm : cwb_cond_alias<"neg", 0b0110>;
442+
defm : cwb_cond_alias<"vc", 0b1111>;
443+
defm : cwb_cond_alias<"vs", 0b0111>;
444+
let EmitPriority = 0 in
445+
{
446+
defm : cwb_cond_alias<"geu", 0b1101>; // same as cc
447+
defm : cwb_cond_alias<"lu", 0b0101>; // same as cs
448+
}
449+
450+
defm : cxb_cond_alias<"ne", 0b1001>;
451+
defm : cxb_cond_alias<"e", 0b0001>;
452+
defm : cxb_cond_alias<"g", 0b1010>;
453+
defm : cxb_cond_alias<"le", 0b0010>;
454+
defm : cxb_cond_alias<"ge", 0b1011>;
455+
defm : cxb_cond_alias<"l", 0b0011>;
456+
defm : cxb_cond_alias<"gu", 0b1100>;
457+
defm : cxb_cond_alias<"leu", 0b0100>;
458+
defm : cxb_cond_alias<"cc", 0b1101>;
459+
defm : cxb_cond_alias<"cs", 0b0101>;
460+
defm : cxb_cond_alias<"pos", 0b1110>;
461+
defm : cxb_cond_alias<"neg", 0b0110>;
462+
defm : cxb_cond_alias<"vc", 0b1111>;
463+
defm : cxb_cond_alias<"vs", 0b0111>;
464+
let EmitPriority = 0 in
465+
{
466+
defm : cxb_cond_alias<"geu", 0b1101>; // same as cc
467+
defm : cxb_cond_alias<"lu", 0b0101>; // same as cs
468+
}
469+
411470
// Section A.3 Synthetic Instructions
412471

413472
// Most are marked as Emit=0, so that they are not used for disassembly. This is
@@ -665,3 +724,9 @@ def : InstAlias<"signx $rs1, $rd", (SRArr IntRegs:$rd, IntRegs:$rs1, G0), 0>, Re
665724

666725
// sir -> sir 0
667726
def : InstAlias<"sir", (SIR 0), 0>;
727+
728+
// pause reg_or_imm -> wrasr %g0, reg_or_imm, %asr27
729+
let Predicates = [HasOSA2011] in {
730+
def : InstAlias<"pause $rs2", (WRASRrr ASR27, G0, IntRegs:$rs2), 1>;
731+
def : InstAlias<"pause $simm13", (WRASRri ASR27, G0, simm13Op:$simm13), 1>;
732+
} // Predicates = [HasOSA2011]

0 commit comments

Comments
 (0)