10b57cec5SDimitry Andric//===- TargetInstrPredicate.td - ---------------------------*- tablegen -*-===// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric// 90b57cec5SDimitry Andric// This file defines class MCInstPredicate and its subclasses. 100b57cec5SDimitry Andric// 110b57cec5SDimitry Andric// MCInstPredicate definitions are used by target scheduling models to describe 120b57cec5SDimitry Andric// constraints on instructions. 130b57cec5SDimitry Andric// 14e8d8bef9SDimitry Andric// Here is an example of an MCInstPredicate definition in TableGen: 150b57cec5SDimitry Andric// 160b57cec5SDimitry Andric// def MCInstPredicateExample : CheckAll<[ 170b57cec5SDimitry Andric// CheckOpcode<[BLR]>, 180b57cec5SDimitry Andric// CheckIsRegOperand<0>, 190b57cec5SDimitry Andric// CheckNot<CheckRegOperand<0, LR>>]>; 200b57cec5SDimitry Andric// 210b57cec5SDimitry Andric// The syntax for MCInstPredicate is declarative, and predicate definitions can 220b57cec5SDimitry Andric// be composed together in order to generate more complex constraints. 230b57cec5SDimitry Andric// 240b57cec5SDimitry Andric// The `CheckAll` from the example defines a composition of three different 250b57cec5SDimitry Andric// predicates. Definition `MCInstPredicateExample` identifies instructions 260b57cec5SDimitry Andric// whose opcode is BLR, and whose first operand is a register different from 270b57cec5SDimitry Andric// register `LR`. 280b57cec5SDimitry Andric// 290b57cec5SDimitry Andric// Every MCInstPredicate class has a well-known semantic in tablegen. For 300b57cec5SDimitry Andric// example, `CheckOpcode` is a special type of predicate used to describe a 310b57cec5SDimitry Andric// constraint on the value of an instruction opcode. 320b57cec5SDimitry Andric// 330b57cec5SDimitry Andric// MCInstPredicate definitions are typically used by scheduling models to 340b57cec5SDimitry Andric// construct MCSchedPredicate definitions (see the definition of class 350b57cec5SDimitry Andric// MCSchedPredicate in llvm/Target/TargetSchedule.td). 360b57cec5SDimitry Andric// In particular, an MCSchedPredicate can be used instead of a SchedPredicate 370b57cec5SDimitry Andric// when defining the set of SchedReadVariant and SchedWriteVariant of a 380b57cec5SDimitry Andric// processor scheduling model. 390b57cec5SDimitry Andric// 400b57cec5SDimitry Andric// The `MCInstPredicateExample` definition above is equivalent (and therefore 410b57cec5SDimitry Andric// could replace) the following definition from a previous ExynosM3 model (see 420b57cec5SDimitry Andric// AArch64SchedExynosM3.td): 430b57cec5SDimitry Andric// 440b57cec5SDimitry Andric// def M3BranchLinkFastPred : SchedPredicate<[{ 450b57cec5SDimitry Andric// MI->getOpcode() == AArch64::BLR && 460b57cec5SDimitry Andric// MI->getOperand(0).isReg() && 470b57cec5SDimitry Andric// MI->getOperand(0).getReg() != AArch64::LR}]>; 480b57cec5SDimitry Andric// 490b57cec5SDimitry Andric// The main advantage of using MCInstPredicate instead of SchedPredicate is 500b57cec5SDimitry Andric// portability: users don't need to specify predicates in C++. As a consequence 510b57cec5SDimitry Andric// of this, MCInstPredicate definitions are not bound to a particular 520b57cec5SDimitry Andric// representation (i.e. MachineInstr vs MCInst). 530b57cec5SDimitry Andric// 540b57cec5SDimitry Andric// Tablegen backends know how to expand MCInstPredicate definitions into actual 550b57cec5SDimitry Andric// C++ code that works on MachineInstr (and/or MCInst). 560b57cec5SDimitry Andric// 570b57cec5SDimitry Andric// Instances of class PredicateExpander (see utils/Tablegen/PredicateExpander.h) 580b57cec5SDimitry Andric// know how to expand a predicate. For each MCInstPredicate class, there must be 590b57cec5SDimitry Andric// an "expand" method available in the PredicateExpander interface. 600b57cec5SDimitry Andric// 610b57cec5SDimitry Andric// For example, a `CheckOpcode` predicate is expanded using method 620b57cec5SDimitry Andric// `PredicateExpander::expandCheckOpcode()`. 630b57cec5SDimitry Andric// 640b57cec5SDimitry Andric// New MCInstPredicate classes must be added to this file. For each new class 650b57cec5SDimitry Andric// XYZ, an "expandXYZ" method must be added to the PredicateExpander. 660b57cec5SDimitry Andric// 670b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric// Forward declarations. 700b57cec5SDimitry Andricclass Instruction; 710b57cec5SDimitry Andricclass SchedMachineModel; 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric// A generic machine instruction predicate. 740b57cec5SDimitry Andricclass MCInstPredicate; 750b57cec5SDimitry Andric 760b57cec5SDimitry Andricclass MCTrue : MCInstPredicate; // A predicate that always evaluates to True. 770b57cec5SDimitry Andricclass MCFalse : MCInstPredicate; // A predicate that always evaluates to False. 780b57cec5SDimitry Andricdef TruePred : MCTrue; 790b57cec5SDimitry Andricdef FalsePred : MCFalse; 800b57cec5SDimitry Andric 810b57cec5SDimitry Andric// A predicate used to negate the outcome of another predicate. 820b57cec5SDimitry Andric// It allows to easily express "set difference" operations. For example, it 830b57cec5SDimitry Andric// makes it easy to describe a check that tests if an opcode is not part of a 840b57cec5SDimitry Andric// set of opcodes. 850b57cec5SDimitry Andricclass CheckNot<MCInstPredicate P> : MCInstPredicate { 860b57cec5SDimitry Andric MCInstPredicate Pred = P; 870b57cec5SDimitry Andric} 880b57cec5SDimitry Andric 890b57cec5SDimitry Andric// This class is used as a building block to define predicates on instruction 900b57cec5SDimitry Andric// operands. It is used to reference a specific machine operand. 910b57cec5SDimitry Andricclass MCOperandPredicate<int Index> : MCInstPredicate { 920b57cec5SDimitry Andric int OpIndex = Index; 930b57cec5SDimitry Andric} 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric// Return true if machine operand at position `Index` is a register operand. 960b57cec5SDimitry Andricclass CheckIsRegOperand<int Index> : MCOperandPredicate<Index>; 970b57cec5SDimitry Andric 981db9f3b2SDimitry Andric// Return true if machine operand at position `Index` is a virtual register operand. 991db9f3b2SDimitry Andricclass CheckIsVRegOperand<int Index> : MCOperandPredicate<Index>; 1001db9f3b2SDimitry Andric 1011db9f3b2SDimitry Andric// Return true if machine operand at position `Index` is not a virtual register operand. 1021db9f3b2SDimitry Andricclass CheckIsNotVRegOperand<int Index> : CheckNot<CheckIsVRegOperand<Index>>; 1031db9f3b2SDimitry Andric 1040b57cec5SDimitry Andric// Return true if machine operand at position `Index` is an immediate operand. 1050b57cec5SDimitry Andricclass CheckIsImmOperand<int Index> : MCOperandPredicate<Index>; 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric// Check if machine operands at index `First` and index `Second` both reference 1080b57cec5SDimitry Andric// the same register. 1090b57cec5SDimitry Andricclass CheckSameRegOperand<int First, int Second> : MCInstPredicate { 1100b57cec5SDimitry Andric int FirstIndex = First; 1110b57cec5SDimitry Andric int SecondIndex = Second; 1120b57cec5SDimitry Andric} 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric// Base class for checks on register/immediate operands. 1150b57cec5SDimitry Andric// It allows users to define checks like: 1160b57cec5SDimitry Andric// MyFunction(MI->getOperand(Index).getImm()) == Val; 1170b57cec5SDimitry Andric// 1180b57cec5SDimitry Andric// In the example above, `MyFunction` is a function that takes as input an 1190b57cec5SDimitry Andric// immediate operand value, and returns another value. Field `FunctionMapper` is 1200b57cec5SDimitry Andric// the name of the function to call on the operand value. 1210b57cec5SDimitry Andricclass CheckOperandBase<int Index, string Fn = ""> : MCOperandPredicate<Index> { 1220b57cec5SDimitry Andric string FunctionMapper = Fn; 1230b57cec5SDimitry Andric} 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric// Check that the machine register operand at position `Index` references 1260b57cec5SDimitry Andric// register R. This predicate assumes that we already checked that the machine 1270b57cec5SDimitry Andric// operand at position `Index` is a register operand. 1280b57cec5SDimitry Andricclass CheckRegOperand<int Index, Register R> : CheckOperandBase<Index> { 1290b57cec5SDimitry Andric Register Reg = R; 1300b57cec5SDimitry Andric} 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric// Check if register operand at index `Index` is the invalid register. 1330b57cec5SDimitry Andricclass CheckInvalidRegOperand<int Index> : CheckOperandBase<Index>; 1340b57cec5SDimitry Andric 135e8d8bef9SDimitry Andric// Return true if machine operand at position `Index` is a valid 136e8d8bef9SDimitry Andric// register operand. 137e8d8bef9SDimitry Andricclass CheckValidRegOperand<int Index> : 138e8d8bef9SDimitry Andric CheckNot<CheckInvalidRegOperand<Index>>; 139e8d8bef9SDimitry Andric 1400b57cec5SDimitry Andric// Check that the operand at position `Index` is immediate `Imm`. 1410b57cec5SDimitry Andric// If field `FunctionMapper` is a non-empty string, then function 1420b57cec5SDimitry Andric// `FunctionMapper` is applied to the operand value, and the return value is then 1430b57cec5SDimitry Andric// compared against `Imm`. 1440b57cec5SDimitry Andricclass CheckImmOperand<int Index, int Imm> : CheckOperandBase<Index> { 1450b57cec5SDimitry Andric int ImmVal = Imm; 1460b57cec5SDimitry Andric} 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric// Similar to CheckImmOperand, however the immediate is not a literal number. 1490b57cec5SDimitry Andric// This is useful when we want to compare the value of an operand against an 1500b57cec5SDimitry Andric// enum value, and we know the actual integer value of that enum. 1510b57cec5SDimitry Andricclass CheckImmOperand_s<int Index, string Value> : CheckOperandBase<Index> { 1520b57cec5SDimitry Andric string ImmVal = Value; 1530b57cec5SDimitry Andric} 1540b57cec5SDimitry Andric 155b3edf446SDimitry Andric// Check that the operand at position `Index` is less than `Imm`. 156b3edf446SDimitry Andric// If field `FunctionMapper` is a non-empty string, then function 157b3edf446SDimitry Andric// `FunctionMapper` is applied to the operand value, and the return value is then 158b3edf446SDimitry Andric// compared against `Imm`. 159b3edf446SDimitry Andricclass CheckImmOperandLT<int Index, int Imm> : CheckOperandBase<Index> { 160b3edf446SDimitry Andric int ImmVal = Imm; 161b3edf446SDimitry Andric} 162b3edf446SDimitry Andric 163b3edf446SDimitry Andric// Check that the operand at position `Index` is greater than `Imm`. 164b3edf446SDimitry Andric// If field `FunctionMapper` is a non-empty string, then function 165b3edf446SDimitry Andric// `FunctionMapper` is applied to the operand value, and the return value is then 166b3edf446SDimitry Andric// compared against `Imm`. 167b3edf446SDimitry Andricclass CheckImmOperandGT<int Index, int Imm> : CheckOperandBase<Index> { 168b3edf446SDimitry Andric int ImmVal = Imm; 169b3edf446SDimitry Andric} 170b3edf446SDimitry Andric 171b3edf446SDimitry Andric// Check that the operand at position `Index` is less than or equal to `Imm`. 172b3edf446SDimitry Andric// If field `FunctionMapper` is a non-empty string, then function 173b3edf446SDimitry Andric// `FunctionMapper` is applied to the operand value, and the return value is then 174b3edf446SDimitry Andric// compared against `Imm`. 175b3edf446SDimitry Andricclass CheckImmOperandLE<int Index, int Imm> : CheckNot<CheckImmOperandGT<Index, Imm>>; 176b3edf446SDimitry Andric 177b3edf446SDimitry Andric// Check that the operand at position `Index` is greater than or equal to `Imm`. 178b3edf446SDimitry Andric// If field `FunctionMapper` is a non-empty string, then function 179b3edf446SDimitry Andric// `FunctionMapper` is applied to the operand value, and the return value is then 180b3edf446SDimitry Andric// compared against `Imm`. 181b3edf446SDimitry Andricclass CheckImmOperandGE<int Index, int Imm> : CheckNot<CheckImmOperandLT<Index, Imm>>; 182b3edf446SDimitry Andric 1830b57cec5SDimitry Andric// Expands to a call to `FunctionMapper` if field `FunctionMapper` is set. 1840b57cec5SDimitry Andric// Otherwise, it expands to a CheckNot<CheckInvalidRegOperand<Index>>. 1850b57cec5SDimitry Andricclass CheckRegOperandSimple<int Index> : CheckOperandBase<Index>; 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric// Expands to a call to `FunctionMapper` if field `FunctionMapper` is set. 1880b57cec5SDimitry Andric// Otherwise, it simply evaluates to TruePred. 1890b57cec5SDimitry Andricclass CheckImmOperandSimple<int Index> : CheckOperandBase<Index>; 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric// Check that the operand at position `Index` is immediate value zero. 1920b57cec5SDimitry Andricclass CheckZeroOperand<int Index> : CheckImmOperand<Index, 0>; 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric// Check that the instruction has exactly `Num` operands. 1950b57cec5SDimitry Andricclass CheckNumOperands<int Num> : MCInstPredicate { 1960b57cec5SDimitry Andric int NumOps = Num; 1970b57cec5SDimitry Andric} 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andric// Check that the instruction opcode is one of the opcodes in set `Opcodes`. 2000b57cec5SDimitry Andric// This is a simple set membership query. The easier way to check if an opcode 2010b57cec5SDimitry Andric// is not a member of the set is by using a `CheckNot<CheckOpcode<[...]>>` 2020b57cec5SDimitry Andric// sequence. 2030b57cec5SDimitry Andricclass CheckOpcode<list<Instruction> Opcodes> : MCInstPredicate { 2040b57cec5SDimitry Andric list<Instruction> ValidOpcodes = Opcodes; 2050b57cec5SDimitry Andric} 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andric// Check that the instruction opcode is a pseudo opcode member of the set 2080b57cec5SDimitry Andric// `Opcodes`. This check is always expanded to "false" if we are generating 2090b57cec5SDimitry Andric// code for MCInst. 2100b57cec5SDimitry Andricclass CheckPseudo<list<Instruction> Opcodes> : CheckOpcode<Opcodes>; 2110b57cec5SDimitry Andric 2120b57cec5SDimitry Andric// A non-portable predicate. Only to use as a last resort when a block of code 2130b57cec5SDimitry Andric// cannot possibly be converted in a declarative way using other MCInstPredicate 2140b57cec5SDimitry Andric// classes. This check is always expanded to "false" when generating code for 2150b57cec5SDimitry Andric// MCInst. 2160b57cec5SDimitry Andricclass CheckNonPortable<string Code> : MCInstPredicate { 2170b57cec5SDimitry Andric string CodeBlock = Code; 2180b57cec5SDimitry Andric} 2190b57cec5SDimitry Andric 2200b57cec5SDimitry Andric// A sequence of predicates. It is used as the base class for CheckAll, and 2210b57cec5SDimitry Andric// CheckAny. It allows to describe compositions of predicates. 2220b57cec5SDimitry Andricclass CheckPredicateSequence<list<MCInstPredicate> Preds> : MCInstPredicate { 2230b57cec5SDimitry Andric list<MCInstPredicate> Predicates = Preds; 2240b57cec5SDimitry Andric} 2250b57cec5SDimitry Andric 2260b57cec5SDimitry Andric// Check that all of the predicates in `Preds` evaluate to true. 2270b57cec5SDimitry Andricclass CheckAll<list<MCInstPredicate> Sequence> 2280b57cec5SDimitry Andric : CheckPredicateSequence<Sequence>; 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andric// Check that at least one of the predicates in `Preds` evaluates to true. 2310b57cec5SDimitry Andricclass CheckAny<list<MCInstPredicate> Sequence> 2320b57cec5SDimitry Andric : CheckPredicateSequence<Sequence>; 2330b57cec5SDimitry Andric 234b3edf446SDimitry Andric// Check that the operand at position `Index` is in range [Start, End]. 235b3edf446SDimitry Andric// If field `FunctionMapper` is a non-empty string, then function 236b3edf446SDimitry Andric// `FunctionMapper` is applied to the operand value, and the return value is then 237b3edf446SDimitry Andric// compared against range [Start, End]. 238b3edf446SDimitry Andricclass CheckImmOperandRange<int Index, int Start, int End> 239b3edf446SDimitry Andric : CheckAll<[CheckImmOperandGE<Index, Start>, CheckImmOperandLE<Index, End>]>; 2400b57cec5SDimitry Andric 2410b57cec5SDimitry Andric// Used to expand the body of a function predicate. See the definition of 2420b57cec5SDimitry Andric// TIIPredicate below. 2430b57cec5SDimitry Andricclass MCStatement; 2440b57cec5SDimitry Andric 2450b57cec5SDimitry Andric// Expands to a return statement. The return expression is a boolean expression 2460b57cec5SDimitry Andric// described by a MCInstPredicate. 2470b57cec5SDimitry Andricclass MCReturnStatement<MCInstPredicate predicate> : MCStatement { 2480b57cec5SDimitry Andric MCInstPredicate Pred = predicate; 2490b57cec5SDimitry Andric} 2500b57cec5SDimitry Andric 2510b57cec5SDimitry Andric// Used to automatically construct cases of a switch statement where the switch 2520b57cec5SDimitry Andric// variable is an instruction opcode. There is a 'case' for every opcode in the 2530b57cec5SDimitry Andric// `opcodes` list, and each case is associated with MCStatement `caseStmt`. 2540b57cec5SDimitry Andricclass MCOpcodeSwitchCase<list<Instruction> opcodes, MCStatement caseStmt> { 2550b57cec5SDimitry Andric list<Instruction> Opcodes = opcodes; 2560b57cec5SDimitry Andric MCStatement CaseStmt = caseStmt; 2570b57cec5SDimitry Andric} 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric// Expands to a switch statement. The switch variable is an instruction opcode. 2600b57cec5SDimitry Andric// The auto-generated switch is populated by a number of cases based on the 2610b57cec5SDimitry Andric// `cases` list in input. A default case is automatically generated, and it 2620b57cec5SDimitry Andric// evaluates to `default`. 2630b57cec5SDimitry Andricclass MCOpcodeSwitchStatement<list<MCOpcodeSwitchCase> cases, 2640b57cec5SDimitry Andric MCStatement default> : MCStatement { 2650b57cec5SDimitry Andric list<MCOpcodeSwitchCase> Cases = cases; 2660b57cec5SDimitry Andric MCStatement DefaultCase = default; 2670b57cec5SDimitry Andric} 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andric// Base class for function predicates. 2700b57cec5SDimitry Andricclass FunctionPredicateBase<string name, MCStatement body> { 2710b57cec5SDimitry Andric string FunctionName = name; 2720b57cec5SDimitry Andric MCStatement Body = body; 2730b57cec5SDimitry Andric} 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andric// Check that a call to method `Name` in class "XXXInstrInfo" (where XXX is 2760b57cec5SDimitry Andric// the name of a target) returns true. 2770b57cec5SDimitry Andric// 2780b57cec5SDimitry Andric// TIIPredicate definitions are used to model calls to the target-specific 2790b57cec5SDimitry Andric// InstrInfo. A TIIPredicate is treated specially by the InstrInfoEmitter 2800b57cec5SDimitry Andric// tablegen backend, which will use it to automatically generate a definition in 2810b57cec5SDimitry Andric// the target specific `InstrInfo` class. 2820b57cec5SDimitry Andric// 2830b57cec5SDimitry Andric// There cannot be multiple TIIPredicate definitions with the same name for the 2840b57cec5SDimitry Andric// same target. 2850b57cec5SDimitry Andricclass TIIPredicate<string Name, MCStatement body> 2860b57cec5SDimitry Andric : FunctionPredicateBase<Name, body>, MCInstPredicate; 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andric// A function predicate that takes as input a machine instruction, and returns 2890b57cec5SDimitry Andric// a boolean value. 2900b57cec5SDimitry Andric// 2910b57cec5SDimitry Andric// This predicate is expanded into a function call by the PredicateExpander. 2920b57cec5SDimitry Andric// In particular, the PredicateExpander would either expand this predicate into 2930b57cec5SDimitry Andric// a call to `MCInstFn`, or into a call to`MachineInstrFn` depending on whether 2940b57cec5SDimitry Andric// it is lowering predicates for MCInst or MachineInstr. 2950b57cec5SDimitry Andric// 2960b57cec5SDimitry Andric// In this context, `MCInstFn` and `MachineInstrFn` are both function names. 2970b57cec5SDimitry Andricclass CheckFunctionPredicate<string MCInstFn, string MachineInstrFn> : MCInstPredicate { 2980b57cec5SDimitry Andric string MCInstFnName = MCInstFn; 2990b57cec5SDimitry Andric string MachineInstrFnName = MachineInstrFn; 3000b57cec5SDimitry Andric} 3010b57cec5SDimitry Andric 302e8d8bef9SDimitry Andric// Similar to CheckFunctionPredicate. However it assumes that MachineInstrFn is 303e8d8bef9SDimitry Andric// a method in TargetInstrInfo, and MCInstrFn takes an extra pointer to 304e8d8bef9SDimitry Andric// MCInstrInfo. 305e8d8bef9SDimitry Andric// 306e8d8bef9SDimitry Andric// It Expands to: 307e8d8bef9SDimitry Andric// - TIIPointer->MachineInstrFn(MI) 308e8d8bef9SDimitry Andric// - MCInstrFn(MI, MCII); 309e8d8bef9SDimitry Andricclass CheckFunctionPredicateWithTII<string MCInstFn, string MachineInstrFn, string 310e8d8bef9SDimitry AndricTIIPointer = "TII"> : MCInstPredicate { 311e8d8bef9SDimitry Andric string MCInstFnName = MCInstFn; 312e8d8bef9SDimitry Andric string TIIPtrName = TIIPointer; 313e8d8bef9SDimitry Andric string MachineInstrFnName = MachineInstrFn; 314e8d8bef9SDimitry Andric} 315e8d8bef9SDimitry Andric 3160b57cec5SDimitry Andric// Used to classify machine instructions based on a machine instruction 3170b57cec5SDimitry Andric// predicate. 3180b57cec5SDimitry Andric// 3190b57cec5SDimitry Andric// Let IC be an InstructionEquivalenceClass definition, and MI a machine 3200b57cec5SDimitry Andric// instruction. We say that MI belongs to the equivalence class described by IC 3210b57cec5SDimitry Andric// if and only if the following two conditions are met: 3220b57cec5SDimitry Andric// a) MI's opcode is in the `opcodes` set, and 3230b57cec5SDimitry Andric// b) `Predicate` evaluates to true when applied to MI. 3240b57cec5SDimitry Andric// 3250b57cec5SDimitry Andric// Instances of this class can be used by processor scheduling models to 3260b57cec5SDimitry Andric// describe instructions that have a property in common. For example, 3270b57cec5SDimitry Andric// InstructionEquivalenceClass definitions can be used to identify the set of 3280b57cec5SDimitry Andric// dependency breaking instructions for a processor model. 3290b57cec5SDimitry Andric// 3300b57cec5SDimitry Andric// An (optional) list of operand indices can be used to further describe 3310b57cec5SDimitry Andric// properties that apply to instruction operands. For example, it can be used to 3320b57cec5SDimitry Andric// identify register uses of a dependency breaking instructions that are not in 3330b57cec5SDimitry Andric// a RAW dependency. 3340b57cec5SDimitry Andricclass InstructionEquivalenceClass<list<Instruction> opcodes, 3350b57cec5SDimitry Andric MCInstPredicate pred, 3360b57cec5SDimitry Andric list<int> operands = []> { 3370b57cec5SDimitry Andric list<Instruction> Opcodes = opcodes; 3380b57cec5SDimitry Andric MCInstPredicate Predicate = pred; 3390b57cec5SDimitry Andric list<int> OperandIndices = operands; 3400b57cec5SDimitry Andric} 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andric// Used by processor models to describe dependency breaking instructions. 3430b57cec5SDimitry Andric// 3440b57cec5SDimitry Andric// This is mainly an alias for InstructionEquivalenceClass. Input operand 3450b57cec5SDimitry Andric// `BrokenDeps` identifies the set of "broken dependencies". There is one bit 3460b57cec5SDimitry Andric// per each implicit and explicit input operand. An empty set of broken 3470b57cec5SDimitry Andric// dependencies means: "explicit input register operands are independent." 3480b57cec5SDimitry Andricclass DepBreakingClass<list<Instruction> opcodes, MCInstPredicate pred, 3490b57cec5SDimitry Andric list<int> BrokenDeps = []> 3500b57cec5SDimitry Andric : InstructionEquivalenceClass<opcodes, pred, BrokenDeps>; 3510b57cec5SDimitry Andric 3520b57cec5SDimitry Andric// A function descriptor used to describe the signature of a predicate methods 3530b57cec5SDimitry Andric// which will be expanded by the STIPredicateExpander into a tablegen'd 3540b57cec5SDimitry Andric// XXXGenSubtargetInfo class member definition (here, XXX is a target name). 3550b57cec5SDimitry Andric// 3560b57cec5SDimitry Andric// It describes the signature of a TargetSubtarget hook, as well as a few extra 3570b57cec5SDimitry Andric// properties. Examples of extra properties are: 3580b57cec5SDimitry Andric// - The default return value for the auto-generate function hook. 3590b57cec5SDimitry Andric// - A list of subtarget hooks (Delegates) that are called from this function. 3600b57cec5SDimitry Andric// 3610b57cec5SDimitry Andricclass STIPredicateDecl<string name, MCInstPredicate default = FalsePred, 362e8d8bef9SDimitry Andric bit overrides = true, bit expandForMC = true, 363e8d8bef9SDimitry Andric bit updatesOpcodeMask = false, 3640b57cec5SDimitry Andric list<STIPredicateDecl> delegates = []> { 3650b57cec5SDimitry Andric string Name = name; 3660b57cec5SDimitry Andric 3670b57cec5SDimitry Andric MCInstPredicate DefaultReturnValue = default; 3680b57cec5SDimitry Andric 3690b57cec5SDimitry Andric // True if this method is declared as virtual in class TargetSubtargetInfo. 3700b57cec5SDimitry Andric bit OverridesBaseClassMember = overrides; 3710b57cec5SDimitry Andric 3720b57cec5SDimitry Andric // True if we need an equivalent predicate function in the MC layer. 3730b57cec5SDimitry Andric bit ExpandForMC = expandForMC; 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andric // True if the autogenerated method has a extra in/out APInt param used as a 3760b57cec5SDimitry Andric // mask of operands. 3770b57cec5SDimitry Andric bit UpdatesOpcodeMask = updatesOpcodeMask; 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andric // A list of STIPredicates used by this definition to delegate part of the 3800b57cec5SDimitry Andric // computation. For example, STIPredicateFunction `isDependencyBreaking()` 3810b57cec5SDimitry Andric // delegates to `isZeroIdiom()` part of its computation. 3820b57cec5SDimitry Andric list<STIPredicateDecl> Delegates = delegates; 3830b57cec5SDimitry Andric} 3840b57cec5SDimitry Andric 3850b57cec5SDimitry Andric// A predicate function definition member of class `XXXGenSubtargetInfo`. 3860b57cec5SDimitry Andric// 3870b57cec5SDimitry Andric// If `Declaration.ExpandForMC` is true, then SubtargetEmitter 3880b57cec5SDimitry Andric// will also expand another definition of this method that accepts a MCInst. 3890b57cec5SDimitry Andricclass STIPredicate<STIPredicateDecl declaration, 3900b57cec5SDimitry Andric list<InstructionEquivalenceClass> classes> { 3910b57cec5SDimitry Andric STIPredicateDecl Declaration = declaration; 3920b57cec5SDimitry Andric list<InstructionEquivalenceClass> Classes = classes; 3930b57cec5SDimitry Andric SchedMachineModel SchedModel = ?; 3940b57cec5SDimitry Andric} 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andric// Convenience classes and definitions used by processor scheduling models to 3970b57cec5SDimitry Andric// describe dependency breaking instructions and move elimination candidates. 398e8d8bef9SDimitry Andriclet UpdatesOpcodeMask = true in { 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andricdef IsZeroIdiomDecl : STIPredicateDecl<"isZeroIdiom">; 4010b57cec5SDimitry Andric 4020b57cec5SDimitry Andriclet Delegates = [IsZeroIdiomDecl] in 4030b57cec5SDimitry Andricdef IsDepBreakingDecl : STIPredicateDecl<"isDependencyBreaking">; 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andric} // UpdatesOpcodeMask 4060b57cec5SDimitry Andric 4070b57cec5SDimitry Andricdef IsOptimizableRegisterMoveDecl 4080b57cec5SDimitry Andric : STIPredicateDecl<"isOptimizableRegisterMove">; 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andricclass IsZeroIdiomFunction<list<DepBreakingClass> classes> 4110b57cec5SDimitry Andric : STIPredicate<IsZeroIdiomDecl, classes>; 4120b57cec5SDimitry Andric 4130b57cec5SDimitry Andricclass IsDepBreakingFunction<list<DepBreakingClass> classes> 4140b57cec5SDimitry Andric : STIPredicate<IsDepBreakingDecl, classes>; 4150b57cec5SDimitry Andric 4160b57cec5SDimitry Andricclass IsOptimizableRegisterMove<list<InstructionEquivalenceClass> classes> 4170b57cec5SDimitry Andric : STIPredicate<IsOptimizableRegisterMoveDecl, classes>; 418