Skip to content

Commit 9b86b70

Browse files
author
Baptiste Saleil
committed
[PowerPC] Add accumulator register class and instructions
This patch adds the xxmfacc, xxmtacc and xxsetaccz instructions to manipulate accumulator registers. It also adds the ACC register class definition for the accumulator registers. Differential Revision: https://reviews.llvm.org/D84847
1 parent 7d0556f commit 9b86b70

File tree

8 files changed

+114
-4
lines changed

8 files changed

+114
-4
lines changed

llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ struct PPCOperand : public MCParsedAsmOperand {
290290
return (unsigned) Imm.Val;
291291
}
292292

293+
unsigned getACCReg() const {
294+
assert(isACCRegNumber() && "Invalid access!");
295+
return (unsigned) Imm.Val;
296+
}
297+
293298
unsigned getVSRpEvenReg() const {
294299
assert(isVSRpEvenRegNumber() && "Invalid access!");
295300
return (unsigned) Imm.Val >> 1;
@@ -407,6 +412,9 @@ struct PPCOperand : public MCParsedAsmOperand {
407412
(getImm() & 3) == 0); }
408413
bool isImmZero() const { return Kind == Immediate && getImm() == 0; }
409414
bool isRegNumber() const { return Kind == Immediate && isUInt<5>(getImm()); }
415+
bool isACCRegNumber() const {
416+
return Kind == Immediate && isUInt<3>(getImm());
417+
}
410418
bool isVSRpEvenRegNumber() const {
411419
return Kind == Immediate && isUInt<6>(getImm()) && ((getImm() & 1) == 0);
412420
}
@@ -510,6 +518,11 @@ struct PPCOperand : public MCParsedAsmOperand {
510518
Inst.addOperand(MCOperand::createReg(SPERegs[getReg()]));
511519
}
512520

521+
void addRegACCRCOperands(MCInst &Inst, unsigned N) const {
522+
assert(N == 1 && "Invalid number of operands!");
523+
Inst.addOperand(MCOperand::createReg(ACCRegs[getACCReg()]));
524+
}
525+
513526
void addRegVSRpRCOperands(MCInst &Inst, unsigned N) const {
514527
assert(N == 1 && "Invalid number of operands!");
515528
Inst.addOperand(MCOperand::createReg(VSRpRegs[getVSRpEvenReg()]));

llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ static DecodeStatus DecodeSPERCRegisterClass(MCInst &Inst, uint64_t RegNo,
173173
return decodeRegisterClass(Inst, RegNo, SPERegs);
174174
}
175175

176+
static DecodeStatus DecodeACCRCRegisterClass(MCInst &Inst, uint64_t RegNo,
177+
uint64_t Address,
178+
const void *Decoder) {
179+
return decodeRegisterClass(Inst, RegNo, ACCRegs);
180+
}
181+
176182
static DecodeStatus DecodeVSRpRCRegisterClass(MCInst &Inst, uint64_t RegNo,
177183
uint64_t Address,
178184
const void *Decoder) {

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ static inline bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME) {
124124
#define GET_SUBTARGETINFO_ENUM
125125
#include "PPCGenSubtargetInfo.inc"
126126

127+
#define PPC_REGS0_7(X) \
128+
{ \
129+
X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \
130+
}
131+
127132
#define PPC_REGS0_31(X) \
128133
{ \
129134
X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
@@ -179,8 +184,6 @@ using llvm::MCPhysReg;
179184
PPC::CR5LT, PPC::CR5GT, PPC::CR5EQ, PPC::CR5UN, \
180185
PPC::CR6LT, PPC::CR6GT, PPC::CR6EQ, PPC::CR6UN, \
181186
PPC::CR7LT, PPC::CR7GT, PPC::CR7EQ, PPC::CR7UN}; \
182-
static const MCPhysReg CRRegs[8] = { \
183-
PPC::CR0, PPC::CR1, PPC::CR2, PPC::CR3, \
184-
PPC::CR4, PPC::CR5, PPC::CR6, PPC::CR7}
185-
187+
static const MCPhysReg CRRegs[8] = PPC_REGS0_7(PPC::CR); \
188+
static const MCPhysReg ACCRegs[8] = PPC_REGS0_7(PPC::ACC)
186189
#endif // LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H

llvm/lib/Target/PowerPC/PPCInstrPrefix.td

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,30 @@ multiclass 8LS_DForm_R_XTp5_SI34_MEM_p<bits<6> pref, bits<6> opcode, dag OOL,
586586
isPCRel;
587587
}
588588

589+
def PPCRegACCRCAsmOperand : AsmOperandClass {
590+
let Name = "RegACCRC"; let PredicateMethod = "isACCRegNumber";
591+
}
592+
593+
def acc : RegisterOperand<ACCRC> {
594+
let ParserMatchClass = PPCRegACCRCAsmOperand;
595+
}
596+
597+
// [PO AS XO2 XO]
598+
class XForm_AT3<bits<6> opcode, bits<5> xo2, bits<10> xo, dag OOL, dag IOL,
599+
string asmstr, InstrItinClass itin, list<dag> pattern>
600+
: I<opcode, OOL, IOL, asmstr, itin> {
601+
bits<3> AT;
602+
603+
let Pattern = pattern;
604+
605+
let Inst{6-8} = AT;
606+
let Inst{9-10} = 0;
607+
let Inst{11-15} = xo2;
608+
let Inst{16-20} = 0;
609+
let Inst{21-30} = xo;
610+
let Inst{31} = 0;
611+
}
612+
589613
def PrefixInstrs : Predicate<"Subtarget->hasPrefixInstrs()">;
590614
def IsISA3_1 : Predicate<"Subtarget->isISA3_1()">;
591615
def PairedVectorMemops : Predicate<"Subtarget->pairedVectorMemops()">;
@@ -741,6 +765,25 @@ let Predicates = [PrefixInstrs] in {
741765
}
742766
}
743767

768+
let Predicates = [MMA] in {
769+
def XXMFACC :
770+
XForm_AT3<31, 0, 177, (outs acc:$ASo), (ins acc:$AS), "xxmfacc $AS",
771+
IIC_VecGeneral, []>, RegConstraint<"$ASo = $AS">,
772+
NoEncode<"$ASo">;
773+
def XXMTACC :
774+
XForm_AT3<31, 1, 177, (outs acc:$AT), (ins acc:$ATi), "xxmtacc $AT",
775+
IIC_VecGeneral, []>, RegConstraint<"$ATi = $AT">,
776+
NoEncode<"$ATi">;
777+
// We define XXSETACCZ as rematerializable to undo CSE of that intrinsic in
778+
// the backend. We avoid CSE here because it generates a copy of the acc
779+
// register and this copy is more expensive than calling the intrinsic again.
780+
let isAsCheapAsAMove = 1, isReMaterializable = 1 in {
781+
def XXSETACCZ :
782+
XForm_AT3<31, 3, 177, (outs acc:$AT), (ins), "xxsetaccz $AT",
783+
IIC_VecGeneral, []>;
784+
}
785+
}
786+
744787
let mayLoad = 1, mayStore = 0, Predicates = [PairedVectorMemops] in {
745788
def LXVP : DQForm_XTp5_RA17_MEM<6, 0, (outs vsrprc:$XTp),
746789
(ins memrix16:$DQ_RA), "lxvp $XTp, $DQ_RA",

llvm/lib/Target/PowerPC/PPCRegisterInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ class PPCRegisterInfo : public PPCGenRegisterInfo {
151151
/// register name so that only the number is left. Used by for linux asm.
152152
static const char *stripRegisterPrefix(const char *RegName) {
153153
switch (RegName[0]) {
154+
case 'a':
155+
if (RegName[1] == 'c' && RegName[2] == 'c')
156+
return RegName + 3;
157+
break;
154158
case 'r':
155159
case 'f':
156160
case 'v':

llvm/lib/Target/PowerPC/PPCRegisterInfo.td

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def sub_32 : SubRegIndex<32>;
1818
def sub_64 : SubRegIndex<64>;
1919
def sub_vsx0 : SubRegIndex<128>;
2020
def sub_vsx1 : SubRegIndex<128>;
21+
def sub_pair0 : SubRegIndex<256>;
22+
def sub_pair1 : SubRegIndex<256>;
2123
}
2224

2325

@@ -96,6 +98,12 @@ class CRBIT<bits<5> num, string n> : PPCReg<n> {
9698
let HWEncoding{4-0} = num;
9799
}
98100

101+
// ACC - One of the 8 512-bit VSX accumulators.
102+
class ACC<bits<3> num, string n, list<Register> subregs> : PPCReg<n> {
103+
let HWEncoding{2-0} = num;
104+
let SubRegs = subregs;
105+
}
106+
99107
// VSR Pairs - One of the 32 paired even-odd consecutive VSRs.
100108
class VSRPair<bits<5> num, string n, list<Register> subregs> : PPCReg<n> {
101109
let HWEncoding{4-0} = num;
@@ -397,6 +405,21 @@ def CARRYRC : RegisterClass<"PPC", [i32], 32, (add CARRY, XER)> {
397405
let CopyCost = -1;
398406
}
399407

408+
let SubRegIndices = [sub_pair0, sub_pair1] in {
409+
def ACC0 : ACC<0, "acc0", [VSRp0, VSRp1]>, DwarfRegNum<[0, 0]>;
410+
def ACC1 : ACC<1, "acc1", [VSRp2, VSRp3]>, DwarfRegNum<[0, 0]>;
411+
def ACC2 : ACC<2, "acc2", [VSRp4, VSRp5]>, DwarfRegNum<[0, 0]>;
412+
def ACC3 : ACC<3, "acc3", [VSRp6, VSRp7]>, DwarfRegNum<[0, 0]>;
413+
def ACC4 : ACC<4, "acc4", [VSRp8, VSRp9]>, DwarfRegNum<[0, 0]>;
414+
def ACC5 : ACC<5, "acc5", [VSRp10, VSRp11]>, DwarfRegNum<[0, 0]>;
415+
def ACC6 : ACC<6, "acc6", [VSRp12, VSRp13]>, DwarfRegNum<[0, 0]>;
416+
def ACC7 : ACC<7, "acc7", [VSRp14, VSRp15]>, DwarfRegNum<[0, 0]>;
417+
}
418+
def ACCRC : RegisterClass<"PPC", [v512i1], 128, (add ACC0, ACC1, ACC2, ACC3,
419+
ACC4, ACC5, ACC6, ACC7)> {
420+
let Size = 512;
421+
}
422+
400423
// Allocate in the same order as the underlying VSX registers.
401424
def VSRpRC :
402425
RegisterClass<"PPC", [v256i1], 128,

llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
# CHECK: pstxv 33, 8589934591(0), 1
2626
0x04 0x11 0xff 0xff 0xdc 0x20 0xff 0xff
2727

28+
# CHECK: xxmfacc 0
29+
0x7c 0x00 0x01 0x62
30+
31+
# CHECK: xxmtacc 0
32+
0x7c 0x01 0x01 0x62
33+
34+
# CHECK: xxsetaccz 0
35+
0x7c 0x03 0x01 0x62
36+
2837
# CHECK: lxvp 2, 32(4)
2938
0x18 0x44 0x00 0x20
3039

llvm/test/MC/PowerPC/ppc64-encoding-ISA31.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
# CHECK-LE: pstxv 33, -8589934592(31), 0 # encoding: [0x00,0x00,0x02,0x04
2424
# CHECK-LE-SAME: 0x00,0x00,0x3f,0xdc]
2525
pstxv 33, -8589934592(31), 0
26+
# CHECK-BE: xxmfacc 2 # encoding: [0x7d,0x00,0x01,0x62]
27+
# CHECK-LE: xxmfacc 2 # encoding: [0x62,0x01,0x00,0x7d]
28+
xxmfacc 2
29+
# CHECK-BE: xxmtacc 2 # encoding: [0x7d,0x01,0x01,0x62]
30+
# CHECK-LE: xxmtacc 2 # encoding: [0x62,0x01,0x01,0x7d]
31+
xxmtacc 2
32+
# CHECK-BE: xxsetaccz 1 # encoding: [0x7c,0x83,0x01,0x62]
33+
# CHECK-LE: xxsetaccz 1 # encoding: [0x62,0x01,0x83,0x7c]
34+
xxsetaccz 1
2635
# CHECK-BE: lxvp 2, 32(4) # encoding: [0x18,0x44,0x00,0x20]
2736
# CHECK-LE: lxvp 2, 32(4) # encoding: [0x20,0x00,0x44,0x18]
2837
lxvp 2, 32(4)

0 commit comments

Comments
 (0)