1 //===- BuiltinOps.h - MLIR Builtin Operations -------------------*- C++ -*-===// 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 contains the Builtin dialect's operations. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef MLIR_IR_BUILTINOPS_H_ 14 #define MLIR_IR_BUILTINOPS_H_ 15 16 #include "mlir/IR/FunctionSupport.h" 17 #include "mlir/IR/OwningOpRef.h" 18 #include "mlir/IR/SymbolTable.h" 19 #include "mlir/Interfaces/CallInterfaces.h" 20 #include "llvm/Support/PointerLikeTypeTraits.h" 21 22 //===----------------------------------------------------------------------===// 23 // Dialect Operations 24 //===----------------------------------------------------------------------===// 25 26 #define GET_OP_CLASSES 27 #include "mlir/IR/BuiltinOps.h.inc" 28 29 //===----------------------------------------------------------------------===// 30 // Dialect Utilities 31 //===----------------------------------------------------------------------===// 32 33 namespace mlir { 34 /// This class acts as an owning reference to a module, and will automatically 35 /// destroy the held module on destruction if the held module is valid. 36 // TODO: Remove this class in favor of using OwningOpRef directly. 37 class OwningModuleRef : public OwningOpRef<ModuleOp> { 38 public: 39 using OwningOpRef<ModuleOp>::OwningOpRef; 40 OwningModuleRef() = default; OwningModuleRef(OwningOpRef<ModuleOp> && other)41 OwningModuleRef(OwningOpRef<ModuleOp> &&other) 42 : OwningOpRef<ModuleOp>(std::move(other)) {} 43 }; 44 } // end namespace mlir 45 46 namespace llvm { 47 // Functions hash just like pointers. 48 template <> 49 struct DenseMapInfo<mlir::FuncOp> { 50 static mlir::FuncOp getEmptyKey() { 51 auto *pointer = llvm::DenseMapInfo<void *>::getEmptyKey(); 52 return mlir::FuncOp::getFromOpaquePointer(pointer); 53 } 54 static mlir::FuncOp getTombstoneKey() { 55 auto *pointer = llvm::DenseMapInfo<void *>::getTombstoneKey(); 56 return mlir::FuncOp::getFromOpaquePointer(pointer); 57 } 58 static unsigned getHashValue(mlir::FuncOp val) { 59 return hash_value(val.getAsOpaquePointer()); 60 } 61 static bool isEqual(mlir::FuncOp lhs, mlir::FuncOp rhs) { return lhs == rhs; } 62 }; 63 64 /// Allow stealing the low bits of FuncOp. 65 template <> 66 struct PointerLikeTypeTraits<mlir::FuncOp> { 67 static inline void *getAsVoidPointer(mlir::FuncOp val) { 68 return const_cast<void *>(val.getAsOpaquePointer()); 69 } 70 static inline mlir::FuncOp getFromVoidPointer(void *p) { 71 return mlir::FuncOp::getFromOpaquePointer(p); 72 } 73 static constexpr int NumLowBitsAvailable = 3; 74 }; 75 76 /// Allow stealing the low bits of ModuleOp. 77 template <> 78 struct PointerLikeTypeTraits<mlir::ModuleOp> { 79 public: 80 static inline void *getAsVoidPointer(mlir::ModuleOp val) { 81 return const_cast<void *>(val.getAsOpaquePointer()); 82 } 83 static inline mlir::ModuleOp getFromVoidPointer(void *p) { 84 return mlir::ModuleOp::getFromOpaquePointer(p); 85 } 86 static constexpr int NumLowBitsAvailable = 3; 87 }; 88 } // end namespace llvm 89 90 #endif // MLIR_IR_BUILTINOPS_H_ 91