1//===- BuiltinOps.td - Builtin operation definitions -------*- 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// Defines the set of builtin MLIR operations, or the set of operations 10// necessary for the validity of and defining the IR. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef BUILTIN_OPS 15#define BUILTIN_OPS 16 17include "mlir/IR/BuiltinDialect.td" 18include "mlir/IR/OpAsmInterface.td" 19include "mlir/IR/RegionKindInterface.td" 20include "mlir/IR/SymbolInterfaces.td" 21include "mlir/Interfaces/CastInterfaces.td" 22include "mlir/Interfaces/DataLayoutInterfaces.td" 23include "mlir/Interfaces/SideEffectInterfaces.td" 24 25// Base class for Builtin dialect ops. 26class Builtin_Op<string mnemonic, list<Trait> traits = []> : 27 Op<Builtin_Dialect, mnemonic, traits>; 28 29//===----------------------------------------------------------------------===// 30// ModuleOp 31//===----------------------------------------------------------------------===// 32 33def ModuleOp : Builtin_Op<"module", [ 34 AffineScope, IsolatedFromAbove, NoRegionArguments, SymbolTable, Symbol, 35 OpAsmOpInterface 36 ] # GraphRegionNoTerminator.traits> { 37 let summary = "A top level container operation"; 38 let description = [{ 39 A `module` represents a top-level container operation. It contains a single 40 [graph region](../LangRef.md#control-flow-and-ssacfg-regions) containing a single block 41 which can contain any operations and does not have a terminator. Operations 42 within this region cannot implicitly capture values defined outside the module, 43 i.e. Modules are [IsolatedFromAbove](../Traits.md#isolatedfromabove). Modules have 44 an optional [symbol name](../SymbolsAndSymbolTables.md) which can be used to refer 45 to them in operations. 46 47 Example: 48 49 ```mlir 50 module { 51 func.func @foo() 52 } 53 ``` 54 }]; 55 56 let arguments = (ins OptionalAttr<SymbolNameAttr>:$sym_name, 57 OptionalAttr<StrAttr>:$sym_visibility); 58 let regions = (region SizedRegion<1>:$bodyRegion); 59 60 let assemblyFormat = "($sym_name^)? attr-dict-with-keyword $bodyRegion"; 61 let builders = [OpBuilder<(ins CArg<"std::optional<StringRef>", "{}">:$name)>]; 62 let extraClassDeclaration = [{ 63 /// Construct a module from the given location with an optional name. 64 static ModuleOp create(Location loc, std::optional<StringRef> name = std::nullopt); 65 66 /// Return the name of this module if present. 67 std::optional<StringRef> getName() { return getSymName(); } 68 69 //===------------------------------------------------------------------===// 70 // SymbolOpInterface Methods 71 //===------------------------------------------------------------------===// 72 73 /// A ModuleOp may optionally define a symbol. 74 bool isOptionalSymbol() { return true; } 75 76 //===------------------------------------------------------------------===// 77 // DataLayoutOpInterface Methods 78 //===------------------------------------------------------------------===// 79 80 DataLayoutSpecInterface getDataLayoutSpec(); 81 TargetSystemSpecInterface getTargetSystemSpec(); 82 83 //===------------------------------------------------------------------===// 84 // OpAsmOpInterface Methods 85 //===------------------------------------------------------------------===// 86 87 static ::llvm::StringRef getDefaultDialect() { 88 return "builtin"; 89 } 90 }]; 91 let hasVerifier = 1; 92 93 // We need to ensure the block inside the region is properly terminated; 94 // the auto-generated builders do not guarantee that. 95 let skipDefaultBuilders = 1; 96} 97 98//===----------------------------------------------------------------------===// 99// UnrealizedConversionCastOp 100//===----------------------------------------------------------------------===// 101 102def UnrealizedConversionCastOp : Builtin_Op<"unrealized_conversion_cast", [ 103 Pure 104 ]> { 105 let summary = "An unrealized conversion from one set of types to another"; 106 let description = [{ 107 An `unrealized_conversion_cast` operation represents an unrealized 108 conversion from one set of types to another, that is used to enable the 109 inter-mixing of different type systems. This operation should not be 110 attributed any special representational or execution semantics, and is 111 generally only intended to be used to satisfy the temporary intermixing of 112 type systems during the conversion of one type system to another. 113 114 This operation may produce results of arity 1-N, and accept as input 115 operands of arity 0-N. 116 117 Example: 118 119 ```mlir 120 // An unrealized 0-1 conversion. These types of conversions are useful in 121 // cases where a type is removed from the type system, but not all uses have 122 // been converted. For example, imagine we have a tuple type that is 123 // expanded to its element types. If only some uses of an empty tuple type 124 // instance are converted we still need an instance of the tuple type, but 125 // have no inputs to the unrealized conversion. 126 %result = unrealized_conversion_cast to !bar.tuple_type<> 127 128 // An unrealized 1-1 conversion. 129 %result1 = unrealized_conversion_cast %operand : !foo.type to !bar.lowered_type 130 131 // An unrealized 1-N conversion. 132 %results2:2 = unrealized_conversion_cast %tuple_operand : !foo.tuple_type<!foo.type, !foo.type> to !foo.type, !foo.type 133 134 // An unrealized N-1 conversion. 135 %result3 = unrealized_conversion_cast %operand, %operand : !foo.type, !foo.type to !bar.tuple_type<!foo.type, !foo.type> 136 ``` 137 }]; 138 139 let arguments = (ins Variadic<AnyType>:$inputs); 140 let results = (outs Variadic<AnyType>:$outputs); 141 let assemblyFormat = [{ 142 ($inputs^ `:` type($inputs))? `to` type($outputs) attr-dict 143 }]; 144 let hasFolder = 1; 145 let hasVerifier = 1; 146} 147 148#endif // BUILTIN_OPS 149