[llvm] [RISCV] Cleanup assembler predicates after #133377. (PR #133652)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 30 12:52:33 PDT 2025
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/133652
Make isSImm12 look more like isUImm20LUI.
Move variables closer to their use.
Fold some function calls into if statements.
>From 4f704459d42b78307f9d5796d8c2ff6cee1cafde Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sun, 30 Mar 2025 12:49:20 -0700
Subject: [PATCH] [RISCV] Cleanup assembler predicates after #133377.
Make isSImm12 look more like isUImm20LUI.
Move variables closer to their use.
Fold some function calls into if statements.
---
.../Target/RISCV/AsmParser/RISCVAsmParser.cpp | 52 ++++++++++---------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 52b38c19873c1..63d0777e4ff52 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -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;
}
@@ -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);
}
@@ -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 ||
More information about the llvm-commits
mailing list