Skip to content

Commit a1cd51c

Browse files
[ARM and TableGen] Change the ARM predicate operands to be optional
This changed the way the assembly matcher works. Previously there was a pile of hacks which dictated whether the CC and CCOut operands should be present which defacto chose which instruction version was used. This meant much of the machinery present for the assembly matching was effectively being bi-passed 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. Change-Id: I6e308487b0e722adfc1f28ef4fa904b50144696a
1 parent 8ef9d24 commit a1cd51c

22 files changed

+840
-607
lines changed

llvm/include/llvm/Target/Target.td

Lines changed: 15 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",
@@ -1724,6 +1733,11 @@ class Target {
17241733
// setting hasExtraDefRegAllocReq and hasExtraSrcRegAllocReq to 1
17251734
// for all opcodes if this flag is set to 0.
17261735
int AllowRegisterRenaming = 0;
1736+
1737+
// SortBySize = Should the assembly matcher prefer the smaller
1738+
// instructions. 1 if the instruction set should sort by size,
1739+
// 0 otherwise.
1740+
int SortBySize = 0;
17271741
}
17281742

17291743
//===----------------------------------------------------------------------===//

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 SortBySize = 1;
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)