Skip to content

Commit b9501ff

Browse files
committed
Add support for Operand Imm32
Change-Id: I49b82a0333ab216d7b150027d973f11d4cbdf35c
1 parent 81d1b62 commit b9501ff

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,20 @@ struct RISCVOperand final : public MCParsedAsmOperand {
10461046
isInt<26>(fixImmediateForRV32(Imm, isRV64Imm()));
10471047
}
10481048

1049+
bool isImm32() const {
1050+
int64_t Imm;
1051+
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
1052+
if (!isImm())
1053+
return false;
1054+
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
1055+
bool IsValid;
1056+
if (!IsConstantImm)
1057+
IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK);
1058+
else
1059+
IsValid = isInt<32>(Imm) || isUInt<32>(Imm);
1060+
return IsValid && VK == RISCVMCExpr::VK_RISCV_None;
1061+
}
1062+
10491063
/// getStartLoc - Gets location of the first token of this operand
10501064
SMLoc getStartLoc() const override { return StartLoc; }
10511065
/// getEndLoc - Gets location of the last token of this operand
@@ -1689,6 +1703,10 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16891703
case Match_InvalidSImm26:
16901704
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 25),
16911705
(1 << 25) - 1);
1706+
case Match_InvalidImm32:
1707+
return generateImmOutOfRangeError(Operands, ErrorInfo,
1708+
std::numeric_limits<int32_t>::min(),
1709+
std::numeric_limits<uint32_t>::max());
16921710
case Match_InvalidRlist: {
16931711
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
16941712
return Error(

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ enum OperandType : unsigned {
333333
OPERAND_SIMM12,
334334
OPERAND_SIMM12_LSB00000,
335335
OPERAND_SIMM26,
336+
OPERAND_IMM32,
336337
OPERAND_CLUI_IMM,
337338
OPERAND_VTYPEI10,
338339
OPERAND_VTYPEI11,

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ def uimm11 : RISCVUImmLeafOp<11>;
3434

3535
def simm26 : RISCVSImmLeafOp<26>;
3636

37+
// 32-bit Immediate, used by RV32 Instructions in 32-bit operations, so no
38+
// sign-/zero-extension. This is represented internally as a signed 32-bit value.
39+
def imm32 : RISCVOp<XLenVT> {
40+
let ParserMatchClass = ImmAsmOperand<"", 32, "">;
41+
let EncoderMethod = "getImmOpValue";
42+
let DecoderMethod = "decodeSImmOperand<32>";
43+
let OperandType = "OPERAND_IMM32";
44+
let MCOperandPredicate = [{
45+
int64_t Imm;
46+
if (MCOp.evaluateAsConstantImm(Imm))
47+
return (isInt<32>(Imm) || isUint<32>(Imm));
48+
return MCOp.isBareSymbolRef();
49+
}];
50+
}
51+
3752
//===----------------------------------------------------------------------===//
3853
// Instruction Formats
3954
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)