66 lines · plain
1//===-- RISCVInstrInfoZibi.td - 'Zibi' instructions --------*- tablegen -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// This file describes the RISC-V instructions for 'Zibi' (branch with imm).10///11//===----------------------------------------------------------------------===//12 13// A 5-bit unsigned immediate representing 1-31 and -1. 00000 represents -1.14def imm5_zibi : RISCVOp<XLenVT>, ImmLeaf<XLenVT, [{15 return (Imm != 0 && isUInt<5>(Imm)) || Imm == -1;16}]> {17 let ParserMatchClass = ImmAsmOperand<"", 5, "Zibi">;18 let EncoderMethod = "getImmOpValueZibi";19 let DecoderMethod = "decodeImmZibiOperand";20 let MCOperandPredicate = [{21 int64_t Imm;22 if (!MCOp.evaluateAsConstantImm(Imm))23 return false;24 return (Imm >= 1 && Imm <= 31) || Imm == -1;25 }];26 let OperandType = "OPERAND_IMM5_ZIBI";27}28 29class Branch_imm<bits<3> funct3, string opcodestr>30 : RVInstBIMM<funct3, OPC_BRANCH, (outs),31 (ins GPR:$rs1, imm5_zibi:$cimm, bare_simm13_lsb0:$imm12),32 opcodestr, "$rs1, $cimm, $imm12">,33 Sched<[WriteJmp, ReadJmp]> {34 let isBranch = 1;35 let isTerminator = 1;36 let hasSideEffects = 0;37 let mayLoad = 0;38 let mayStore = 0;39}40 41let Predicates = [HasStdExtZibi] in {42 def BEQI : Branch_imm<0b010, "beqi">;43 def BNEI : Branch_imm<0b011, "bnei">;44} // Predicates = [HasStdExtZibi]45 46multiclass BccImmPat<CondCode Cond, Branch_imm Inst> {47 def : Pat<(riscv_brcc (XLenVT GPR:$rs1), imm5_zibi:$cimm, Cond, bb:$imm12),48 (Inst GPR:$rs1, imm5_zibi:$cimm, bare_simm13_lsb0_bb:$imm12)>;49}50 51defm CC_Imm5_Zibi : SelectCC_GPR_riirr<GPR, imm5_zibi>;52 53class SelectZibi<CondCode Cond>54 : Pat<(riscv_selectcc_frag:$cc (XLenVT GPR:$lhs), imm5_zibi:$cimm, Cond,55 (XLenVT GPR:$truev), GPR:$falsev),56 (Select_GPR_Using_CC_Imm5_Zibi GPR:$lhs, imm5_zibi:$cimm,57 (IntCCtoRISCVCC $cc), GPR:$truev, GPR:$falsev)>;58 59let Predicates = [HasStdExtZibi] in {60 def : SelectZibi<SETEQ>;61 def : SelectZibi<SETNE>;62 63 defm : BccImmPat<SETEQ, BEQI>;64 defm : BccImmPat<SETNE, BNEI>;65} // Predicates = [HasStdExtZibi]66