-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[RISCV] Align MCOperandPredicates with AsmParser #146184
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,12 +63,29 @@ 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() && "isBareSymbolRef expects only expressions"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you maybe want to change the assert to say isSimpleSymbolRef instead of isBareSymbolRef? |
||
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: | ||
case MCExpr::Target: | ||
break; | ||
case MCExpr::SymbolRef: | ||
Specifier = cast<MCSymbolRefExpr>(Expr)->getSpecifier(); | ||
return true; | ||
case MCExpr::Specifier: | ||
Specifier = cast<MCSpecifierExpr>(Expr)->getSpecifier(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,12 +327,20 @@ def uimm16 : RISCVUImmOp<16>; | |
def uimm32 : RISCVUImmOp<32>; | ||
def uimm48 : RISCVUImmOp<48>; | ||
def uimm64 : RISCVUImmOp<64>; | ||
|
||
def simm12 : RISCVSImmLeafOp<12> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the urge to call this something like |
||
let MCOperandPredicate = [{ | ||
int64_t Imm; | ||
if (MCOp.evaluateAsConstantImm(Imm)) | ||
return isInt<12>(Imm); | ||
return MCOp.isBareSymbolRef(); | ||
|
||
MCExpr::Spec S; | ||
if (!MCOp.isExpr() || !MCOp.isSimpleSymbolRef(S)) | ||
return false; | ||
|
||
return (S == RISCV::S_LO) || (S == RISCV::S_PCREL_LO) || | ||
(S == RISCV::S_TPREL_LO) || (S == ELF::R_RISCV_TLSDESC_LOAD_LO12) || | ||
(S == ELF::R_RISCV_TLSDESC_ADD_LO12); | ||
}]; | ||
} | ||
|
||
|
@@ -368,20 +376,37 @@ def bare_simm13_lsb0 : BareSImm13Lsb0MaybeSym, | |
// is used to match with a basic block (eg. BccPat<>). | ||
def bare_simm13_lsb0_bb : BareSImm13Lsb0MaybeSym; | ||
|
||
class UImm20OperandMaybeSym : RISCVUImmOp<20> { | ||
def uimm20_lui : RISCVUImmOp<20> { | ||
let ParserMatchClass = UImmAsmOperand<20, "LUI">; | ||
let MCOperandPredicate = [{ | ||
int64_t Imm; | ||
if (MCOp.evaluateAsConstantImm(Imm)) | ||
return isUInt<20>(Imm); | ||
return MCOp.isBareSymbolRef(); | ||
}]; | ||
} | ||
|
||
def uimm20_lui : UImm20OperandMaybeSym { | ||
let ParserMatchClass = UImmAsmOperand<20, "LUI">; | ||
MCExpr::Spec S; | ||
if (!MCOp.isExpr() || !MCOp.isSimpleSymbolRef(S)) | ||
return false; | ||
|
||
return (S == ELF::R_RISCV_HI20) || | ||
(S == ELF::R_RISCV_TPREL_HI20); | ||
}]; | ||
} | ||
def uimm20_auipc : UImm20OperandMaybeSym { | ||
def uimm20_auipc : RISCVUImmOp<20> { | ||
let ParserMatchClass = UImmAsmOperand<20, "AUIPC">; | ||
let MCOperandPredicate = [{ | ||
int64_t Imm; | ||
if (MCOp.evaluateAsConstantImm(Imm)) | ||
return isUInt<20>(Imm); | ||
|
||
MCExpr::Spec S; | ||
if (!MCOp.isExpr() || !MCOp.isSimpleSymbolRef(S)) | ||
return false; | ||
|
||
return (S == ELF::R_RISCV_PCREL_HI20) || (S == ELF::R_RISCV_GOT_HI20) || | ||
(S == ELF::R_RISCV_TLS_GOT_HI20) || | ||
(S == ELF::R_RISCV_TLS_GD_HI20) || | ||
(S == ELF::R_RISCV_TLSDESC_HI20); | ||
}]; | ||
} | ||
|
||
def uimm20 : RISCVUImmOp<20>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should try eliminating isBareSymbolRef instead of adding more variants...