Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 5b2a284

Browse files
committed
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to memory to/from a consecutive even/odd pair of (32-bit) registers. They are part of SparcV8, and also present in SparcV9. (Although deprecated there, as you can store 64bits in one register). As recommended on llvmdev in the thread "How to enable use of 64bit load/store for 32bit architecture" from Apr 2015, I've modeled the 64-bit load/store operations as working on a v2i32 type, rather than making i64 a legal type, but with few legal operations. The latter does not (currently) work, as there is much code in llvm which assumes that if i64 is legal, operations like "add" will actually work on it. The same assumption does not hold for v2i32 -- for vector types, it is workable to support only load/store, and expand everything else. This patch: - Adds a new register class, IntPair, for even/odd pairs of registers. - Modifies the list of reserved registers, the stack spilling code, and register copying code to support the IntPair register class. - Adds support in AsmParser. (note that in asm text, you write the name of the first register of the pair only. So the parser has to morph the single register into the equivalent paired register). - Adds the new instructions themselves (LDD/STD/LDDA/STDA). - Hooks up the instructions and registers as a vector type v2i32. Adds custom legalizer to transform i64 load/stores into v2i32 load/stores and bitcasts, so that the new instructions can actually be generated, and marks all operations other than load/store on v2i32 as needing to be expanded. - Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG. This hack undoes the transformation of i64 operands into two arbitrarily-allocated separate i32 registers in SelectionDAGBuilder. and instead passes them in a single IntPair. (Arbitrarily allocated registers are not useful, asm code expects to be receiving a pair, which can be passed to ldd/std.) Also adds a bunch of test cases covering all the bugs I've added along the way. Differential Revision: http://reviews.llvm.org/D8713 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244484 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 47b7f78 commit 5b2a284

18 files changed

+841
-56
lines changed

Diff for: lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,20 @@ class SparcAsmParser : public MCTargetAsmParser {
140140
SP::ASR24, SP::ASR25, SP::ASR26, SP::ASR27,
141141
SP::ASR28, SP::ASR29, SP::ASR30, SP::ASR31};
142142

143+
static unsigned IntPairRegs[] = {
144+
Sparc::G0_G1, Sparc::G2_G3, Sparc::G4_G5, Sparc::G6_G7,
145+
Sparc::O0_O1, Sparc::O2_O3, Sparc::O4_O5, Sparc::O6_O7,
146+
Sparc::L0_L1, Sparc::L2_L3, Sparc::L4_L5, Sparc::L6_L7,
147+
Sparc::I0_I1, Sparc::I2_I3, Sparc::I4_I5, Sparc::I6_I7};
148+
143149
/// SparcOperand - Instances of this class represent a parsed Sparc machine
144150
/// instruction.
145151
class SparcOperand : public MCParsedAsmOperand {
146152
public:
147153
enum RegisterKind {
148154
rk_None,
149155
rk_IntReg,
156+
rk_IntPairReg,
150157
rk_FloatReg,
151158
rk_DoubleReg,
152159
rk_QuadReg,
@@ -200,6 +207,10 @@ class SparcOperand : public MCParsedAsmOperand {
200207
bool isMEMrr() const { return Kind == k_MemoryReg; }
201208
bool isMEMri() const { return Kind == k_MemoryImm; }
202209

210+
bool isIntReg() const {
211+
return (Kind == k_Register && Reg.Kind == rk_IntReg);
212+
}
213+
203214
bool isFloatReg() const {
204215
return (Kind == k_Register && Reg.Kind == rk_FloatReg);
205216
}
@@ -330,6 +341,25 @@ class SparcOperand : public MCParsedAsmOperand {
330341
return Op;
331342
}
332343

344+
static bool MorphToIntPairReg(SparcOperand &Op) {
345+
unsigned Reg = Op.getReg();
346+
assert(Op.Reg.Kind == rk_IntReg);
347+
unsigned regIdx = 32;
348+
if (Reg >= Sparc::G0 && Reg <= Sparc::G7)
349+
regIdx = Reg - Sparc::G0;
350+
else if (Reg >= Sparc::O0 && Reg <= Sparc::O7)
351+
regIdx = Reg - Sparc::O0 + 8;
352+
else if (Reg >= Sparc::L0 && Reg <= Sparc::L7)
353+
regIdx = Reg - Sparc::L0 + 16;
354+
else if (Reg >= Sparc::I0 && Reg <= Sparc::I7)
355+
regIdx = Reg - Sparc::I0 + 24;
356+
if (regIdx % 2 || regIdx > 31)
357+
return false;
358+
Op.Reg.RegNum = IntPairRegs[regIdx / 2];
359+
Op.Reg.Kind = rk_IntPairReg;
360+
return true;
361+
}
362+
333363
static bool MorphToDoubleReg(SparcOperand &Op) {
334364
unsigned Reg = Op.getReg();
335365
assert(Op.Reg.Kind == rk_FloatReg);
@@ -1051,5 +1081,9 @@ unsigned SparcAsmParser::validateTargetOperandClass(MCParsedAsmOperand &GOp,
10511081
break;
10521082
}
10531083
}
1084+
if (Op.isIntReg() && Kind == MCK_IntPair) {
1085+
if (SparcOperand::MorphToIntPairReg(Op))
1086+
return MCTargetAsmParser::Match_Success;
1087+
}
10541088
return Match_InvalidOperand;
10551089
}

Diff for: lib/Target/Sparc/Disassembler/SparcDisassembler.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ static const unsigned ASRRegDecoderTable[] = {
117117
SP::ASR24, SP::ASR25, SP::ASR26, SP::ASR27,
118118
SP::ASR28, SP::ASR29, SP::ASR30, SP::ASR31};
119119

120+
static const uint16_t IntPairDecoderTable[] = {
121+
SP::G0_G1, SP::G2_G3, SP::G4_G5, SP::G6_G7,
122+
SP::O0_O1, SP::O2_O3, SP::O4_O5, SP::O6_O7,
123+
SP::L0_L1, SP::L2_L3, SP::L4_L5, SP::L6_L7,
124+
SP::I0_I1, SP::I2_I3, SP::I4_I5, SP::I6_I7,
125+
};
126+
120127
static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst,
121128
unsigned RegNo,
122129
uint64_t Address,
@@ -196,9 +203,25 @@ static DecodeStatus DecodeASRRegsRegisterClass(MCInst &Inst, unsigned RegNo,
196203
return MCDisassembler::Success;
197204
}
198205

206+
static DecodeStatus DecodeIntPairRegisterClass(MCInst &Inst, unsigned RegNo,
207+
uint64_t Address, const void *Decoder) {
208+
DecodeStatus S = MCDisassembler::Success;
209+
210+
if (RegNo > 31)
211+
return MCDisassembler::Fail;
212+
213+
if ((RegNo & 1))
214+
S = MCDisassembler::SoftFail;
215+
216+
unsigned RegisterPair = IntPairDecoderTable[RegNo/2];
217+
Inst.addOperand(MCOperand::createReg(RegisterPair));
218+
return S;
219+
}
199220

200221
static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
201222
const void *Decoder);
223+
static DecodeStatus DecodeLoadIntPair(MCInst &Inst, unsigned insn, uint64_t Address,
224+
const void *Decoder);
202225
static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
203226
const void *Decoder);
204227
static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address,
@@ -207,6 +230,8 @@ static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address,
207230
const void *Decoder);
208231
static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
209232
uint64_t Address, const void *Decoder);
233+
static DecodeStatus DecodeStoreIntPair(MCInst &Inst, unsigned insn,
234+
uint64_t Address, const void *Decoder);
210235
static DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn,
211236
uint64_t Address, const void *Decoder);
212237
static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn,
@@ -326,6 +351,12 @@ static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
326351
DecodeIntRegsRegisterClass);
327352
}
328353

354+
static DecodeStatus DecodeLoadIntPair(MCInst &Inst, unsigned insn, uint64_t Address,
355+
const void *Decoder) {
356+
return DecodeMem(Inst, insn, Address, Decoder, true,
357+
DecodeIntPairRegisterClass);
358+
}
359+
329360
static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
330361
const void *Decoder) {
331362
return DecodeMem(Inst, insn, Address, Decoder, true,
@@ -350,6 +381,12 @@ static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
350381
DecodeIntRegsRegisterClass);
351382
}
352383

384+
static DecodeStatus DecodeStoreIntPair(MCInst &Inst, unsigned insn,
385+
uint64_t Address, const void *Decoder) {
386+
return DecodeMem(Inst, insn, Address, Decoder, false,
387+
DecodeIntPairRegisterClass);
388+
}
389+
353390
static DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn, uint64_t Address,
354391
const void *Decoder) {
355392
return DecodeMem(Inst, insn, Address, Decoder, false,

Diff for: lib/Target/Sparc/SparcCallingConv.td

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def CC_Sparc32 : CallingConv<[
2121
// i32 f32 arguments get passed in integer registers if there is space.
2222
CCIfType<[i32, f32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,
2323
// f64 arguments are split and passed through registers or through stack.
24-
CCIfType<[f64], CCCustom<"CC_Sparc_Assign_f64">>,
24+
CCIfType<[f64], CCCustom<"CC_Sparc_Assign_Split_64">>,
25+
// As are v2i32 arguments (this would be the default behavior for
26+
// v2i32 if it wasn't allocated to the IntPair register-class)
27+
CCIfType<[v2i32], CCCustom<"CC_Sparc_Assign_Split_64">>,
28+
2529

2630
// Alternatively, they are assigned to the stack in 4-byte aligned units.
2731
CCAssignToStack<4, 4>
@@ -30,7 +34,8 @@ def CC_Sparc32 : CallingConv<[
3034
def RetCC_Sparc32 : CallingConv<[
3135
CCIfType<[i32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,
3236
CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3]>>,
33-
CCIfType<[f64], CCAssignToReg<[D0, D1]>>
37+
CCIfType<[f64], CCAssignToReg<[D0, D1]>>,
38+
CCIfType<[v2i32], CCCustom<"CC_Sparc_Assign_Ret_Split_64">>
3439
]>;
3540

3641

Diff for: lib/Target/Sparc/SparcFrameLowering.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,35 @@ bool SparcFrameLowering::isLeafProc(MachineFunction &MF) const
213213
}
214214

215215
void SparcFrameLowering::remapRegsForLeafProc(MachineFunction &MF) const {
216-
217216
MachineRegisterInfo &MRI = MF.getRegInfo();
218-
219217
// Remap %i[0-7] to %o[0-7].
220218
for (unsigned reg = SP::I0; reg <= SP::I7; ++reg) {
221219
if (MRI.reg_nodbg_empty(reg))
222220
continue;
223-
unsigned mapped_reg = (reg - SP::I0 + SP::O0);
221+
222+
unsigned mapped_reg = reg - SP::I0 + SP::O0;
224223
assert(MRI.reg_nodbg_empty(mapped_reg));
225224

226225
// Replace I register with O register.
227226
MRI.replaceRegWith(reg, mapped_reg);
227+
228+
// Also replace register pair super-registers.
229+
if ((reg - SP::I0) % 2 == 0) {
230+
unsigned preg = (reg - SP::I0) / 2 + SP::I0_I1;
231+
unsigned mapped_preg = preg - SP::I0_I1 + SP::O0_O1;
232+
MRI.replaceRegWith(preg, mapped_preg);
233+
}
228234
}
229235

230236
// Rewrite MBB's Live-ins.
231237
for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
232238
MBB != E; ++MBB) {
239+
for (unsigned reg = SP::I0_I1; reg <= SP::I6_I7; ++reg) {
240+
if (!MBB->isLiveIn(reg))
241+
continue;
242+
MBB->removeLiveIn(reg);
243+
MBB->addLiveIn(reg - SP::I0_I1 + SP::O0_O1);
244+
}
233245
for (unsigned reg = SP::I0; reg <= SP::I7; ++reg) {
234246
if (!MBB->isLiveIn(reg))
235247
continue;

0 commit comments

Comments
 (0)