Skip to content

Commit a46b797

Browse files
[ARM][TableGen][MC] Change the ARM mnemonic operands to be optional for ASM parsing
This changs the way the assembly matcher works for Aarch32 parsing. Previously there was a pile of hacks which dictated whether the CC and CCOut operands should be present which de-facto chose if the wide/narrow (or thumb1/thumb2/arm) instruction version were chosen. This meant much of the TableGen machinery present for the assembly matching was effectively being bypassed and worked around. This patch makes the CC and CCOut operands optional which allows the ASM matcher operate as it was designed and means we can avoid doing some of the hacks done previously. This also adds the option for the target to allow the prioritizing the smaller instruction encodings as is required for Aarch32.
1 parent 083ff70 commit a46b797

21 files changed

+802
-607
lines changed

llvm/include/llvm/Target/Target.td

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,18 @@ class AsmOperandClass {
948948
/// error will be suppressed if all of the remaining unmatched operands are
949949
/// marked as IsOptional.
950950
///
951-
/// Optional arguments must be at the end of the operand list.
951+
/// Note: Optional arguments have caveats if they are not at the end of this list
952+
/// when regarding custom operand parsing. See below
952953
bit IsOptional = false;
953954

955+
// Fixme: Ideally this would not be necessary however this would involve interleaving the
956+
// parsing and matching processes.
957+
/// Set to 1 if the parser should assume this operand will always be present
958+
/// for the sake of calculating the operand index in regards to which custom operand
959+
/// parser should be used.
960+
/// This is only used for custom operands that are not at the end of the instruction.
961+
bit OptionalShouldOffsetCustomParsers = true;
962+
954963
/// The name of the method on the target specific asm parser that returns the
955964
/// default operand for this optional operand. This method is only used if
956965
/// IsOptional == 1. If not set, this will default to "defaultFooOperands",

llvm/lib/Target/ARM/ARM.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,4 +1747,5 @@ def ARM : Target {
17471747
let AssemblyParsers = [ARMAsmParser];
17481748
let AssemblyParserVariants = [ARMAsmParserVariant];
17491749
let AllowRegisterRenaming = 1;
1750+
let PreferSmallerInstructions= true;
17501751
}

llvm/lib/Target/ARM/ARMInstrFormats.td

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ def iflags_op : Operand<i32> {
155155

156156
// ARM Predicate operand. Default to 14 = always (AL). Second part is CC
157157
// register whose default is 0 (no register).
158-
def CondCodeOperand : AsmOperandClass { let Name = "CondCode"; }
158+
def CondCodeOperand : AsmOperandClass {
159+
let Name = "CondCode";
160+
let PredicateMethod = "isCondCode";
161+
let DefaultMethod = "defaultCondCodeOp";
162+
let IsOptional = true;
163+
let OptionalShouldOffsetCustomParsers = false;
164+
}
159165
def pred : PredicateOperand<OtherVT, (ops i32imm, i32imm),
160166
(ops (i32 14), (i32 zero_reg))> {
161167
let PrintMethod = "printPredicateOperand";
@@ -174,7 +180,12 @@ def cmovpred : Operand<i32>, PredicateOp,
174180
}
175181

176182
// Conditional code result for instructions whose 's' bit is set, e.g. subs.
177-
def CCOutOperand : AsmOperandClass { let Name = "CCOut"; }
183+
def CCOutOperand : AsmOperandClass {
184+
let Name = "CCOut";
185+
let DefaultMethod = "defaultCCOutOp";
186+
let IsOptional = true;
187+
let OptionalShouldOffsetCustomParsers = false;
188+
}
178189
def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
179190
let EncoderMethod = "getCCOutOpValue";
180191
let PrintMethod = "printSBitModifierOperand";
@@ -468,7 +479,7 @@ class InstThumb<AddrMode am, int sz, IndexMode im,
468479
// These are aliases that require C++ handling to convert to the target
469480
// instruction, while InstAliases can be handled directly by tblgen.
470481
class AsmPseudoInst<string asm, dag iops, dag oops = (outs)>
471-
: InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
482+
: InstTemplate<AddrModeNone, 4, IndexModeNone, Pseudo, GenericDomain,
472483
"", NoItinerary> {
473484
let OutOperandList = oops;
474485
let InOperandList = iops;

0 commit comments

Comments
 (0)