1//===-- LLVMDialect.td - LLVM IR dialect definition --------*- 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 LLVMIR_DIALECT 10#define LLVMIR_DIALECT 11 12include "mlir/IR/DialectBase.td" 13 14def LLVM_Dialect : Dialect { 15 let name = "llvm"; 16 let cppNamespace = "::mlir::LLVM"; 17 18 let hasConstantMaterializer = 1; 19 let useDefaultAttributePrinterParser = 1; 20 let hasRegionArgAttrVerify = 1; 21 let hasRegionResultAttrVerify = 1; 22 let hasOperationAttrVerify = 1; 23 24 let discardableAttrs = (ins 25 /// Attribute encoding size and type of GPU workgroup attributions. 26 "WorkgroupAttributionAttr":$workgroup_attribution 27 ); 28 29 let extraClassDeclaration = [{ 30 /// Name of the data layout attributes. 31 static StringRef getDataLayoutAttrName() { return "llvm.data_layout"; } 32 static StringRef getNoAliasScopesAttrName() { return "noalias_scopes"; } 33 static StringRef getAliasScopesAttrName() { return "alias_scopes"; } 34 static StringRef getAccessGroupsAttrName() { return "access_groups"; } 35 static StringRef getIdentAttrName() { return "llvm.ident"; } 36 static StringRef getCommandlineAttrName() { return "llvm.commandline"; } 37 38 /// Names of llvm parameter attributes. 39 static StringRef getAlignAttrName() { return "llvm.align"; } 40 static StringRef getAllocAlignAttrName() { return "llvm.allocalign"; } 41 static StringRef getAllocatedPointerAttrName() { return "llvm.allocptr"; } 42 static StringRef getByValAttrName() { return "llvm.byval"; } 43 static StringRef getByRefAttrName() { return "llvm.byref"; } 44 static StringRef getNoUndefAttrName() { return "llvm.noundef"; } 45 static StringRef getDereferenceableAttrName() { return "llvm.dereferenceable"; } 46 static StringRef getDereferenceableOrNullAttrName() { return "llvm.dereferenceable_or_null"; } 47 static StringRef getInAllocaAttrName() { return "llvm.inalloca"; } 48 static StringRef getInRegAttrName() { return "llvm.inreg"; } 49 static StringRef getNestAttrName() { return "llvm.nest"; } 50 static StringRef getNoAliasAttrName() { return "llvm.noalias"; } 51 static StringRef getNoCaptureAttrName() { return "llvm.nocapture"; } 52 static StringRef getNoFreeAttrName() { return "llvm.nofree"; } 53 static StringRef getNonNullAttrName() { return "llvm.nonnull"; } 54 static StringRef getPreallocatedAttrName() { return "llvm.preallocated"; } 55 static StringRef getRangeAttrName() { return "llvm.range"; } 56 static StringRef getReadonlyAttrName() { return "llvm.readonly"; } 57 static StringRef getReturnedAttrName() { return "llvm.returned"; } 58 static StringRef getSExtAttrName() { return "llvm.signext"; } 59 static StringRef getStackAlignmentAttrName() { return "llvm.alignstack"; } 60 static StringRef getStructRetAttrName() { return "llvm.sret"; } 61 static StringRef getWriteOnlyAttrName() { return "llvm.writeonly"; } 62 static StringRef getZExtAttrName() { return "llvm.zeroext"; } 63 static StringRef getOpBundleSizesAttrName() { return "op_bundle_sizes"; } 64 static StringRef getOpBundleTagsAttrName() { return "op_bundle_tags"; } 65 // TODO Restrict the usage of this to parameter attributes once there is an 66 // alternative way of modeling memory effects on FunctionOpInterface. 67 /// Name of the attribute that will cause the creation of a readnone memory 68 /// effect when lowering to the LLVMDialect. 69 static StringRef getReadnoneAttrName() { return "llvm.readnone"; } 70 71 /// Verifies if the given string is a well-formed data layout descriptor. 72 /// Uses `reportError` to report errors. 73 static LogicalResult verifyDataLayoutString( 74 StringRef descr, llvm::function_ref<void (const Twine &)> reportError); 75 76 /// Name of the target triple attribute. 77 static StringRef getTargetTripleAttrName() { return "llvm.target_triple"; } 78 79 /// Name of the C wrapper emission attribute. 80 static StringRef getEmitCWrapperAttrName() { 81 return "llvm.emit_c_interface"; 82 } 83 84 /// Returns `true` if the given type is compatible with the LLVM dialect. 85 static bool isCompatibleType(Type); 86 87 88 Type parseType(DialectAsmParser &p) const override; 89 void printType(Type, DialectAsmPrinter &p) const override; 90 91 private: 92 /// Verifies a parameter attribute attached to a parameter of type 93 /// paramType. 94 LogicalResult verifyParameterAttribute(Operation *op, 95 Type paramType, 96 NamedAttribute paramAttr); 97 98 /// Register all types. 99 void registerTypes(); 100 101 /// A cache storing compatible LLVM types that have been verified. This 102 /// can save us lots of verification time if there are many occurrences 103 /// of some deeply-nested aggregate types in the program. 104 ThreadLocalCache<DenseSet<Type>> compatibleTypes; 105 106 /// Register the attributes of this dialect. 107 void registerAttributes(); 108 }]; 109} 110 111#endif // LLVMIR_DIALECT 112