[PATCH] D150133: [RISCV] Support constant immediate for la pseudo instruction
garvit gupta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 22:05:54 PDT 2023
garvitgupta08 added inline comments.
================
Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:1619
+ isCodeGenOnly = 0, isAsmParserOnly = 1 in
+def PseudoLAImm : Pseudo<(outs GPR:$rd), (ins ixlenimm_la:$imm), [],
+ "la", "$rd, $imm">;
----------------
jrtc27 wrote:
> I don't understand why you need a new pseudo rather than teaching the existing one to also accept an integer
I did this in the revision https://reviews.llvm.org/D150133?id=521304. Below is the diff for the same but I believe that having a separate defintion for supporting constant operand in la will be much cleaner and readable than modifying the existing defintion to accept bare symbol and constant as argument.
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+ OperandMatchResultTy parseBareSymbolOrConstant(OperandVector &Operands);
+ // Allow Constant Immediate as well as BareSymbols
+ bool isBareSymbolOrConstant() const {
+ if (isBareSymbol())
+ return true;
+ int64_t Imm;
+ RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+ if (!isImm())
+ return false;
+ bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+ bool IsInRange = isInt<32>(Imm) || isUInt<32>(Imm) || isRV64Imm();
+ return IsConstantImm && IsInRange && VK == RISCVMCExpr::VK_RISCV_None;
+ }
+
+ case Match_InvalidBareSymbolOrConstant: {
+ return generateImmOutOfRangeError(
+ Operands, ErrorInfo, std::numeric_limits<int32_t>::min(),
+ std::numeric_limits<uint32_t>::max(),
+ "operand either must be a Bare Symbol or an integer in the range");
+ }
+OperandMatchResultTy RISCVAsmParser::parseBareSymbolOrConstant(OperandVector &Operands) {
+ if (getLexer().getKind() == AsmToken::Identifier) {
+ OperandMatchResultTy Result = parseImmediate(Operands);
+ if (Result == MatchOperand_Success)
+ return MatchOperand_Success;
+ }
+ return parseBareSymbol(Operands);
+}
+
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
+def BareSymbolOrConstant : AsmOperandClass {
+ let Name = "BareSymbolOrConstant";
+ let RenderMethod = "addImmOperands";
+ let DiagnosticType = "InvalidBareSymbolOrConstant";
+ let ParserMethod = "parseBareSymbolOrConstant";
+}
+
+// support constant operand for la pseudoinstruction.
+def bare_symbol_or_constant : Operand<XLenVT> {
+ let ParserMatchClass = BareSymbolOrConstant;
+}
+
-def PseudoLA : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [],
+def PseudoLA : Pseudo<(outs GPR:$dst), (ins bare_symbol_or_constant:$src), [],
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150133/new/
https://reviews.llvm.org/D150133
More information about the llvm-commits
mailing list