1*e8d8bef9SDimitry Andric//===-- CSKYInstrInfo.td - Target Description for CSKY -----*- tablegen -*-===// 2*e8d8bef9SDimitry Andric// 3*e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5*e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e8d8bef9SDimitry Andric// 7*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 8*e8d8bef9SDimitry Andric// 9*e8d8bef9SDimitry Andric// This file describes the CSKY instructions in TableGen format. 10*e8d8bef9SDimitry Andric// 11*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 12*e8d8bef9SDimitry Andric 13*e8d8bef9SDimitry Andricinclude "CSKYInstrFormats.td" 14*e8d8bef9SDimitry Andric 15*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 16*e8d8bef9SDimitry Andric// CSKY specific DAG Nodes. 17*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 18*e8d8bef9SDimitry Andric 19*e8d8bef9SDimitry Andric// TODO: Add CSKY specific DAG Nodes. 20*e8d8bef9SDimitry Andric 21*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 22*e8d8bef9SDimitry Andric// Operand and SDNode transformation definitions. 23*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 24*e8d8bef9SDimitry Andric 25*e8d8bef9SDimitry Andricclass oimm<int num> : Operand<i32>, 26*e8d8bef9SDimitry Andric ImmLeaf<i32, "return isUInt<"#num#">(Imm - 1);"> { 27*e8d8bef9SDimitry Andric let EncoderMethod = "getOImmOpValue"; 28*e8d8bef9SDimitry Andric} 29*e8d8bef9SDimitry Andric 30*e8d8bef9SDimitry Andricclass uimm<int num, int shift = 0> : Operand<i32>, 31*e8d8bef9SDimitry Andric ImmLeaf<i32, "return isShiftedUInt<"#num#", "#shift#">(Imm);"> { 32*e8d8bef9SDimitry Andric let EncoderMethod = "getImmOpValue<"#shift#">"; 33*e8d8bef9SDimitry Andric} 34*e8d8bef9SDimitry Andric 35*e8d8bef9SDimitry Andricclass simm<int num, int shift = 0> : Operand<i32>, 36*e8d8bef9SDimitry Andric ImmLeaf<i32, "return isShiftedInt<"#num#", "#shift#">(Imm);"> { 37*e8d8bef9SDimitry Andric let EncoderMethod = "getImmOpValue<"#shift#">"; 38*e8d8bef9SDimitry Andric} 39*e8d8bef9SDimitry Andric 40*e8d8bef9SDimitry Andricdef nimm_XFORM : SDNodeXForm<imm, [{ 41*e8d8bef9SDimitry Andric return CurDAG->getTargetConstant(~N->getSExtValue(), SDLoc(N), MVT::i32); 42*e8d8bef9SDimitry Andric}]>; 43*e8d8bef9SDimitry Andricclass nimm<int num> : Operand<i32>, 44*e8d8bef9SDimitry Andric ImmLeaf<i32, "return isUInt<"#num#">(~Imm);", nimm_XFORM> { 45*e8d8bef9SDimitry Andric} 46*e8d8bef9SDimitry Andric 47*e8d8bef9SDimitry Andric 48*e8d8bef9SDimitry Andricdef oimm12 : oimm<12>; 49*e8d8bef9SDimitry Andric 50*e8d8bef9SDimitry Andricdef nimm12 : nimm<12>; 51*e8d8bef9SDimitry Andric 52*e8d8bef9SDimitry Andricdef uimm5 : uimm<5>; 53*e8d8bef9SDimitry Andricdef uimm12 : uimm<12>; 54*e8d8bef9SDimitry Andric 55*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 56*e8d8bef9SDimitry Andric// Instruction definitions. 57*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 58*e8d8bef9SDimitry Andric 59*e8d8bef9SDimitry Andricclass TriOpFrag<dag res> : PatFrag<(ops node: $LHS, node:$MHS, node:$RHS), res>; 60*e8d8bef9SDimitry Andricclass BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>; 61*e8d8bef9SDimitry Andricclass UnOpFrag<dag res> : PatFrag<(ops node:$Src), res>; 62*e8d8bef9SDimitry Andric 63*e8d8bef9SDimitry Andricdef ADDI32 : I_12<0x0, "addi32", add, oimm12>; 64*e8d8bef9SDimitry Andricdef SUBI32 : I_12<0x1, "subi32", sub, oimm12>; 65*e8d8bef9SDimitry Andricdef ANDI32 : I_12<0x2, "andi32", and, uimm12>; 66*e8d8bef9SDimitry Andricdef ANDNI32 : I_12<0x3, "andni32", and, nimm12>; 67*e8d8bef9SDimitry Andricdef XORI32 : I_12<0x4, "xori32", xor, uimm12>; 68*e8d8bef9SDimitry Andricdef LSLI32 : I_5_XZ<0x12, 0x1, "lsli32", 69*e8d8bef9SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 70*e8d8bef9SDimitry Andric [(set GPR:$rz, (shl GPR:$rx, uimm5:$imm5))]>; 71*e8d8bef9SDimitry Andricdef LSRI32 : I_5_XZ<0x12, 0x2, "lsri32", 72*e8d8bef9SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 73*e8d8bef9SDimitry Andric [(set GPR:$rz, (srl GPR:$rx, uimm5:$imm5))]>; 74*e8d8bef9SDimitry Andricdef ASRI32 : I_5_XZ<0x12, 0x4, "asri32", 75*e8d8bef9SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 76*e8d8bef9SDimitry Andric [(set GPR:$rz, (sra GPR:$rx, uimm5:$imm5))]>; 77*e8d8bef9SDimitry Andric 78*e8d8bef9SDimitry Andric 79*e8d8bef9SDimitry Andric 80*e8d8bef9SDimitry Andricdef ADDU32 : R_YXZ_SP_F1<0x0, 0x1, 81*e8d8bef9SDimitry Andric BinOpFrag<(add node:$LHS, node:$RHS)>, "addu32", 1>; 82*e8d8bef9SDimitry Andricdef SUBU32 : R_YXZ_SP_F1<0x0, 0x4, 83*e8d8bef9SDimitry Andric BinOpFrag<(sub node:$LHS, node:$RHS)>, "subu32">; 84*e8d8bef9SDimitry Andricdef AND32 : R_YXZ_SP_F1<0x8, 0x1, 85*e8d8bef9SDimitry Andric BinOpFrag<(and node:$LHS, node:$RHS)>, "and32", 1>; 86*e8d8bef9SDimitry Andricdef ANDN32 : R_YXZ_SP_F1<0x8, 0x2, 87*e8d8bef9SDimitry Andric BinOpFrag<(and node:$LHS, (not node:$RHS))>, "andn32">; 88*e8d8bef9SDimitry Andricdef OR32: R_YXZ_SP_F1<0x9, 0x1, 89*e8d8bef9SDimitry Andric BinOpFrag<(or node:$LHS, node:$RHS)>, "or32", 1>; 90*e8d8bef9SDimitry Andricdef XOR32 : R_YXZ_SP_F1<0x9, 0x2, 91*e8d8bef9SDimitry Andric BinOpFrag<(xor node:$LHS, node:$RHS)>, "xor32", 1>; 92*e8d8bef9SDimitry Andricdef NOR32 : R_YXZ_SP_F1<0x9, 0x4, 93*e8d8bef9SDimitry Andric BinOpFrag<(not (or node:$LHS, node:$RHS))>, "nor32", 1>; 94*e8d8bef9SDimitry Andricdef LSL32 : R_YXZ_SP_F1<0x10, 0x1, 95*e8d8bef9SDimitry Andric BinOpFrag<(shl node:$LHS, node:$RHS)>, "lsl32">; 96*e8d8bef9SDimitry Andricdef LSR32 : R_YXZ_SP_F1<0x10, 0x2, 97*e8d8bef9SDimitry Andric BinOpFrag<(srl node:$LHS, node:$RHS)>, "lsr32">; 98*e8d8bef9SDimitry Andricdef ASR32 : R_YXZ_SP_F1<0x10, 0x4, 99*e8d8bef9SDimitry Andric BinOpFrag<(sra node:$LHS, node:$RHS)>, "asr32">; 100*e8d8bef9SDimitry Andricdef MULT32 : R_YXZ_SP_F1<0x21, 0x1, 101*e8d8bef9SDimitry Andric BinOpFrag<(mul node:$LHS, node:$RHS)>, "mult32", 1>; 102*e8d8bef9SDimitry Andricdef DIVS32 : R_YXZ_SP_F1<0x20, 0x2, 103*e8d8bef9SDimitry Andric BinOpFrag<(sdiv node:$LHS, node:$RHS)>, "divs32">; 104*e8d8bef9SDimitry Andricdef DIVU32 : R_YXZ_SP_F1<0x20, 0x1, 105*e8d8bef9SDimitry Andric BinOpFrag<(udiv node:$LHS, node:$RHS)>, "divu32">; 106*e8d8bef9SDimitry Andric 107*e8d8bef9SDimitry Andricdef NOT32 : R_XXZ<0b001001, 0b00100, (outs GPR:$rz), (ins GPR:$rx), 108*e8d8bef9SDimitry Andric "not", [(set GPR:$rz, (not GPR:$rx))]>; 109