1 //===- LLVMDialect.h - MLIR LLVM IR dialect ---------------------*- 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 defines the LLVM IR dialect in MLIR, containing LLVM operations and
10 // LLVM type system.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
15 #define MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
16 
17 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
18 #include "mlir/IR/BuiltinOps.h"
19 #include "mlir/IR/Dialect.h"
20 #include "mlir/IR/FunctionInterfaces.h"
21 #include "mlir/IR/OpDefinition.h"
22 #include "mlir/IR/OpImplementation.h"
23 #include "mlir/IR/TypeSupport.h"
24 #include "mlir/IR/Types.h"
25 #include "mlir/Interfaces/CallInterfaces.h"
26 #include "mlir/Interfaces/ControlFlowInterfaces.h"
27 #include "mlir/Interfaces/InferTypeOpInterface.h"
28 #include "mlir/Interfaces/SideEffectInterfaces.h"
29 #include "mlir/Support/ThreadLocalCache.h"
30 #include "llvm/IR/DerivedTypes.h"
31 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/Module.h"
33 #include "llvm/IR/Type.h"
34 
35 #include "mlir/Dialect/LLVMIR/LLVMOpsEnums.h.inc"
36 
37 namespace mlir {
38 namespace LLVM {
39 // Inline the LLVM generated Linkage enum and utility.
40 // This is only necessary to isolate the "enum generated code" from the
41 // attribute definition itself.
42 // TODO: this shouldn't be needed after we unify the attribute generation, i.e.
43 // --gen-attr-* and --gen-attrdef-*.
44 using cconv::CConv;
45 using linkage::Linkage;
46 } // namespace LLVM
47 } // namespace mlir
48 
49 #include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.h.inc"
50 
51 namespace llvm {
52 class Type;
53 class LLVMContext;
54 namespace sys {
55 template <bool mt_only>
56 class SmartMutex;
57 } // namespace sys
58 } // namespace llvm
59 
60 namespace mlir {
61 namespace LLVM {
62 class LLVMDialect;
63 class LoopOptionsAttrBuilder;
64 
65 namespace detail {
66 struct LLVMTypeStorage;
67 struct LLVMDialectImpl;
68 } // namespace detail
69 } // namespace LLVM
70 } // namespace mlir
71 
72 #define GET_ATTRDEF_CLASSES
73 #include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.h.inc"
74 
75 ///// Ops /////
76 #define GET_OP_CLASSES
77 #include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"
78 #define GET_OP_CLASSES
79 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.h.inc"
80 
81 #include "mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc"
82 
83 namespace mlir {
84 namespace LLVM {
85 /// Create an LLVM global containing the string "value" at the module containing
86 /// surrounding the insertion point of builder. Obtain the address of that
87 /// global and use it to compute the address of the first character in the
88 /// string (operations inserted at the builder insertion point).
89 Value createGlobalString(Location loc, OpBuilder &builder, StringRef name,
90                          StringRef value, Linkage linkage);
91 
92 /// LLVM requires some operations to be inside of a Module operation. This
93 /// function confirms that the Operation has the desired properties.
94 bool satisfiesLLVMModule(Operation *op);
95 
96 /// Builder class for LoopOptionsAttr. This helper class allows to progressively
97 /// build a LoopOptionsAttr one option at a time, and pay the price of attribute
98 /// creation once all the options are in place.
99 class LoopOptionsAttrBuilder {
100 public:
101   /// Construct a empty builder.
102   LoopOptionsAttrBuilder() = default;
103 
104   /// Construct a builder with an initial list of options from an existing
105   /// LoopOptionsAttr.
106   LoopOptionsAttrBuilder(LoopOptionsAttr attr);
107 
108   /// Set the `disable_licm` option to the provided value. If no value
109   /// is provided the option is deleted.
110   LoopOptionsAttrBuilder &setDisableLICM(Optional<bool> value);
111 
112   /// Set the `interleave_count` option to the provided value. If no value
113   /// is provided the option is deleted.
114   LoopOptionsAttrBuilder &setInterleaveCount(Optional<uint64_t> count);
115 
116   /// Set the `disable_unroll` option to the provided value. If no value
117   /// is provided the option is deleted.
118   LoopOptionsAttrBuilder &setDisableUnroll(Optional<bool> value);
119 
120   /// Set the `disable_pipeline` option to the provided value. If no value
121   /// is provided the option is deleted.
122   LoopOptionsAttrBuilder &setDisablePipeline(Optional<bool> value);
123 
124   /// Set the `pipeline_initiation_interval` option to the provided value.
125   /// If no value is provided the option is deleted.
126   LoopOptionsAttrBuilder &
127   setPipelineInitiationInterval(Optional<uint64_t> count);
128 
129   /// Returns true if any option has been set.
empty()130   bool empty() { return options.empty(); }
131 
132 private:
133   template <typename T>
134   LoopOptionsAttrBuilder &setOption(LoopOptionCase tag, Optional<T> value);
135 
136   friend class LoopOptionsAttr;
137   SmallVector<LoopOptionsAttr::OptionValuePair> options;
138 };
139 
140 } // namespace LLVM
141 } // namespace mlir
142 
143 #endif // MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
144