1//===- Target.td - Define GlobalISel rules -----------------*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file defines the target-independent interfaces used to support 10// SelectionDAG instruction selection patterns (specified in 11// TargetSelectionDAG.td) when generating GlobalISel instruction selectors. 12// 13// This is intended as a compatibility layer, to enable reuse of target 14// descriptions written for SelectionDAG without requiring explicit GlobalISel 15// support. It will eventually supersede SelectionDAG patterns. 16// 17//===----------------------------------------------------------------------===// 18 19// Definitions that inherit from LLT define types that will be used in the 20// GlobalISel matcher. 21class LLT; 22 23def s32 : LLT; 24def s64 : LLT; 25 26// Defines a matcher for complex operands. This is analogous to ComplexPattern 27// from SelectionDAG. 28// 29// Definitions that inherit from this may also inherit from 30// GIComplexPatternEquiv to enable the import of SelectionDAG patterns involving 31// those ComplexPatterns. 32class GIComplexOperandMatcher<LLT type, string matcherfn> { 33 // The expected type of the root of the match. 34 // 35 // TODO: We should probably support, any-type, any-scalar, and multiple types 36 // in the future. 37 LLT Type = type; 38 39 // The function that determines whether the operand matches. It should be of 40 // the form: 41 // bool select(const MatchOperand &Root, MatchOperand &Result1) 42 // and should have the same number of ResultX arguments as the number of 43 // result operands. It must return true on successful match and false 44 // otherwise. If it returns true, then all the ResultX arguments must be 45 // overwritten. 46 string MatcherFn = matcherfn; 47} 48 49// Defines a custom renderer. This is analogous to SDNodeXForm from 50// SelectionDAG. Unlike SDNodeXForm, this matches a MachineInstr and 51// renders directly to the result instruction without an intermediate node. 52// 53// Definitions that inherit from this may also inherit from GISDNodeXFormEquiv 54// to enable the import of SelectionDAG patterns involving those SDNodeXForms. 55class GICustomOperandRenderer<string rendererfn> { 56 // The function renders the operand(s) of the matched instruction to 57 // the specified instruction. It should be of the form: 58 // void render(MachineInstrBuilder &MIB, const MachineInstr &MI, 59 // int OpIdx = -1) 60 // 61 // If OpIdx is specified (i.e. not invalid/negative), this 62 // references the source operand MI.getOperand(OpIdx). Otherwise, 63 // this is the value defined by MI. This is to support the case 64 // where there is no corresponding instruction to match. 65 string RendererFn = rendererfn; 66} 67