-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ARM] Auto-decode vpred_n/vpred_r operands #160282
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
s-barannikov
merged 2 commits into
llvm:main
from
s-barannikov:tablegen/decoder/arm-vpred
Oct 4, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -639,6 +639,43 @@ static DecodeStatus DecodeCCOutOperand(MCInst &Inst, | |
return MCDisassembler::Success; | ||
} | ||
|
||
static DecodeStatus DecodeVpredNOperand(MCInst &Inst, | ||
const MCDisassembler *Decoder) { | ||
const auto *D = static_cast<const ARMDisassembler *>(Decoder); | ||
unsigned VCC = D->VPTBlock.getVPTPred(); | ||
MCRegister CondReg = VCC == ARMVCC::None ? ARM::NoRegister : ARM::P0; | ||
|
||
Inst.addOperand(MCOperand::createImm(VCC)); // $cond | ||
Inst.addOperand(MCOperand::createReg(CondReg)); // $cond_reg | ||
Inst.addOperand(MCOperand::createReg(ARM::NoRegister)); // $tp_reg | ||
|
||
return MCDisassembler::Success; | ||
} | ||
|
||
static DecodeStatus DecodeVpredROperand(MCInst &Inst, | ||
const MCDisassembler *Decoder) { | ||
const auto *D = static_cast<const ARMDisassembler *>(Decoder); | ||
unsigned VCC = D->VPTBlock.getVPTPred(); | ||
MCRegister CondReg = VCC == ARMVCC::None ? ARM::NoRegister : ARM::P0; | ||
|
||
Inst.addOperand(MCOperand::createImm(VCC)); // $cond | ||
Inst.addOperand(MCOperand::createReg(CondReg)); // $cond_reg | ||
Inst.addOperand(MCOperand::createReg(ARM::NoRegister)); // $tp_reg | ||
|
||
// The last sub-operand ($inactive) is tied to an output operand. | ||
// The output operand has already been decoded, so just copy it. | ||
const MCInstrDesc &MCID = D->MCII->get(Inst.getOpcode()); | ||
unsigned InactiveOpIdx = Inst.getNumOperands(); | ||
int TiedOpIdx = MCID.getOperandConstraint(InactiveOpIdx, MCOI::TIED_TO); | ||
assert(TiedOpIdx >= 0 && | ||
"Inactive register in vpred_r is not tied to an output!"); | ||
|
||
// Make a copy of the operand to ensure it is not invalidated when MI grows. | ||
Inst.addOperand(MCOperand(Inst.getOperand(TiedOpIdx))); // $inactive | ||
|
||
return MCDisassembler::Success; | ||
} | ||
|
||
static DecodeStatus DecodeSORegImmOperand(MCInst &Inst, unsigned Val, | ||
uint64_t Address, | ||
const MCDisassembler *Decoder) { | ||
|
@@ -2777,6 +2814,7 @@ static DecodeStatus DecodeMVEModImmInstruction(MCInst &Inst, unsigned Insn, | |
|
||
Inst.addOperand(MCOperand::createImm(imm)); | ||
|
||
Check(S, DecodeVpredROperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -2802,6 +2840,7 @@ static DecodeStatus DecodeMVEVADCInstruction(MCInst &Inst, unsigned Insn, | |
if (!fieldFromInstruction(Insn, 12, 1)) // I bit clear => need input FPSCR | ||
Inst.addOperand(MCOperand::createReg(ARM::FPSCR_NZCV)); | ||
|
||
Check(S, DecodeVpredROperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -5466,30 +5505,6 @@ static DecodeStatus DecodeVPTMaskOperand(MCInst &Inst, unsigned Val, | |
return S; | ||
} | ||
|
||
static DecodeStatus DecodeVpredROperand(MCInst &Inst, unsigned RegNo, | ||
uint64_t Address, | ||
const MCDisassembler *Decoder) { | ||
// The vpred_r operand type includes an MQPR register field derived | ||
// from the encoding. But we don't actually want to add an operand | ||
// to the MCInst at this stage, because AddThumbPredicate will do it | ||
// later, and will infer the register number from the TIED_TO | ||
// constraint. So this is a deliberately empty decoder method that | ||
// will inhibit the auto-generated disassembly code from adding an | ||
// operand at all. | ||
return MCDisassembler::Success; | ||
} | ||
|
||
[[maybe_unused]] static DecodeStatus | ||
DecodeVpredNOperand(MCInst &Inst, unsigned RegNo, uint64_t Address, | ||
const MCDisassembler *Decoder) { | ||
// Similar to above, we want to ensure that no operands are added for the | ||
// vpred operands. (This is marked "maybe_unused" for the moment; because | ||
// DecoderEmitter currently (wrongly) omits operands with no instruction bits, | ||
// the decoder doesn't actually call it yet. That will be addressed in a | ||
// future change.) | ||
return MCDisassembler::Success; | ||
} | ||
|
||
static DecodeStatus | ||
DecodeRestrictedIPredicateOperand(MCInst &Inst, unsigned Val, uint64_t Address, | ||
const MCDisassembler *Decoder) { | ||
|
@@ -5668,6 +5683,7 @@ DecodeMVE_MEM_pre(MCInst &Inst, unsigned Val, uint64_t Address, | |
if (!Check(S, AddrDecoder(Inst, addr, Address, Decoder))) | ||
return MCDisassembler::Fail; | ||
|
||
Check(S, DecodeVpredNOperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -5871,7 +5887,7 @@ static DecodeStatus DecodeMVEVCVTt1fp(MCInst &Inst, unsigned Insn, | |
return MCDisassembler::Fail; | ||
if (!Check(S, DecodeVCVTImmOperand(Inst, imm6, Address, Decoder))) | ||
return MCDisassembler::Fail; | ||
|
||
Check(S, DecodeVpredROperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -5906,6 +5922,7 @@ static DecodeStatus DecodeMVEVCMP(MCInst &Inst, unsigned Insn, uint64_t Address, | |
if (!Check(S, predicate_decoder(Inst, fc, Address, Decoder))) | ||
return MCDisassembler::Fail; | ||
|
||
Check(S, DecodeVpredNOperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -5916,6 +5933,7 @@ static DecodeStatus DecodeMveVCTP(MCInst &Inst, unsigned Insn, uint64_t Address, | |
unsigned Rn = fieldFromInstruction(Insn, 16, 4); | ||
if (!Check(S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder))) | ||
return MCDisassembler::Fail; | ||
Check(S, DecodeVpredNOperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -5925,6 +5943,7 @@ static DecodeStatus DecodeMVEVPNOT(MCInst &Inst, unsigned Insn, | |
DecodeStatus S = MCDisassembler::Success; | ||
Inst.addOperand(MCOperand::createReg(ARM::VPR)); | ||
Inst.addOperand(MCOperand::createReg(ARM::VPR)); | ||
Check(S, DecodeVpredNOperand(Inst, Decoder)); | ||
return S; | ||
} | ||
|
||
|
@@ -6199,15 +6218,13 @@ ARMDisassembler::AddThumbPredicate(MCInst &MI) const { | |
(isVectorPredicable(MI) && ITBlock.instrInITBlock())) | ||
S = SoftFail; | ||
|
||
// If we're in an IT/VPT block, base the predicate on that. Otherwise, | ||
// If we're in an IT block, base the predicate on that. Otherwise, | ||
// assume a predicate of AL. | ||
unsigned CC = ARMCC::AL; | ||
unsigned VCC = ARMVCC::None; | ||
if (ITBlock.instrInITBlock()) { | ||
CC = ITBlock.getITCC(); | ||
ITBlock.advanceITState(); | ||
} else if (VPTBlock.instrInVPTBlock()) { | ||
VCC = VPTBlock.getVPTPred(); | ||
VPTBlock.advanceVPTState(); | ||
} | ||
|
||
|
@@ -6230,34 +6247,6 @@ ARMDisassembler::AddThumbPredicate(MCInst &MI) const { | |
Check(S, SoftFail); | ||
} | ||
|
||
MCInst::iterator VCCI = MI.begin(); | ||
unsigned VCCPos; | ||
for (VCCPos = 0; VCCPos < MCID.NumOperands; ++VCCPos, ++VCCI) { | ||
if (ARM::isVpred(MCID.operands()[VCCPos].OperandType) || VCCI == MI.end()) | ||
break; | ||
} | ||
|
||
if (isVectorPredicable(MI)) { | ||
VCCI = MI.insert(VCCI, MCOperand::createImm(VCC)); | ||
++VCCI; | ||
if (VCC == ARMVCC::None) | ||
VCCI = MI.insert(VCCI, MCOperand::createReg(0)); | ||
else | ||
VCCI = MI.insert(VCCI, MCOperand::createReg(ARM::P0)); | ||
++VCCI; | ||
VCCI = MI.insert(VCCI, MCOperand::createReg(0)); | ||
++VCCI; | ||
if (MCID.operands()[VCCPos].OperandType == ARM::OPERAND_VPRED_R) { | ||
int TiedOp = MCID.getOperandConstraint(VCCPos + 3, MCOI::TIED_TO); | ||
assert(TiedOp >= 0 && | ||
"Inactive register in vpred_r is not tied to an output!"); | ||
// Copy the operand to ensure it's not invalidated when MI grows. | ||
MI.insert(VCCI, MCOperand(MI.getOperand(TiedOp))); | ||
} | ||
} else if (VCC != ARMVCC::None) { | ||
Check(S, SoftFail); | ||
} | ||
Comment on lines
-6257
to
-6259
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. The SoftFail case is already checked above (line 6200 on the left). |
||
|
||
return S; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The operand decoder can never fail/softfail, I left the
Check
because that's what a generated instruction decoder would do.