1//===- FuncTransformOps.td - CF transformation ops -*- 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#ifndef FUNC_TRANSFORM_OPS 10#define FUNC_TRANSFORM_OPS 11 12include "mlir/Dialect/Transform/IR/TransformDialect.td" 13include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td" 14include "mlir/Dialect/Transform/IR/TransformTypes.td" 15include "mlir/Interfaces/SideEffectInterfaces.td" 16include "mlir/IR/RegionKindInterface.td" 17include "mlir/IR/OpBase.td" 18 19def ApplyFuncToLLVMConversionPatternsOp : Op<Transform_Dialect, 20 "apply_conversion_patterns.func.func_to_llvm", 21 [DeclareOpInterfaceMethods<ConversionPatternDescriptorOpInterface, 22 ["verifyTypeConverter"]>]> { 23 let description = [{ 24 Collects patterns that convert Func dialect ops to LLVM dialect ops. 25 These patterns require an "LLVMTypeConverter". 26 }]; 27 28 let assemblyFormat = "attr-dict"; 29} 30 31def CastAndCallOp : Op<Transform_Dialect, 32 "func.cast_and_call", 33 [DeclareOpInterfaceMethods<TransformOpInterface>, 34 DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, 35 AttrSizedOperandSegments, 36 ReportTrackingListenerFailuresOpTrait] 37 # GraphRegionNoTerminator.traits> { 38 let summary = "Casts values to the signature of a function and replaces them " 39 "with a call"; 40 let description = [{ 41 This transform takes value handles to a set of `inputs` and `outputs` and 42 attempts to cast them to the function signature of the attached function 43 op, then builds a call to the function and replaces the users of the 44 outputs. It is the responsibility of the user to ensure that the slice of 45 the program replaced by this operation makes sense, i.e. there is no 46 verification that the inputs to this operation have any relation to the 47 outputs outside of basic dominance requirements needed for the call. 48 49 The casting materialization functions are specified in the graph region of 50 this op. They must implement the `TypeConverterBuilderOpInterface`. The 51 order of ops within the region is irrelevant. 52 53 The target function can be specified by a symbol name or by a handle to the 54 operation. 55 56 This transform only reads the operand handles and only replaces the users of 57 the outputs with the results of the call. No handles are consumed and no 58 operations are removed. Users are expected to run cleanup separately if 59 desired. 60 61 Warning: The replacement of the uses of the outputs could invalidate certain 62 restricted value handle types (e.g. `transform.block_arg` if it existed, by 63 replacing the use with something not coming from a block argument). The 64 value will still exist in such cases but wouldn't verify against the type. 65 See the discussion here for more information: 66 https://github.com/llvm/llvm-project/pull/78398#discussion_r1455070087 67 68 This transform will emit a silenceable failure if: 69 - The set of outputs isn't unique 70 - The handle for the insertion point does not include exactly one operation 71 - The insertion point op does not dominate any of the output users 72 - The insertion point op is not dominated by any of the inputs 73 - The function signature does not match the number of inputs/outputs 74 75 This transform will emit a definite failure if it fails to resolve the 76 target function, or if it fails to materialize the conversion casts of 77 either the inputs to the function argument types, or the call results to 78 the output types. 79 }]; 80 81 let arguments = (ins 82 TransformHandleTypeInterface:$insertion_point, 83 UnitAttr:$insert_after, 84 Optional<TransformValueHandleTypeInterface>:$inputs, 85 Optional<TransformValueHandleTypeInterface>:$outputs, 86 OptionalAttr<SymbolRefAttr>:$function_name, 87 Optional<TransformHandleTypeInterface>:$function); 88 let results = (outs TransformHandleTypeInterface:$result); 89 let regions = (region MaxSizedRegion<1>:$conversions); 90 91 let assemblyFormat = [{ 92 ($function_name^)? ($function^)? 93 ( `(` $inputs^ `)` )? 94 ( `->` $outputs^ )? 95 (`after` $insert_after^):(`before`)? $insertion_point 96 ($conversions^)? attr-dict `:` functional-type(operands, results) 97 }]; 98 let hasVerifier = 1; 99} 100 101#endif // FUNC_TRANSFORM_OPS 102