From 057c063c9b0638916adffe53767242bdf507d129 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 12 Apr 2022 13:25:51 -0700 Subject: [PATCH] [RISCV] Add a encodeLMUL function to RISCVVType. NFC This moves the encoding handling out of the assembly parser. Reviewed By: khchen, frasercrmck Differential Revision: https://reviews.llvm.org/D123553 --- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 4 +--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 2954f9d..ffa30b2 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -1776,9 +1776,7 @@ OperandMatchResultTy RISCVAsmParser::parseVTypeI(OperandVector &Operands) { else goto MatchFail; - unsigned LmulLog2 = Log2_32(Lmul); - RISCVII::VLMUL VLMUL = - static_cast(Fractional ? 8 - LmulLog2 : LmulLog2); + RISCVII::VLMUL VLMUL = RISCVVType::encodeLMUL(Lmul, Fractional); unsigned VTypeI = RISCVVType::encodeVTYPE(VLMUL, Sew, TailAgnostic, MaskAgnostic); diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h index 5826a2c..56c217e 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h @@ -383,6 +383,12 @@ inline static RISCVII::VLMUL getVLMUL(unsigned VType) { // Decode VLMUL into 1,2,4,8 and fractional indicator. std::pair decodeVLMUL(RISCVII::VLMUL VLMUL); +inline static RISCVII::VLMUL encodeLMUL(unsigned LMUL, bool Fractional) { + assert(isValidLMUL(LMUL, Fractional) && "Unsupported LMUL"); + unsigned LmulLog2 = Log2_32(LMUL); + return static_cast(Fractional ? 8 - LmulLog2 : LmulLog2); +} + inline static unsigned decodeVSEW(unsigned VSEW) { assert(VSEW < 8 && "Unexpected VSEW value"); return 1 << (VSEW + 3); -- 2.7.4