[llvm] [RISCV] Align MCOperandPredicates with AsmParser (PR #146184)
Sam Elliott via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 23:05:38 PDT 2025
================
@@ -63,12 +63,31 @@ bool MCOperand::evaluateAsConstantImm(int64_t &Imm) const {
}
bool MCOperand::isBareSymbolRef() const {
- assert(isExpr() &&
- "isBareSymbolRef expects only expressions");
+ MCExpr::Spec Specifier;
+ return isSimpleSymbolRef(Specifier) && Specifier == 0;
+}
+
+bool MCOperand::isSimpleSymbolRef(MCExpr::Spec &Specifier) const {
+ assert(isExpr() && "isSimpleSymbolRef expects only expressions");
const MCExpr *Expr = getExpr();
MCExpr::ExprKind Kind = getExpr()->getKind();
- return Kind == MCExpr::SymbolRef &&
- cast<MCSymbolRefExpr>(Expr)->getSpecifier() == 0;
+
+ switch (Kind) {
+ case MCExpr::Binary:
+ case MCExpr::Unary:
+ case MCExpr::Constant:
+ break;
+ case MCExpr::Target:
+ // It's not clear this is right, does MCTargetExpr need another virtual method?
+ break;
+ case MCExpr::SymbolRef:
+ Specifier = cast<MCSymbolRefExpr>(Expr)->getSpecifier();
+ return true;
+ case MCExpr::Specifier:
+ Specifier = cast<MCSpecifierExpr>(Expr)->getSpecifier();
+ return true;
+ }
+ return false;
----------------
lenary wrote:
@MaskRay it would be good to understand your view on this method - the aim is to effectively capture everywhere which is just a specifier and one symbol, extracting the specifier - like what `RISCVAsmParser::classifySymbolRef` does.
I haven't had to cover MCTargetExpr because only RISC-V uses this method right now, and that backend now uses MCSpecifierExpr. I guess maybe I should be using `Expr->evaluateAsRelocatable(...))` and looking at the resulting `MCValue`, rather than adding a new virtual method?
https://github.com/llvm/llvm-project/pull/146184
More information about the llvm-commits
mailing list