Skip to content

Commit

Permalink
[Sparc] Add trap on integer condition codes (Ticc) instructions to Sp…
Browse files Browse the repository at this point in the history
…arc backend.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202670 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vegovin committed Mar 2, 2014
1 parent 75bff89 commit c594f39
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/Target/Sparc/SparcInstr64Bit.td
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ def ATOMIC_SWAP_64 : Pseudo<(outs I64Regs:$rd),
[(set i64:$rd,
(atomic_swap_64 iPTR:$addr, i64:$rs2))]>;

let Predicates = [Is64Bit], hasSideEffects = 1, Uses = [ICC], cc = 0b10 in
defm TXCC : TRAP<"%xcc">;

// Global addresses, constant pool entries
let Predicates = [Is64Bit] in {

Expand Down
56 changes: 55 additions & 1 deletion lib/Target/Sparc/SparcInstrAliases.td
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,59 @@ multiclass int_cond_alias<string cond, int condVal> {
(FMOVQ_XCC QFPRegs:$rd, QFPRegs:$rs2, condVal)>,
Requires<[Is64Bit, HasHardQuad]>;

// t<cond> %icc, rs1 + rs2
def : InstAlias<!strconcat(!strconcat("t", cond), " %icc, $rs1 + $rs2"),
(TICCrr IntRegs:$rs1, IntRegs:$rs2, condVal)>,
Requires<[HasV9]>;

// t<cond> %icc, rs => t<cond> %icc, G0 + rs
def : InstAlias<!strconcat(!strconcat("t", cond), " %icc, $rs2"),
(TICCrr G0, IntRegs:$rs2, condVal)>,
Requires<[HasV9]>;

// t<cond> %xcc, rs1 + rs2
def : InstAlias<!strconcat(!strconcat("t", cond), " %xcc, $rs1 + $rs2"),
(TXCCrr IntRegs:$rs1, IntRegs:$rs2, condVal)>,
Requires<[HasV9]>;

// t<cond> %xcc, rs => t<cond> %xcc, G0 + rs
def : InstAlias<!strconcat(!strconcat("t", cond), " %xcc, $rs2"),
(TXCCrr G0, IntRegs:$rs2, condVal)>,
Requires<[HasV9]>;

// t<cond> rs1 + rs2 => t<cond> %icc, rs1 + rs2
def : InstAlias<!strconcat(!strconcat("t", cond), " $rs1 + $rs2"),
(TICCrr IntRegs:$rs1, IntRegs:$rs2, condVal)>;

// t<cond> rs=> t<cond> %icc, G0 + rs2
def : InstAlias<!strconcat(!strconcat("t", cond), " $rs2"),
(TICCrr G0, IntRegs:$rs2, condVal)>;

// t<cond> %icc, rs1 + imm
def : InstAlias<!strconcat(!strconcat("t", cond), " %icc, $rs1 + $imm"),
(TICCri IntRegs:$rs1, i32imm:$imm, condVal)>,
Requires<[HasV9]>;
// t<cond> %icc, imm => t<cond> %icc, G0 + imm
def : InstAlias<!strconcat(!strconcat("t", cond), " %icc, $imm"),
(TICCri G0, i32imm:$imm, condVal)>,
Requires<[HasV9]>;
// t<cond> %xcc, rs1 + imm
def : InstAlias<!strconcat(!strconcat("t", cond), " %xcc, $rs1 + $imm"),
(TXCCri IntRegs:$rs1, i32imm:$imm, condVal)>,
Requires<[HasV9]>;
// t<cond> %xcc, imm => t<cond> %xcc, G0 + imm
def : InstAlias<!strconcat(!strconcat("t", cond), " %xcc, $imm"),
(TXCCri G0, i32imm:$imm, condVal)>,
Requires<[HasV9]>;

// t<cond> rs1 + imm => t<cond> %icc, rs1 + imm
def : InstAlias<!strconcat(!strconcat("t", cond), " $rs1 + $imm"),
(TICCri IntRegs:$rs1, i32imm:$imm, condVal)>;

// t<cond> imm => t<cond> %icc, G0 + imm
def : InstAlias<!strconcat(!strconcat("t", cond), " $imm"),
(TICCri G0, i32imm:$imm, condVal)>;

}


Expand Down Expand Up @@ -177,7 +230,8 @@ multiclass fp_cond_alias<string cond, int condVal> {

// fb<cond>,a,pn %fcc0, $imm
def : InstAlias<!strconcat(!strconcat("fb", cond), ",a,pn $cc, $imm"),
(BPFCCANT brtarget:$imm, condVal, FCCRegs:$cc)>, Requires<[HasV9]>;
(BPFCCANT brtarget:$imm, condVal, FCCRegs:$cc)>,
Requires<[HasV9]>;

defm : fpcond_mov_alias<cond, condVal,
V9MOVFCCrr, V9MOVFCCri,
Expand Down
31 changes: 31 additions & 0 deletions lib/Target/Sparc/SparcInstrFormats.td
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,34 @@ class F4_4i<bits<6> op3, bits<3> rcond, dag outs, dag ins,
let Inst{12-10} = rcond;
let Inst{9-0} = simm10;
}


class TRAPSP<bits<6> op3Val, bit isimm, dag outs, dag ins, string asmstr,
list<dag> pattern>: F3<outs, ins, asmstr, pattern> {

bits<4> cond;
bits<2> cc;

let op = 0b10;
let rd{4} = 0;
let rd{3-0} = cond;
let op3 = op3Val;
let Inst{13} = isimm;
let Inst{12-11} = cc;

}

class TRAPSPrr<bits<6> op3Val, dag outs, dag ins, string asmstr,
list<dag> pattern>: TRAPSP<op3Val, 0, outs, ins, asmstr, pattern> {
bits<5> rs2;

let Inst{10-5} = 0;
let Inst{4-0} = rs2;
}
class TRAPSPri<bits<6> op3Val, dag outs, dag ins, string asmstr,
list<dag> pattern>: TRAPSP<op3Val, 1, outs, ins, asmstr, pattern> {
bits<8> imm;

let Inst{10-8} = 0;
let Inst{7-0} = imm;
}
12 changes: 12 additions & 0 deletions lib/Target/Sparc/SparcInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,18 @@ let hasSideEffects = 1 in {
}
}

multiclass TRAP<string regStr> {
def rr : TRAPSPrr<0b111010, (outs), (ins IntRegs:$rs1, IntRegs:$rs2,
CCOp:$cond),
!strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $rs2"), []>;
def ri : TRAPSPri<0b111010, (outs), (ins IntRegs:$rs1, i32imm:$imm,
CCOp:$cond),
!strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $imm"), []>;
}

let hasSideEffects = 1, Uses = [ICC], cc = 0b00 in
defm TICC : TRAP<"%icc">;

//===----------------------------------------------------------------------===//
// Non-Instruction Patterns
//===----------------------------------------------------------------------===//
Expand Down
7 changes: 7 additions & 0 deletions test/MC/Sparc/sparc64-ctrl-instructions.s
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,10 @@

! CHECK: rett %i7+8 ! encoding: [0x81,0xcf,0xe0,0x08]
return %i7 + 8

! CHECK: ta %icc, %g0 + 5 ! encoding: [0x91,0xd0,0x20,0x05]
ta 5

! CHECK: te %xcc, %g0 + 3 ! encoding: [0x83,0xd0,0x30,0x03]
te %xcc, 3

0 comments on commit c594f39

Please sign in to comment.