78 changes: 74 additions & 4 deletions llvm/lib/Target/Sparc/SparcRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ foreach I = 0-3 in

def FSR : SparcCtrlReg<0, "FSR">; // Floating-point state register.

def FQ : SparcCtrlReg<0, "FQ">; // Floating-point deferred-trap queue.

def CPSR : SparcCtrlReg<0, "CPSR">; // Co-processor state register.

def CPQ : SparcCtrlReg<0, "CPQ">; // Co-processor queue.

// Y register
def Y : SparcCtrlReg<0, "Y">, DwarfRegNum<[64]>;
// Ancillary state registers (implementation defined)
Expand Down Expand Up @@ -204,6 +210,40 @@ def D13 : Rd<26, "F26", [F26, F27]>, DwarfRegNum<[85]>;
def D14 : Rd<28, "F28", [F28, F29]>, DwarfRegNum<[86]>;
def D15 : Rd<30, "F30", [F30, F31]>, DwarfRegNum<[87]>;

// Co-processor registers
def C0 : Ri< 0, "C0">;
def C1 : Ri< 1, "C1">;
def C2 : Ri< 2, "C2">;
def C3 : Ri< 3, "C3">;
def C4 : Ri< 4, "C4">;
def C5 : Ri< 5, "C5">;
def C6 : Ri< 6, "C6">;
def C7 : Ri< 7, "C7">;
def C8 : Ri< 8, "C8">;
def C9 : Ri< 9, "C9">;
def C10 : Ri< 10, "C10">;
def C11 : Ri< 11, "C11">;
def C12 : Ri< 12, "C12">;
def C13 : Ri< 13, "C13">;
def C14 : Ri< 14, "C14">;
def C15 : Ri< 15, "C15">;
def C16 : Ri< 16, "C16">;
def C17 : Ri< 17, "C17">;
def C18 : Ri< 18, "C18">;
def C19 : Ri< 19, "C19">;
def C20 : Ri< 20, "C20">;
def C21 : Ri< 21, "C21">;
def C22 : Ri< 22, "C22">;
def C23 : Ri< 23, "C23">;
def C24 : Ri< 24, "C24">;
def C25 : Ri< 25, "C25">;
def C26 : Ri< 26, "C26">;
def C27 : Ri< 27, "C27">;
def C28 : Ri< 28, "C28">;
def C29 : Ri< 29, "C29">;
def C30 : Ri< 30, "C30">;
def C31 : Ri< 31, "C31">;

// Unaliased double precision floating point registers.
// FIXME: Define DwarfRegNum for these registers.
def D16 : SparcReg< 1, "F32">;
Expand Down Expand Up @@ -259,6 +299,24 @@ def I2_I3 : Rdi<26, "I2", [I2, I3]>;
def I4_I5 : Rdi<28, "I4", [I4, I5]>;
def I6_I7 : Rdi<30, "I6", [I6, I7]>;

// Aliases of the co-processor registers used for LDD/STD double-word operations
def C0_C1 : Rdi<0, "C0", [C0, C1]>;
def C2_C3 : Rdi<2, "C2", [C2, C3]>;
def C4_C5 : Rdi<4, "C4", [C4, C5]>;
def C6_C7 : Rdi<6, "C6", [C6, C7]>;
def C8_C9 : Rdi<8, "C8", [C8, C9]>;
def C10_C11 : Rdi<10, "C10", [C10, C11]>;
def C12_C13 : Rdi<12, "C12", [C12, C13]>;
def C14_C15 : Rdi<14, "C14", [C14, C15]>;
def C16_C17 : Rdi<16, "C16", [C16, C17]>;
def C18_C19 : Rdi<18, "C18", [C18, C19]>;
def C20_C21 : Rdi<20, "C20", [C20, C21]>;
def C22_C23 : Rdi<22, "C22", [C22, C23]>;
def C24_C25 : Rdi<24, "C24", [C24, C25]>;
def C26_C27 : Rdi<26, "C26", [C26, C27]>;
def C28_C29 : Rdi<28, "C28", [C28, C29]>;
def C30_C31 : Rdi<30, "C30", [C30, C31]>;

// Register classes.
//
// FIXME: the register order should be defined in terms of the preferred
Expand All @@ -273,6 +331,7 @@ def IntRegs : RegisterClass<"SP", [i32, i64], 32,
(sequence "L%u", 0, 7),
(sequence "O%u", 0, 7))>;


// Should be in the same order as IntRegs.
def IntPair : RegisterClass<"SP", [v2i32], 64,
(add I0_I1, I2_I3, I4_I5, I6_I7,
Expand All @@ -296,10 +355,21 @@ def QFPRegs : RegisterClass<"SP", [f128], 128, (sequence "Q%u", 0, 15)>;
// Floating point control register classes.
def FCCRegs : RegisterClass<"SP", [i1], 1, (sequence "FCC%u", 0, 3)>;

// Ancillary state registers
def ASRRegs : RegisterClass<"SP", [i32], 32,
(add Y, (sequence "ASR%u", 1, 31))> {
let isAllocatable = 0;
let isAllocatable = 0 in {
// Ancillary state registers
def ASRRegs : RegisterClass<"SP", [i32], 32,
(add Y, (sequence "ASR%u", 1, 31))>;

// This register class should not be used to hold i64 values.
def CoprocRegs : RegisterClass<"SP", [i32], 32,
(add (sequence "C%u", 0, 31))>;

// Should be in the same order as CoprocRegs.
def CoprocPair : RegisterClass<"SP", [v2i32], 64,
(add C0_C1, C2_C3, C4_C5, C6_C7,
C8_C9, C10_C11, C12_C13, C14_C15,
C16_C17, C18_C19, C20_C21, C22_C23,
C24_C25, C26_C27, C28_C29, C30_C31)>;
}

// Privileged Registers
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/MC/Disassembler/Sparc/sparc-special-registers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@

# CHECK: wr %i0, 5, %tbr
0x81 0x9e 0x20 0x05

# CHECK: st %fsr, [%i5]
0xc1 0x2f 0x40 0x00

# CHECK: st %csr, [%i5]
0xc1 0xaf 0x40 0x00

# CHECK: std %cq, [%o3+-93]
0xc1 0xb2 0xff 0xa3

# CHECK: std %fq, [%i5+%l1]
0xc1 0x37 0x40 0x11
30 changes: 19 additions & 11 deletions llvm/test/MC/Sparc/sparc-fp-instructions.s
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
faddq %f0, %f4, %f8

! make sure we can handle V9 double registers and their aliased quad registers.
! CHECK: faddd %f32, %f34, %f62 ! encoding: [0xbf,0xa0,0x48,0x43]
! CHECK: faddq %f32, %f36, %f60 ! encoding: [0xbb,0xa0,0x48,0x65]
! CHECK: faddd %f32, %f34, %f62 ! encoding: [0xbf,0xa0,0x48,0x43]
! CHECK: faddq %f32, %f36, %f60 ! encoding: [0xbb,0xa0,0x48,0x65]
faddd %f32, %f34, %f62
faddq %f32, %f36, %f60

Expand Down Expand Up @@ -103,23 +103,23 @@
fcmpd %f0, %f4
fcmpq %f0, %f4

! CHECK: fcmpes %f0, %f4 ! encoding: [0x81,0xa8,0x0a,0xa4]
! CHECK: fcmped %f0, %f4 ! encoding: [0x81,0xa8,0x0a,0xc4]
! CHECK: fcmpeq %f0, %f4 ! encoding: [0x81,0xa8,0x0a,0xe4]
! CHECK: fcmpes %f0, %f4 ! encoding: [0x81,0xa8,0x0a,0xa4]
! CHECK: fcmped %f0, %f4 ! encoding: [0x81,0xa8,0x0a,0xc4]
! CHECK: fcmpeq %f0, %f4 ! encoding: [0x81,0xa8,0x0a,0xe4]
fcmpes %f0, %f4
fcmped %f0, %f4
fcmpeq %f0, %f4

! CHECK: fcmps %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0x24]
! CHECK: fcmpd %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0x44]
! CHECK: fcmpq %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0x64]
! CHECK: fcmps %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0x24]
! CHECK: fcmpd %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0x44]
! CHECK: fcmpq %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0x64]
fcmps %fcc2, %f0, %f4
fcmpd %fcc2, %f0, %f4
fcmpq %fcc2, %f0, %f4

! CHECK: fcmpes %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0xa4]
! CHECK: fcmped %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0xc4]
! CHECK: fcmpeq %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0xe4]
! CHECK: fcmpes %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0xa4]
! CHECK: fcmped %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0xc4]
! CHECK: fcmpeq %fcc2, %f0, %f4 ! encoding: [0x85,0xa8,0x0a,0xe4]
fcmpes %fcc2, %f0, %f4
fcmped %fcc2, %f0, %f4
fcmpeq %fcc2, %f0, %f4
Expand Down Expand Up @@ -147,3 +147,11 @@
! CHECK: std %f48, [%l0] ! encoding: [0xe3,0x3c,0x00,0x00]
st %f29, [%l0]
std %f48, [%l0]

! CHECK: std %fq, [%o4] ! encoding: [0xc1,0x33,0x00,0x00]
! CHECK: std %fq, [%l1+62] ! encoding: [0xc1,0x34,0x60,0x3e]
! CHECK: std %fq, [%i3+%l7] ! encoding: [0xc1,0x36,0xc0,0x17]
std %fq, [%o4]
std %fq, [%l1+62]
std %fq, [%i3+%l7]

3 changes: 3 additions & 0 deletions llvm/test/MC/Sparc/sparc-special-registers.s
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@

! CHECK: st %fsr, [%g2+%i5] ! encoding: [0xc1,0x28,0x80,0x1d]
st %fsr,[%g2 + %i5]

! CHECK: std %fq, [%g6+%i2] ! encoding: [0xc1,0x31,0x80,0x1a]
std %fq, [%g6 + %i2]