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; 25def v2s32 : LLT; 26def v4s16 : LLT; 27def v8s8 : LLT; 28 29// Defines a matcher for complex operands. This is analogous to ComplexPattern 30// from SelectionDAG. 31// 32// Definitions that inherit from this may also inherit from 33// GIComplexPatternEquiv to enable the import of SelectionDAG patterns involving 34// those ComplexPatterns. 35class GIComplexOperandMatcher<LLT type, string matcherfn> { 36 // The expected type of the root of the match. 37 // 38 // TODO: We should probably support, any-type, any-scalar, and multiple types 39 // in the future. 40 LLT Type = type; 41 42 // The function that determines whether the operand matches. It should be of 43 // the form: 44 // ComplexRendererFn select(MachineOperand &Root) const; 45 // where Root is the root of the match. The function should return nullptr 46 // on match failure, or a ComplexRendererFn that renders the operand in case 47 // of a successful match. 48 string MatcherFn = matcherfn; 49} 50 51// Defines a custom renderer. This is analogous to SDNodeXForm from 52// SelectionDAG. Unlike SDNodeXForm, this matches a MachineInstr and 53// renders directly to the result instruction without an intermediate node. 54// 55// Definitions that inherit from this may also inherit from GISDNodeXFormEquiv 56// to enable the import of SelectionDAG patterns involving those SDNodeXForms. 57class GICustomOperandRenderer<string rendererfn> { 58 // The function renders the operand(s) of the matched instruction to 59 // the specified instruction. It should be of the form: 60 // void render(MachineInstrBuilder &MIB, const MachineInstr &MI, 61 // int OpIdx = -1) 62 // 63 // If OpIdx is specified (i.e. not invalid/negative), this 64 // references the source operand MI.getOperand(OpIdx). Otherwise, 65 // this is the value defined by MI. This is to support the case 66 // where there is no corresponding instruction to match. 67 string RendererFn = rendererfn; 68} 69