1//- DXIL.td - Describe DXIL operation -------------------------*- 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/// \file
10/// This is a target description file for DXIL operation.
11///
12//===----------------------------------------------------------------------===//
13
14include "llvm/IR/Intrinsics.td"
15
16class dxil_class<string _name> {
17  string name = _name;
18}
19class dxil_category<string _name> {
20  string name = _name;
21}
22
23def Unary : dxil_class<"Unary">;
24def Binary : dxil_class<"Binary">;
25
26def binary_uint : dxil_category<"Binary uint">;
27def unary_float : dxil_category<"Unary float">;
28
29
30
31// The parameter description for a DXIL instruction
32class dxil_param<int _pos, string type, string _name, string _doc,
33                 bit _is_const = 0, string _enum_name = "",
34                 int _max_value = 0> {
35  int pos = _pos;           // position in parameter list
36  string llvm_type = type; // llvm type name, $o for overload, $r for resource
37                           // type, $cb for legacy cbuffer, $u4 for u4 struct
38  string name = _name;      // short, unique name
39  string doc = _doc;        // the documentation description of this parameter
40  bit is_const =
41      _is_const; // whether this argument requires a constant value in the IR
42  string enum_name = _enum_name; // the name of the enum type if applicable
43  int max_value =
44      _max_value; // the maximum value for this parameter if applicable
45}
46
47// A representation for a DXIL instruction
48class dxil_inst<string _name> {
49  string name = _name; // short, unique name
50
51  string dxil_op = "";       // name of DXIL operation
52  int dxil_opid = 0;         // ID of DXIL operation
53  dxil_class  op_class;      // name of the opcode class
54  dxil_category category;    // classification for this instruction
55  string doc = "";           // the documentation description of this instruction
56  list<dxil_param> ops = []; // the operands that this instruction takes
57  string oload_types = "";   // overload types if applicable
58  string fn_attr = "";       // attribute shorthands: rn=does not access
59                             // memory,ro=only reads from memory,
60  bit is_deriv = 0;          // whether this is some kind of derivative
61  bit is_gradient = 0;       // whether this requires a gradient calculation
62  bit is_feedback = 0;       // whether this is a sampler feedback op
63  bit is_wave = 0; // whether this requires in-wave, cross-lane functionality
64  bit requires_uniform_inputs = 0; // whether this operation requires that all
65                                   // of its inputs are uniform across the wave
66  // Group dxil operation for stats.
67  // Like how many atomic/float/uint/int/... instructions used in the program.
68  list<string> stats_group = [];
69}
70
71class dxil_op<string name, int code_id, dxil_class code_class, dxil_category op_category, string _doc,
72              string _oload_types, string _fn_attr, list<dxil_param> op_params,
73              list<string> _stats_group = []> : dxil_inst<name> {
74  let dxil_op = name;
75  let dxil_opid = code_id;
76  let doc = _doc;
77  let ops = op_params;
78  let op_class = code_class;
79  let category = op_category;
80  let oload_types = _oload_types;
81  let fn_attr = _fn_attr;
82  let stats_group = _stats_group;
83}
84
85// The intrinsic which map directly to this dxil op.
86class dxil_map_intrinsic<Intrinsic llvm_intrinsic_> { Intrinsic llvm_intrinsic = llvm_intrinsic_; }
87
88def Sin : dxil_op<"Sin", 13, Unary, unary_float, "returns sine(theta) for theta in radians.",
89  "half;float;", "rn",
90  [
91    dxil_param<0, "$o", "", "operation result">,
92    dxil_param<1, "i32", "opcode", "DXIL opcode">,
93    dxil_param<2, "$o", "value", "input value">
94  ],
95  ["floats"]>,
96  dxil_map_intrinsic<int_sin>;
97
98def UMax :dxil_op< "UMax", 39,  Binary,  binary_uint, "unsigned integer maximum. UMax(a,b) = a > b ? a : b",
99    "i16;i32;i64;",  "rn",
100  [
101    dxil_param<0,  "$o",  "",  "operation result">,
102    dxil_param<1,  "i32",  "opcode",  "DXIL opcode">,
103    dxil_param<2,  "$o",  "a",  "input value">,
104    dxil_param<3,  "$o",  "b",  "input value">
105  ],
106  ["uints"]>,
107  dxil_map_intrinsic<int_umax>;
108