Skip to content

[RISCV] Cleanup assembler predicates after #133377. #133652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,50 +555,55 @@ struct RISCVOperand final : public MCParsedAsmOperand {

bool isBareSymbol() const {
int64_t Imm;
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
// Must be of 'immediate' type but not a constant.
if (!isImm() || evaluateConstantImm(getImm(), Imm))
return false;

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
VK == RISCVMCExpr::VK_None;
}

bool isCallSymbol() const {
int64_t Imm;
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
// Must be of 'immediate' type but not a constant.
if (!isImm() || evaluateConstantImm(getImm(), Imm))
return false;

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
(VK == RISCVMCExpr::VK_CALL || VK == RISCVMCExpr::VK_CALL_PLT);
}

bool isPseudoJumpSymbol() const {
int64_t Imm;
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
// Must be of 'immediate' type but not a constant.
if (!isImm() || evaluateConstantImm(getImm(), Imm))
return false;

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
VK == RISCVMCExpr::VK_CALL;
}

bool isTPRelAddSymbol() const {
int64_t Imm;
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
// Must be of 'immediate' type but not a constant.
if (!isImm() || evaluateConstantImm(getImm(), Imm))
return false;

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
VK == RISCVMCExpr::VK_TPREL_ADD;
}

bool isTLSDESCCallSymbol() const {
int64_t Imm;
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
// Must be of 'immediate' type but not a constant.
if (!isImm() || evaluateConstantImm(getImm(), Imm))
return false;

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
VK == RISCVMCExpr::VK_TLSDESC_CALL;
}
Expand Down Expand Up @@ -838,19 +843,17 @@ struct RISCVOperand final : public MCParsedAsmOperand {
}

bool isSImm12() const {
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
int64_t Imm;
bool IsValid;
if (!isImm())
return false;
bool IsConstantImm = evaluateConstantImm(getImm(), Imm);
if (!IsConstantImm)
IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK);
else
IsValid = isInt<12>(fixImmediateForRV32(Imm, isRV64Imm()));
return IsValid &&
(IsConstantImm || VK == RISCVMCExpr::VK_LO ||
VK == RISCVMCExpr::VK_PCREL_LO || VK == RISCVMCExpr::VK_TPREL_LO ||

int64_t Imm;
if (evaluateConstantImm(getImm(), Imm))
return isInt<12>(fixImmediateForRV32(Imm, isRV64Imm()));

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
(VK == RISCVMCExpr::VK_LO || VK == RISCVMCExpr::VK_PCREL_LO ||
VK == RISCVMCExpr::VK_TPREL_LO ||
VK == RISCVMCExpr::VK_TLSDESC_LOAD_LO ||
VK == RISCVMCExpr::VK_TLSDESC_ADD_LO);
}
Expand All @@ -873,26 +876,27 @@ struct RISCVOperand final : public MCParsedAsmOperand {
}

bool isUImm20LUI() const {
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
int64_t Imm;
if (!isImm())
return false;
bool IsConstantImm = evaluateConstantImm(getImm(), Imm);
if (IsConstantImm)

int64_t Imm;
if (evaluateConstantImm(getImm(), Imm))
return isUInt<20>(Imm);

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
(VK == RISCVMCExpr::VK_HI || VK == RISCVMCExpr::VK_TPREL_HI);
}

bool isUImm20AUIPC() const {
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
int64_t Imm;
if (!isImm())
return false;
bool IsConstantImm = evaluateConstantImm(getImm(), Imm);
if (IsConstantImm)

int64_t Imm;
if (evaluateConstantImm(getImm(), Imm))
return isUInt<20>(Imm);

RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
return RISCVAsmParser::classifySymbolRef(getImm(), VK) &&
(VK == RISCVMCExpr::VK_PCREL_HI || VK == RISCVMCExpr::VK_GOT_HI ||
VK == RISCVMCExpr::VK_TLS_GOT_HI ||
Expand Down