diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -45,6 +45,7 @@ // CHECK-NOT: __riscv_zk // CHECK-NOT: __riscv_zicbom // CHECK-NOT: __riscv_zicboz +// CHECK-NOT: __riscv_zcmp // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s @@ -462,3 +463,10 @@ // RUN: %clang -target riscv64 -march=rv64izicbop -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOP-EXT %s // CHECK-ZICBOP-EXT: __riscv_zicbop 1000000{{$}} + +// RUN: %clang -target riscv32 -march=rv32izcmp0p70 -menable-experimental-extensions \ +// RUN: -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-ZCMP-EXT %s +// RUN: %clang -target riscv64 -march=rv64izcmp0p70 -menable-experimental-extensions \ +// RUN: -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-ZCMP-EXT %s +// CHECK-ZCMP-EXT: __riscv_zca 70000{{$}} +// CHECK-ZCMP-EXT: __riscv_zcmp 70000{{$}} \ No newline at end of file diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -114,6 +114,7 @@ {"zbt", RISCVExtensionVersion{0, 93}}, {"zca", RISCVExtensionVersion{0, 70}}, {"zcb", RISCVExtensionVersion{0, 70}}, + {"zcmp", RISCVExtensionVersion{0, 70}}, {"zvfh", RISCVExtensionVersion{0, 1}}, }; @@ -779,6 +780,7 @@ static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"}; static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"}; static const char *ImpliedExtsZvfh[] = {"zve32f"}; +static const char *ImpliedExtsZcmp[] = {"zca"}; struct ImpliedExtsEntry { StringLiteral Name; @@ -794,6 +796,7 @@ // Note: The table needs to be sorted by name. static constexpr ImpliedExtsEntry ImpliedExts[] = { {{"v"}, {ImpliedExtsV}}, + {{"zcmp"}, {ImpliedExtsZcmp}}, {{"zdinx"}, {ImpliedExtsZdinx}}, {{"zfh"}, {ImpliedExtsZfh}}, {{"zfhmin"}, {ImpliedExtsZfhmin}}, diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -172,6 +172,9 @@ OperandMatchResultTy parseMaskReg(OperandVector &Operands); OperandMatchResultTy parseInsnDirectiveOpcode(OperandVector &Operands); OperandMatchResultTy parseGPRAsFPR(OperandVector &Operands); + OperandMatchResultTy parseReglist(OperandVector &Operands); + OperandMatchResultTy parseRetval(OperandVector &Operands); + OperandMatchResultTy parseZceSpimm(OperandVector &Operands); bool parseOperand(OperandVector &Operands, StringRef Mnemonic); @@ -276,6 +279,8 @@ Immediate, SystemRegister, VType, + Rlist, + Spimm, } Kind; bool IsRV64; @@ -302,6 +307,15 @@ unsigned Val; }; + struct RlistOp { + bool isCInst; + unsigned Val; + }; + + struct SpimmOp { + unsigned Val; + }; + SMLoc StartLoc, EndLoc; union { StringRef Tok; @@ -309,6 +323,8 @@ ImmOp Imm; struct SysRegOp SysReg; struct VTypeOp VType; + struct RlistOp Rlist; + struct SpimmOp Spimm; }; RISCVOperand(KindTy K) : Kind(K) {} @@ -335,6 +351,12 @@ case KindTy::VType: VType = o.VType; break; + case KindTy::Rlist: + Rlist = o.Rlist; + break; + case KindTy::Spimm: + Spimm = o.Spimm; + break; } } @@ -346,6 +368,8 @@ bool isImm() const override { return Kind == KindTy::Immediate; } bool isMem() const override { return false; } bool isSystemRegister() const { return Kind == KindTy::SystemRegister; } + bool isRlist() const { return Kind == KindTy::Rlist; } + bool isSpimm() const { return Kind == KindTy::Spimm; } bool isGPR() const { return Kind == KindTy::Register && @@ -840,6 +864,16 @@ RISCVVType::printVType(getVType(), OS); OS << '>'; break; + case KindTy::Rlist: + OS << "'; + break; + case KindTy::Spimm: + OS << "{Spimm: "; + RISCVZCE::printSpimm(Spimm.Val, OS); + OS << '}'; + break; } } @@ -897,6 +931,25 @@ return Op; } + static std::unique_ptr + createRlist(unsigned RlistEncode, SMLoc S, bool IsRV64, bool isCInst) { + auto Op = std::make_unique(KindTy::Rlist); + Op->Rlist.Val = RlistEncode; + Op->Rlist.isCInst = isCInst; + Op->StartLoc = S; + Op->IsRV64 = IsRV64; + return Op; + } + + static std::unique_ptr createSpimm(unsigned spimm, SMLoc S, + bool IsRV64) { + auto Op = std::make_unique(KindTy::Spimm); + Op->Spimm.Val = spimm; + Op->StartLoc = S; + Op->IsRV64 = IsRV64; + return Op; + } + void addExpr(MCInst &Inst, const MCExpr *Expr) const { assert(Expr && "Expr shouldn't be null!"); int64_t Imm = 0; @@ -980,6 +1033,16 @@ Inst.addOperand(MCOperand::createImm(Imm)); } + void addRlistOperands(MCInst &Inst, unsigned N) const { + assert(N == 1 && "Invalid number of operands!"); + Inst.addOperand(MCOperand::createImm(Rlist.Val)); + } + + void addSpimmOperands(MCInst &Inst, unsigned N) const { + assert(N == 1 && "Invalid number of operands!"); + Inst.addOperand(MCOperand::createImm(Spimm.Val)); + } + // Returns the rounding mode represented by this RISCVOperand. Should only // be called after checking isFRMArg. RISCVFPRndMode::RoundingMode getRoundingMode() const { @@ -1292,6 +1355,18 @@ (1 << 4), "immediate must be in the range"); } + case Match_InvalidRlist: { + SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); + return Error(ErrorLoc, "operand must be {}, {a0}, or {a0-a[1|2|3]}"); + } + case Match_InvalidSpimm: { + SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); + return Error( + ErrorLoc, + "This stack adjustment is invalid for this instruction and register " + "list, " + "Please refer to Zce spec for a detailed range of stack adjustment."); + } case Match_InvalidRnumArg: { return generateImmOutOfRangeError(Operands, ErrorInfo, 0, 10); } @@ -1935,6 +2010,115 @@ return MatchOperand_Success; } +OperandMatchResultTy RISCVAsmParser::parseReglist(OperandVector &Operands) { + // Rlist grammar: {ra [, s0[-sN]]} (UABI) + // XRlist :{x1 [, x8[-x9][, x18[-xN]]]} (UABI) + SMLoc S = getLoc(); + if (getLexer().isNot(AsmToken::LCurly)) + return MatchOperand_NoMatch; + getLexer().Lex(); // eat '{' + bool IsEmptyList = getLexer().is(AsmToken::RCurly); + + StringRef Memonic = + static_cast(Operands.front().get())->getToken(); + bool Is16Bit = Memonic.startswith("cm."); + bool IsEABI = isRV32E() || Memonic.endswith(".e"); + bool IsXReglist = Memonic.find("x"); + + MCRegister RegStart = RISCV::NoRegister; + MCRegister RegEnd = RISCV::NoRegister; + if (!IsEmptyList) { + StringRef RegName = getLexer().getTok().getIdentifier(); + matchRegisterNameHelper(IsEABI, RegStart, RegName); + if (RegStart != RISCV::X1) + return MatchOperand_NoMatch; + getLexer().Lex(); + } + + // parse case like ,s0 + if (getLexer().is(AsmToken::Comma)) { + getLexer().Lex(); + if (getLexer().isNot(AsmToken::Identifier)) + return MatchOperand_NoMatch; + StringRef RegName = getLexer().getTok().getIdentifier(); + if (matchRegisterNameHelper(/*IsEABI*/ false, RegStart, RegName)) + return MatchOperand_NoMatch; + if (RegStart != RISCV::X8) + return MatchOperand_NoMatch; + getLexer().Lex(); // eat reg + } + + // parse case like -s1 + if (getLexer().is(AsmToken::Minus)) { + getLexer().Lex(); + StringRef EndName = getLexer().getTok().getIdentifier(); + // FixMe: the register mapping and checks of EABI is wrong + if (matchRegisterNameHelper(/*IsEABI*/ false, RegEnd, EndName)) + return MatchOperand_NoMatch; + getLexer().Lex(); + } + + // parse extra part like ', x18[-x20]' for XRegList + if (IsXReglist && getLexer().is(AsmToken::Comma)) { + if (RegEnd != RISCV::X9) + return MatchOperand_NoMatch; + + // parse ', x18' for extra part + getLexer().Lex(); + if (getLexer().isNot(AsmToken::Identifier)) + return MatchOperand_NoMatch; + StringRef EndName = getLexer().getTok().getIdentifier(); + if (MatchRegisterName(EndName) != RISCV::X18) + return MatchOperand_NoMatch; + getLexer().Lex(); + + // parse '-x20' for extra part + if (getLexer().is(AsmToken::Minus)) { + getLexer().Lex(); + if (getLexer().isNot(AsmToken::Identifier)) + return MatchOperand_NoMatch; + EndName = getLexer().getTok().getIdentifier(); + if (MatchRegisterName(EndName) == RISCV::NoRegister) + return MatchOperand_NoMatch; + getLexer().Lex(); + } + RegEnd = MatchRegisterName(EndName); + } + + if (getLexer().isNot(AsmToken::RCurly)) + return MatchOperand_NoMatch; + getLexer().Lex(); // eat '}' + + if (RegEnd == RISCV::NoRegister) + RegEnd = RegStart; + + auto Encode = RISCVZCE::encodeRlist(RegEnd, Is16Bit, IsEABI); + if (Encode == 16) + Error(getLoc(), "invalid register list, {ra, s0-s10} is not supported."); + Operands.push_back(RISCVOperand::createRlist(Encode, S, isRV64(), Is16Bit)); + + return MatchOperand_Success; +} + +OperandMatchResultTy RISCVAsmParser::parseZceSpimm(OperandVector &Operands) { + if (getLexer().is(AsmToken::Minus)) + getLexer().Lex(); + + SMLoc S = getLoc(); + + StringRef Memonic = + static_cast(Operands.front().get())->getToken(); + int64_t StackAdjustment = getLexer().getTok().getIntVal(); + unsigned Spimm = 0; + unsigned RlistVal = static_cast(Operands[1].get())->Rlist.Val; + + bool IsEABI = isRV32E() || Memonic.endswith(".e"); + if (!RISCVZCE::getSpimm(RlistVal, Spimm, StackAdjustment, isRV64(), IsEABI)) + return MatchOperand_NoMatch; + Operands.push_back(RISCVOperand::createSpimm(Spimm << 4, S, isRV64())); + getLexer().Lex(); + return MatchOperand_Success; +} /// Looks at a token type and creates the relevant operand from this /// information, adding to Operands. If operand was parsed, returns false, else @@ -2807,7 +2991,16 @@ .addImm(Imm - 1) .addOperand(Inst.getOperand(3))); } - + return false; + } + case RISCV::CM_POPRET: + case RISCV::CM_POPRETZ: + case RISCV::CM_POP: + case RISCV::CM_PUSH: { + unsigned Opc = Inst.getOpcode(); + emitToStreamer(Out, MCInstBuilder(Opc) + .addOperand(Inst.getOperand(0)) + .addOperand(Inst.getOperand(1))); return false; } } diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp --- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp +++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp @@ -170,6 +170,17 @@ return MCDisassembler::Success; } +static DecodeStatus DecodeSR07RegisterClass(MCInst &Inst, uint64_t RegNo, + uint64_t Address, + const void *Decoder) { + if (RegNo >= 8) + return MCDisassembler::Fail; + + MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18); + Inst.addOperand(MCOperand::createReg(Reg)); + return MCDisassembler::Success; +} + static DecodeStatus DecodeVRRegisterClass(MCInst &Inst, uint64_t RegNo, uint64_t Address, const MCDisassembler *Decoder) { @@ -369,6 +380,12 @@ uint64_t Address, const MCDisassembler *Decoder); +static DecodeStatus decodeZceRlist(MCInst &Inst, unsigned Imm, uint64_t Address, + const void *Decoder); + +static DecodeStatus decodeZceSpimm(MCInst &Inst, unsigned Imm, uint64_t Address, + const void *Decoder); + #include "RISCVGenDisassemblerTables.inc" static DecodeStatus decodeRVCInstrSImm(MCInst &Inst, unsigned Insn, @@ -428,6 +445,23 @@ return MCDisassembler::Success; } +static DecodeStatus decodeZceRlist(MCInst &Inst, unsigned Imm, uint64_t Address, + const void *Decoder) { + // Sign-extend the number in the bottom N bits of Imm + if (Imm <= 3) + return MCDisassembler::Fail; + Inst.addOperand(MCOperand::createImm(Imm)); + return MCDisassembler::Success; +} + +// spimm is based on rlist now. +static DecodeStatus decodeZceSpimm(MCInst &Inst, unsigned Imm, uint64_t Address, + const void *Decoder) { + // TODO: check if spimm matches rlist + Inst.addOperand(MCOperand::createImm(Imm)); + return MCDisassembler::Success; +} + DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size, ArrayRef Bytes, uint64_t Address, diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h @@ -433,6 +433,130 @@ } // namespace RISCVVType +namespace RISCVZCE { + +enum class RLISTENCODE { + RA = 4, + RA_S0, + RA_S0_S1, + RA_S0_S2, + RA_S0_S3, + RA_S0_S4, + RA_S0_S5, + RA_S0_S6, + RA_S0_S7, + RA_S0_S8, + RA_S0_S9, + // note - to include s10, s11 must also be included + RA_S0_S11, + RA_S0_S10, // This is for error checking. +}; + +inline unsigned encodeRlist(MCRegister EndReg, bool isCInst, + bool IsRV32E = false) { + auto RlistEncode = [=] { + switch (EndReg) { + case RISCV::X1: + return RLISTENCODE::RA; + case RISCV::X8: + return RLISTENCODE::RA_S0; + case RISCV::X9: + return RLISTENCODE::RA_S0_S1; + case RISCV::X18: + return RLISTENCODE::RA_S0_S2; + case RISCV::X19: + return RLISTENCODE::RA_S0_S3; + case RISCV::X20: + return RLISTENCODE::RA_S0_S4; + case RISCV::X21: + return RLISTENCODE::RA_S0_S5; + case RISCV::X22: + return RLISTENCODE::RA_S0_S6; + case RISCV::X23: + return RLISTENCODE::RA_S0_S7; + case RISCV::X24: + return RLISTENCODE::RA_S0_S8; + case RISCV::X25: + return RLISTENCODE::RA_S0_S9; + case RISCV::X26: + return RLISTENCODE::RA_S0_S10; + case RISCV::X27: + return RLISTENCODE::RA_S0_S11; + default: + llvm_unreachable("Undefined input."); + } + }(); + return static_cast(RlistEncode); +} + +inline static unsigned getStackAdjBase(unsigned rlistVal, bool isRV64, + bool isEABI) { + if (rlistVal == 16) + assert(0 && "{ra, s0-s10} is not supported, s11 must be included."); + if (isEABI) { + return 16; + } + if (!isRV64) { + switch (rlistVal) { + case /*ra*/ 4: + case /*s0*/ 5: + case /*s1*/ 6: + case /*s2*/ 7: + return 16; + case /*s3*/ 8: + case /*s4*/ 9: + case /*s5*/ 10: + case /*s6*/ 11: + return 32; + case /*s7*/ 12: + case /*s8*/ 13: + case /*s9*/ 14: + return 48; + case /*s11*/ 15: + return 64; + } + } else { + switch (rlistVal) { + case /*ra*/ 4: + case /*s0*/ 5: + return 16; + case /*s1*/ 6: + case /*s2*/ 7: + return 32; + case /*s3*/ 8: + case /*s4*/ 9: + return 48; + case /*s5*/ 10: + case /*s6*/ 11: + return 64; + case /*s7*/ 12: + case /*s8*/ 13: + return 80; + case /*s9*/ 14: + return 96; + case /*s11*/ 15: + return 112; + } + } + llvm_unreachable("Unexpected rlistVal"); +} + +inline static bool getSpimm(unsigned rlistVal, unsigned &spimmVal, + int64_t stackAdjustment, bool isRV64, bool isEABI) { + if (rlistVal == 16) + return false; + unsigned stackAdj = getStackAdjBase(rlistVal, isRV64, isEABI); + spimmVal = (stackAdjustment - stackAdj) / 16; + if (spimmVal > 3) + return false; + return true; +} + +void printRlist(unsigned SlistEncode, raw_ostream &OS); +void printSpimm(int64_t Spimm, raw_ostream &OS); + +} // namespace RISCVZCE + } // namespace llvm #endif diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp @@ -185,4 +185,49 @@ OS << ", mu"; } +void RISCVZCE::printRlist(unsigned SlistEncode, raw_ostream &OS) { + OS << "{"; + switch (SlistEncode) { + case 4: + OS << "ra"; + break; + case 5: + OS << "ra, s0"; + break; + case 6: + OS << "ra, s0-s1"; + break; + case 7: + OS << "ra, s0-s2"; + break; + case 8: + OS << "ra, s0-s3"; + break; + case 9: + OS << "ra, s0-s4"; + break; + case 10: + OS << "ra, s0-s5"; + break; + case 11: + OS << "ra, s0-s6"; + break; + case 12: + OS << "ra, s0-s7"; + break; + case 13: + OS << "ra, s0-s8"; + break; + case 14: + OS << "ra, s0-s9"; + break; + case 15: + OS << "ra, s0-s11"; + break; + } + OS << "}"; +} + +void RISCVZCE::printSpimm(int64_t Spimm, raw_ostream &OS) { OS << Spimm; } + } // namespace llvm diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h @@ -46,6 +46,10 @@ raw_ostream &O); void printVMaskReg(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O); + void printRlist(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, + raw_ostream &O); + void printSpimm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, + raw_ostream &O); // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp @@ -181,6 +181,33 @@ RISCVVType::printVType(Imm, O); } +void RISCVInstPrinter::printRlist(const MCInst *MI, unsigned OpNo, + const MCSubtargetInfo &STI, raw_ostream &O) { + unsigned Imm = MI->getOperand(OpNo).getImm(); + RISCVZCE::printRlist(Imm, O); +} + +void RISCVInstPrinter::printSpimm(const MCInst *MI, unsigned OpNo, + const MCSubtargetInfo &STI, raw_ostream &O) { + int64_t Imm = MI->getOperand(OpNo).getImm(); + unsigned opcode = MI->getOpcode(); + bool isRV64 = STI.getFeatureBits()[RISCV::Feature64Bit]; + int64_t spimm = 0; + bool isEABI = false; // Reserved for future implementation + auto rlistVal = MI->getOperand(0).getImm(); + if (rlistVal == 16) + assert(0 && "Incorrect rlist."); + auto base = RISCVZCE::getStackAdjBase(rlistVal, isRV64, isEABI); + spimm = Imm + base; + if (spimm < base || spimm > base + 48) + llvm_unreachable("Incorrect spimm"); + if (opcode == RISCV::CM_PUSH) { + spimm *= -1; + } + + RISCVZCE::printSpimm(spimm, O); +} + void RISCVInstPrinter::printVMaskReg(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O) { diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp @@ -84,6 +84,16 @@ unsigned getVMaskReg(const MCInst &MI, unsigned OpNo, SmallVectorImpl &Fixups, const MCSubtargetInfo &STI) const; + + unsigned getRlistOpValue(const MCInst &MI, unsigned OpNo, + SmallVectorImpl &Fixups, + const MCSubtargetInfo &STI) const; + +private: + FeatureBitset computeAvailableFeatures(const FeatureBitset &FB) const; + void + verifyInstructionPredicates(const MCInst &MI, + const FeatureBitset &AvailableFeatures) const; }; } // end anonymous namespace @@ -394,4 +404,16 @@ } } +unsigned RISCVMCCodeEmitter::getRlistOpValue(const MCInst &MI, unsigned OpNo, + SmallVectorImpl &Fixups, + const MCSubtargetInfo &STI) const { + MCOperand MO = MI.getOperand(OpNo); + assert(MO.isImm() && "Rlist operand must be immidiate"); + auto Imm = MO.getImm(); + if (Imm < 4) + assert(0 && "EABI is currently not implemented"); + else + return Imm; +} + #include "RISCVGenMCCodeEmitter.inc" diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -368,6 +368,14 @@ AssemblerPredicate<(all_of FeatureExtZcb), "'Zcb' (Shortened format for basic bit manipulation instructions)">; +def FeatureExtZcmp + : SubtargetFeature<"experimental-zcmp", "HasStdExtZcmp", "true", + "'Zcmp' (sequenced instuctions for code-size reduction.)", + [FeatureExtZca]>; +def HasStdExtZcmp : Predicate<"Subtarget->hasStdExtZcmp() && !Subtarget->hasStdExtC()">, + AssemblerPredicate<(all_of FeatureExtZcmp, (not FeatureStdExtC)), + "'Zcmp' (sequenced instuctions for code-size reduction.)">; + def FeatureNoRVCHints : SubtargetFeature<"no-rvc-hints", "EnableRVCHintInstrs", "false", "Disable RVC Hint Instructions.">; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.h b/llvm/lib/Target/RISCV/RISCVInstrInfo.h --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.h +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.h @@ -112,6 +112,8 @@ bool isAsCheapAsAMove(const MachineInstr &MI) const override; + Optional isLoadImmImpl(const MachineInstr &MI) const; + Optional isCopyInstrImpl(const MachineInstr &MI) const override; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -1073,6 +1073,24 @@ return MI.isAsCheapAsAMove(); } +Optional +RISCVInstrInfo::isLoadImmImpl(const MachineInstr &MI) const { + if (MI.isMoveImmediate()) + return DestSourcePair{MI.getOperand(0), MI.getOperand(2)}; + switch (MI.getOpcode()) { + default: + break; + case RISCV::ADDIW: + case RISCV::ADDI: + // Operand 1 can be a frameindex but callers expect registers + if (MI.getOperand(1).isReg() && MI.getOperand(2).isImm() && + MI.getOperand(1).getReg() == RISCV::X0) + return DestSourcePair{MI.getOperand(0), MI.getOperand(2)}; + break; + } + return None; +} + Optional RISCVInstrInfo::isCopyInstrImpl(const MachineInstr &MI) const { if (MI.isMoveReg()) @@ -1080,6 +1098,16 @@ switch (MI.getOpcode()) { default: break; + case RISCV::ADD: + if (!MI.getOperand(1).isReg() || !MI.getOperand(2).isReg()) + break; + if ((MI.getOperand(1).getReg() == RISCV::X0) && + (MI.getOperand(2).getReg() != RISCV::X0)) + return DestSourcePair{MI.getOperand(0), MI.getOperand(2)}; + if ((MI.getOperand(1).getReg() != RISCV::X0) && + (MI.getOperand(2).getReg() == RISCV::X0)) + return DestSourcePair{MI.getOperand(0), MI.getOperand(1)}; + break; case RISCV::ADDI: // Operand 1 can be a frameindex but callers expect registers if (MI.getOperand(1).isReg() && MI.getOperand(2).isImm() && diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td @@ -44,6 +44,45 @@ }]; } +def RlistAsmOperand : AsmOperandClass { + let Name = "Rlist"; + let ParserMethod = "parseReglist"; + let DiagnosticType = "InvalidRlist"; +} + +def SpimmAsmOperand : AsmOperandClass { + let Name = "Spimm"; + let ParserMethod = "parseZceSpimm"; + let DiagnosticType = "InvalidSpimm"; +} + +def rlist : Operand, ImmLeaf(Imm);}]> { + let ParserMatchClass = RlistAsmOperand; + let PrintMethod = "printRlist"; + let DecoderMethod = "decodeZceRlist"; + let EncoderMethod = "getRlistOpValue"; + let MCOperandPredicate = [{ + int64_t Imm; + if (!MCOp.evaluateAsConstantImm(Imm)) + return false; + if (!isUInt<4>(Imm)) return false; + // 0~3 Reserved for EABI + return (Imm>=4) && (Imm <=15); + }]; + } + +def spimm : Operand, ImmLeaf(Imm);}]>{ + let ParserMatchClass = SpimmAsmOperand; + let PrintMethod = "printSpimm"; + let DecoderMethod = "decodeZceSpimm"; + let MCOperandPredicate = [{ + int64_t Imm; + if (!MCOp.evaluateAsConstantImm(Imm)) + return false; + return isShiftedUInt<5, 4>(Imm); + }]; +} + //===----------------------------------------------------------------------===// // Instruction Class Templates //===----------------------------------------------------------------------===// @@ -90,6 +129,13 @@ : RVInst16CS; +class RVInstZceCPPP + : RVInst16 { + + let Inst{1-0} = 0b10; + let Inst{15-13} = 0b101; +} + //===----------------------------------------------------------------------===// // Instructions //===----------------------------------------------------------------------===// @@ -159,3 +205,61 @@ let Inst{5} = imm{1}; } } + +// ZCMP +let Predicates = [HasStdExtZcmp], Defs = [X10, X11], + hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { +def CM_MVA01S : RVInst16CA<0b101011, 0b11, 0b10, (outs), + (ins SR07:$rs1, SR07:$rs2), "cm.mva01s", "$rs1, $rs2">, + Sched<[]>; + +def CM_MVSA01 : RVInst16CA<0b101011, 0b01, 0b10, (outs SR07:$rs1, SR07:$rs2), + (ins), "cm.mvsa01", "$rs1, $rs2">, + Sched<[]>; +} + +let Predicates = [HasStdExtZcmp] in { +let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in +def CM_PUSH : RVInstZceCPPP<(outs), (ins rlist:$rlist, spimm:$spimm), + "cm.push", "{$rlist}, $spimm">, Sched<[]> { + bits<4> rlist; + bits<16> spimm; + + let Inst{12-8} = 0b11000; + let Inst{7-4} = rlist; + let Inst{3-2} = spimm{5-4}; +} + +let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in +def CM_POPRET : RVInstZceCPPP<(outs), (ins rlist:$rlist, spimm:$spimm), + "cm.popret", "{$rlist}, $spimm">, Sched<[]> { + bits<4> rlist; + bits<16> spimm; + + let Inst{12-8} = 0b11110; + let Inst{7-4} = rlist; + let Inst{3-2} = spimm{5-4}; +} + +let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in +def CM_POPRETZ : RVInstZceCPPP<(outs), (ins rlist:$rlist, spimm:$spimm), + "cm.popretz", "{$rlist}, $spimm">, Sched<[]> { + bits<4> rlist; + bits<16> spimm; + + let Inst{12-8} = 0b11100; + let Inst{7-4} = rlist; + let Inst{3-2} = spimm{5-4}; +} + +let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in +def CM_POP : RVInstZceCPPP<(outs), (ins rlist:$rlist, spimm:$spimm), + "cm.pop", "{$rlist}, $spimm">, Sched<[]> { + bits<4> rlist; + bits<16> spimm; + + let Inst{12-8} = 0b11010; + let Inst{7-4} = rlist; + let Inst{3-2} = spimm{5-4}; +} +} diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td --- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td +++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td @@ -177,6 +177,24 @@ let RegInfos = XLenRI; } +// Saved Registers from s0 to s7, for C.MVA01S07 instruction in Zce extension +def SR07 : RegisterClass<"RISCV", [XLenVT], 32, (add + (sequence "X%u", 8, 9), + (sequence "X%u", 18, 23) + )> { + let RegInfos = XLenRI; +} + +// Registers saveable by PUSH instruction in Zce extension +def PGPR : RegisterClass<"RISCV", [XLenVT], 32, (add + (sequence "X%u", 8, 9), + (sequence "X%u", 18, 25), + X27, + X1 + )> { + let RegInfos = XLenRI; +} + // Floating point registers let RegAltNameIndices = [ABIRegAltName] in { def F0_H : RISCVReg16<0, "f0", ["ft0"]>, DwarfRegNum<[32]>; diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h --- a/llvm/lib/Target/RISCV/RISCVSubtarget.h +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h @@ -63,6 +63,7 @@ bool HasStdExtZbt = false; bool HasStdExtZca = false; bool HasStdExtZcb = false; + bool HasStdExtZcmp = false; bool HasStdExtV = false; bool HasStdExtZve32x = false; bool HasStdExtZve32f = false; @@ -173,6 +174,7 @@ bool hasStdExtZbt() const { return HasStdExtZbt; } bool hasStdExtZca() const { return HasStdExtZca; } bool hasStdExtZcb() const { return HasStdExtZcb; } + bool hasStdExtZcmp() const { return HasStdExtZcmp; } bool hasStdExtZvl() const { return ZvlLen != 0; } bool hasStdExtZvfh() const { return HasStdExtZvfh; } bool hasStdExtZfhmin() const { return HasStdExtZfhmin; } diff --git a/llvm/test/MC/RISCV/attribute-arch.s b/llvm/test/MC/RISCV/attribute-arch.s --- a/llvm/test/MC/RISCV/attribute-arch.s +++ b/llvm/test/MC/RISCV/attribute-arch.s @@ -185,6 +185,12 @@ .attribute arch, "rv32i_zk1p0" # CHECK: attribute 5, "rv32i2p0_zbkb1p0_zbkc1p0_zbkx1p0_zk1p0_zkn1p0_zknd1p0_zkne1p0_zknh1p0_zkr1p0_zkt1p0" +.attribute arch, "rv32izihintntl0p2" +# CHECK: attribute 5, "rv32i2p0_zihintntl0p2" + +.attribute arch, "rv32iczihintntl0p2" +# CHECK: attribute 5, "rv32i2p0_c2p0_zihintntl0p2" + .attribute arch, "rv32if_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0" # CHECK: attribute 5, "rv32i2p0_f2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0" @@ -193,3 +199,6 @@ .attribute arch, "rv32izcb0p70" # CHECK: attribute 5, "rv32i2p0_zcb0p70" + +.attribute arch, "rv32izcmp0p70" +# CHECK: attribute 5, "rv32i2p0_zca0p70_zcmp0p70" diff --git a/llvm/test/MC/RISCV/rv32zcmp-Invalid.s b/llvm/test/MC/RISCV/rv32zcmp-Invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rv32zcmp-Invalid.s @@ -0,0 +1,14 @@ +# RUN: not llvm-mc -triple=riscv32 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding < %s 2>&1 \ +# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s + +# CHECK-ERROR: error: invalid operand for instruction +cm.mvsa01 a1, a2 + +# CHECK-ERROR: error: invalid operand for instruction +cm.mva01s a1, a2 + +# CHECK-ERROR: error: invalid register list, {ra, s0-s10} is not supported. +cm.popretz {ra, s0-s10}, 112 + +# CHECK-ERROR: error: This stack adjustment is invalid for this instruction and register list, Please refer to Zce spec for a detailed range of stack adjustment. +cm.popretz {ra, s0-s1}, 112 \ No newline at end of file diff --git a/llvm/test/MC/RISCV/rv32zcmp-valid.s b/llvm/test/MC/RISCV/rv32zcmp-valid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rv32zcmp-valid.s @@ -0,0 +1,285 @@ +# RUN: llvm-mc %s -triple=riscv32 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding \ +# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s +# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=experimental-zcmp < %s \ +# RUN: | llvm-objdump --mattr=-c,experimental-zcmp -M no-aliases -d -r - \ +# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s + +# CHECK-ASM-AND-OBJ: cm.mvsa01 s1, s0 +# CHECK-ASM: encoding: [0xa2,0xac] +cm.mvsa01 s1, s0 + +# CHECK-ASM-AND-OBJ: cm.mva01s s1, s0 +# CHECK-ASM: encoding: [0xe2,0xac] +cm.mva01s s1, s0 + +# CHECK-ASM-AND-OBJ: cm.popret {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xbe] +cm.popret {ra}, 16 + +# CHECK-ASM-AND-OBJ: cm.popret {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xbe] +cm.popret {x1}, 16 + +# CHECK-ASM-AND-OBJ: cm.popret {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xbe] +cm.popret {ra}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xbe] +cm.popret {x1}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0}, 64 +# CHECK-ASM: encoding: [0x5e,0xbe] +cm.popret {ra, s0}, 64 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0}, 64 +# CHECK-ASM: encoding: [0x5e,0xbe] +cm.popret {x1, x8}, 64 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s1}, 16 +# CHECK-ASM: encoding: [0x62,0xbe] +cm.popret {ra,s0-s1}, 16 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s1}, 16 +# CHECK-ASM: encoding: [0x62,0xbe] +cm.popret {x1, x8-x9}, 16 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x76,0xbe] +cm.popret {ra, s0-s2}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x76,0xbe] +cm.popret {x1, x8-x9, x18}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s3}, 32 +# CHECK-ASM: encoding: [0x82,0xbe] +cm.popret {ra, s0-s3}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s3}, 32 +# CHECK-ASM: encoding: [0x82,0xbe] +cm.popret {x1, x8-x9, x18-x19}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s5}, 32 +# CHECK-ASM: encoding: [0xa2,0xbe] +cm.popret {ra, s0-s5}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s5}, 32 +# CHECK-ASM: encoding: [0xa2,0xbe] +cm.popret {x1, x8-x9, x18-x21}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s7}, 48 +# CHECK-ASM: encoding: [0xc2,0xbe] +cm.popret {ra, s0-s7}, 48 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s7}, 48 +# CHECK-ASM: encoding: [0xc2,0xbe] +cm.popret {x1, x8-x9, x18-x23}, 48 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xfe,0xbe] +cm.popret {ra, s0-s11}, 112 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xfe,0xbe] +cm.popret {x1, x8-x9, x18-x27}, 112 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xbc] +cm.popretz {ra}, 16 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xbc] +cm.popretz {x1}, 16 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xbc] +cm.popretz {ra}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xbc] +cm.popretz {x1}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0}, 64 +# CHECK-ASM: encoding: [0x5e,0xbc] +cm.popretz {ra, s0}, 64 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0}, 64 +# CHECK-ASM: encoding: [0x5e,0xbc] +cm.popretz {x1, x8}, 64 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s1}, 16 +# CHECK-ASM: encoding: [0x62,0xbc] +cm.popretz {ra, s0-s1}, 16 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s1}, 16 +# CHECK-ASM: encoding: [0x62,0xbc] +cm.popretz {x1, x8-x9}, 16 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x76,0xbc] +cm.popretz {ra, s0-s2}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x76,0xbc] +cm.popretz {x1, x8-x9, x18}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s3}, 32 +# CHECK-ASM: encoding: [0x82,0xbc] +cm.popretz {ra, s0-s3}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s3}, 32 +# CHECK-ASM: encoding: [0x82,0xbc] +cm.popretz {x1, x8-x9, x18-x19}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s5}, 32 +# CHECK-ASM: encoding: [0xa2,0xbc] +cm.popretz {ra, s0-s5}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s5}, 32 +# CHECK-ASM: encoding: [0xa2,0xbc] +cm.popretz {x1, x8-x9, x18-x21}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s7}, 48 +# CHECK-ASM: encoding: [0xc2,0xbc] +cm.popretz {ra, s0-s7}, 48 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s7}, 48 +# CHECK-ASM: encoding: [0xc2,0xbc] +cm.popretz {x1, x8-x9, x18-x23}, 48 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xfe,0xbc] +cm.popretz {ra, s0-s11}, 112 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xfe,0xbc] +cm.popretz {x1, x8-x9, x18-x27}, 112 + +# CHECK-ASM-AND-OBJ: cm.pop {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xba] +cm.pop {ra}, 16 + +# CHECK-ASM-AND-OBJ: cm.pop {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xba] +cm.pop {x1}, 16 + +# CHECK-ASM-AND-OBJ: cm.pop {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xba] +cm.pop {ra}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xba] +cm.pop {x1}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0}, 16 +# CHECK-ASM: encoding: [0x52,0xba] +cm.pop {ra, s0}, 16 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0}, 16 +# CHECK-ASM: encoding: [0x52,0xba] +cm.pop {x1, x8}, 16 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s1}, 32 +# CHECK-ASM: encoding: [0x66,0xba] +cm.pop {ra, s0-s1}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s1}, 32 +# CHECK-ASM: encoding: [0x66,0xba] +cm.pop {x1, x8-x9}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x76,0xba] +cm.pop {ra, s0-s2}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x76,0xba] +cm.pop {x1, x8-x9, x18}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s5}, 32 +# CHECK-ASM: encoding: [0xa2,0xba] +cm.pop {ra, s0-s5}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s5}, 32 +# CHECK-ASM: encoding: [0xa2,0xba] +cm.pop {x1, x8-x9, x18-x21}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s7}, 48 +# CHECK-ASM: encoding: [0xc2,0xba] +cm.pop {ra, s0-s7}, 48 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s7}, 48 +# CHECK-ASM: encoding: [0xc2,0xba] +cm.pop {x1, x8-x9, x18-x23}, 48 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s11}, 64 +# CHECK-ASM: encoding: [0xf2,0xba] +cm.pop {ra, s0-s11}, 64 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s11}, 64 +# CHECK-ASM: encoding: [0xf2,0xba] +cm.pop {x1, x8-x9, x18-x27}, 64 + +# CHECK-ASM-AND-OBJ: cm.push {ra}, -16 +# CHECK-ASM: encoding: [0x42,0xb8] +cm.push {ra}, -16 + +# CHECK-ASM-AND-OBJ: cm.push {ra}, -16 +# CHECK-ASM: encoding: [0x42,0xb8] +cm.push {x1}, -16 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0}, -32 +# CHECK-ASM: encoding: [0x56,0xb8] +cm.push {ra, s0}, -32 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0}, -32 +# CHECK-ASM: encoding: [0x56,0xb8] +cm.push {x1, x8}, -32 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s1}, -16 +# CHECK-ASM: encoding: [0x62,0xb8] +cm.push {ra, s0-s1}, -16 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s1}, -16 +# CHECK-ASM: encoding: [0x62,0xb8] +cm.push {x1, x8-x9}, -16 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s3}, -32 +# CHECK-ASM: encoding: [0x82,0xb8] +cm.push {ra, s0-s3}, -32 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s3}, -32 +# CHECK-ASM: encoding: [0x82,0xb8] +cm.push {x1, x8-x9, x18-x19}, -32 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s7}, -48 +# CHECK-ASM: encoding: [0xc2,0xb8] +cm.push {ra, s0-s7}, -48 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s7}, -48 +# CHECK-ASM: encoding: [0xc2,0xb8] +cm.push {x1, x8-x9, x18-x23}, -48 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s7}, -64 +# CHECK-ASM: encoding: [0xc6,0xb8] +cm.push {ra, s0-s7}, -64 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s7}, -64 +# CHECK-ASM: encoding: [0xc6,0xb8] +cm.push {x1, x8-x9, x18-x23}, -64 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s11}, -80 +# CHECK-ASM: encoding: [0xf6,0xb8] +cm.push {ra, s0-s11}, -80 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s11}, -80 +# CHECK-ASM: encoding: [0xf6,0xb8] +cm.push {x1, x8-x9, x18-x27}, -80 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s11}, -112 +# CHECK-ASM: encoding: [0xfe,0xb8] +cm.push {ra, s0-s11}, -112 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s11}, -112 +# CHECK-ASM: encoding: [0xfe,0xb8] +cm.push {x1, x8-x9, x18-x27}, -112 diff --git a/llvm/test/MC/RISCV/rv64zcmp-Invalid.s b/llvm/test/MC/RISCV/rv64zcmp-Invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rv64zcmp-Invalid.s @@ -0,0 +1,14 @@ +# RUN: not llvm-mc -triple=riscv64 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding < %s 2>&1 \ +# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s + +# CHECK-ERROR: error: invalid operand for instruction +cm.mvsa01 a1, a2 + +# CHECK-ERROR: error: invalid operand for instruction +cm.mva01s a1, a2 + +# CHECK-ERROR: error: invalid register list, {ra, s0-s10} is not supported. +cm.popretz {ra, s0-s10}, 112 + +# CHECK-ERROR: error: This stack adjustment is invalid for this instruction and register list, Please refer to Zce spec for a detailed range of stack adjustment. +cm.popretz {ra, s0-s1}, 112 \ No newline at end of file diff --git a/llvm/test/MC/RISCV/rv64zcmp-valid.s b/llvm/test/MC/RISCV/rv64zcmp-valid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rv64zcmp-valid.s @@ -0,0 +1,149 @@ +# RUN: llvm-mc %s -triple=riscv64 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding \ +# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s +# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=experimental-zcmp < %s \ +# RUN: | llvm-objdump --mattr=-c,experimental-zcmp -M no-aliases -d -r - \ +# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s + +# CHECK-ASM-AND-OBJ: cm.mvsa01 s1, s0 +# CHECK-ASM: encoding: [0xa2,0xac] +cm.mvsa01 s1, s0 + +# CHECK-ASM-AND-OBJ: cm.mva01s s1, s0 +# CHECK-ASM: encoding: [0xe2,0xac] +cm.mva01s s1, s0 + +# CHECK-ASM-AND-OBJ: cm.popret {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xbe] +cm.popret {ra}, 16 + +# CHECK-ASM-AND-OBJ: cm.popret {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xbe] +cm.popret {ra}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0}, 64 +# CHECK-ASM: encoding: [0x5e,0xbe] +cm.popret {ra, s0}, 64 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s1}, 32 +# CHECK-ASM: encoding: [0x62,0xbe] +cm.popret {ra,s0-s1}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x72,0xbe] +cm.popret {ra, s0-s2}, 32 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s3}, 64 +# CHECK-ASM: encoding: [0x86,0xbe] +cm.popret {ra, s0-s3}, 64 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s5}, 64 +# CHECK-ASM: encoding: [0xa2,0xbe] +cm.popret {ra, s0-s5}, 64 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s7}, 80 +# CHECK-ASM: encoding: [0xc2,0xbe] +cm.popret {ra, s0-s7}, 80 + +# CHECK-ASM-AND-OBJ: cm.popret {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xf2,0xbe] +cm.popret {ra, s0-s11}, 112 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xbc] +cm.popretz {ra}, 16 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xbc] +cm.popretz {ra}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0}, 64 +# CHECK-ASM: encoding: [0x5e,0xbc] +cm.popretz {ra, s0}, 64 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s1}, 32 +# CHECK-ASM: encoding: [0x62,0xbc] +cm.popretz {ra, s0-s1}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x72,0xbc] +cm.popretz {ra, s0-s2}, 32 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s3}, 64 +# CHECK-ASM: encoding: [0x86,0xbc] +cm.popretz {ra, s0-s3}, 64 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s5}, 64 +# CHECK-ASM: encoding: [0xa2,0xbc] +cm.popretz {ra, s0-s5}, 64 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s7}, 80 +# CHECK-ASM: encoding: [0xc2,0xbc] +cm.popretz {ra, s0-s7}, 80 + +# CHECK-ASM-AND-OBJ: cm.popretz {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xf2,0xbc] +cm.popretz {ra, s0-s11}, 112 + +# CHECK-ASM-AND-OBJ: cm.pop {ra}, 16 +# CHECK-ASM: encoding: [0x42,0xba] +cm.pop {ra}, 16 + +# CHECK-ASM-AND-OBJ: cm.pop {ra}, 32 +# CHECK-ASM: encoding: [0x46,0xba] +cm.pop {ra}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0}, 16 +# CHECK-ASM: encoding: [0x52,0xba] +cm.pop {ra, s0}, 16 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s1}, 32 +# CHECK-ASM: encoding: [0x62,0xba] +cm.pop {ra, s0-s1}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s2}, 32 +# CHECK-ASM: encoding: [0x72,0xba] +cm.pop {ra, s0-s2}, 32 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s5}, 64 +# CHECK-ASM: encoding: [0xa2,0xba] +cm.pop {ra, s0-s5}, 64 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s7}, 80 +# CHECK-ASM: encoding: [0xc2,0xba] +cm.pop {ra, s0-s7}, 80 + +# CHECK-ASM-AND-OBJ: cm.pop {ra, s0-s11}, 112 +# CHECK-ASM: encoding: [0xf2,0xba] +cm.pop {ra, s0-s11}, 112 + +# CHECK-ASM-AND-OBJ: cm.push {ra}, -16 +# CHECK-ASM: encoding: [0x42,0xb8] +cm.push {ra}, -16 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0}, -32 +# CHECK-ASM: encoding: [0x56,0xb8] +cm.push {ra, s0}, -32 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s1}, -32 +# CHECK-ASM: encoding: [0x62,0xb8] +cm.push {ra, s0-s1}, -32 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s3}, -64 +# CHECK-ASM: encoding: [0x86,0xb8] +cm.push {ra, s0-s3}, -64 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s7}, -80 +# CHECK-ASM: encoding: [0xc2,0xb8] +cm.push {ra, s0-s7}, -80 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s7}, -80 +# CHECK-ASM: encoding: [0xc2,0xb8] +cm.push {ra, s0-s7}, -80 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s11}, -112 +# CHECK-ASM: encoding: [0xf2,0xb8] +cm.push {ra, s0-s11}, -112 + +# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s11}, -128 +# CHECK-ASM: encoding: [0xf6,0xb8] +cm.push {ra, s0-s11}, -128 \ No newline at end of file