[llvm] [RISCV] Cleanup assembler predicates after #133377. (PR #133652)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 30 12:53:05 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
Make isSImm12 look more like isUImm20LUI.
Move variables closer to their use.
Fold some function calls into if statements.
---
Full diff: https://github.com/llvm/llvm-project/pull/133652.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+28-24)
``````````diff
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 ||
``````````
</details>
https://github.com/llvm/llvm-project/pull/133652
More information about the llvm-commits
mailing list