14 #ifndef MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
15 #define MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
34 #include "llvm/ADT/PointerEmbeddedInt.h"
35 #include "llvm/IR/DerivedTypes.h"
36 #include "llvm/IR/LLVMContext.h"
37 #include "llvm/IR/Module.h"
38 #include "llvm/IR/Type.h"
44 template <
bool mt_only>
54 struct LLVMTypeStorage;
55 struct LLVMDialectImpl;
62 template <
typename Values>
63 class GEPIndicesAdaptor;
69 llvm::PointerEmbeddedInt<int32_t, kGEPConstantBitWidth>;
85 using BaseT::operator=;
91 #define GET_OP_CLASSES
92 #include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"
93 #define GET_OP_CLASSES
94 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.h.inc"
96 #include "mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc"
114 template <
typename DynamicRange>
124 llvm::detail::ValueOfRange<DynamicRange>>::value,
131 : rawConstantIndices(rawConstantIndices), values(std::move(values)) {}
139 assert(index <
size() &&
"index out of bounds");
140 return *std::next(
begin(), index);
145 return rawConstantIndices[index] == GEPOp::kDynamicIndex;
149 size_t size()
const {
return rawConstantIndices.size(); }
152 bool empty()
const {
return rawConstantIndices.empty(); }
155 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
156 value_type, std::ptrdiff_t,
157 value_type *, value_type> {
161 llvm::detail::IterOfRange<const DynamicRange> valuesIter)
162 : base(base), rawConstantIter(rawConstantIter), valuesIter(valuesIter) {
166 if (*rawConstantIter == GEPOp::kDynamicIndex)
174 if (*rawConstantIter == GEPOp::kDynamicIndex)
181 return base == rhs.base && rawConstantIter == rhs.rawConstantIter &&
182 valuesIter == rhs.valuesIter;
188 llvm::detail::IterOfRange<const DynamicRange> valuesIter;
212 StringRef value, Linkage linkage,
213 bool useOpaquePointers);
221 template <
typename IntT =
int64_t>
224 indices.reserve(attrs.size());
226 indices.push_back(cast<IntegerAttr>(attr).getInt());
232 template <
typename IntT =
int64_t>
234 return convertArrayToIndices<IntT>(attrs.getValue());
243 template <
typename To>
245 :
public CastInfo<To, mlir::LLVM::GEPArg::PointerUnion> {};
247 template <
typename To>
249 :
public CastInfo<To, const mlir::LLVM::GEPArg::PointerUnion> {};
Attributes are known-constant values of operations.
Class used for building a 'llvm.getelementptr'.
GEPArg(int32_t integer)
Constructs a GEPArg with a constant index.
GEPArg(Value value)
Constructs a GEPArg with a dynamic index.
iterator(const GEPIndicesAdaptor *base, ArrayRef< int32_t >::iterator rawConstantIter, llvm::detail::IterOfRange< const DynamicRange > valuesIter)
bool operator==(const iterator &rhs) const
value_type operator*() const
Class used for convenient access and iteration over GEP indices.
iterator begin() const
Returns the begin iterator, iterating over all GEP indices.
std::conditional_t< std::is_base_of< Attribute, llvm::detail::ValueOfRange< DynamicRange > >::value, Attribute, PointerUnion< IntegerAttr, llvm::detail::ValueOfRange< DynamicRange > >> value_type
Return type of 'operator[]' and the iterators 'operator*'.
iterator end() const
Returns the end iterator, iterating over all GEP indices.
bool isDynamicIndex(size_t index) const
Returns whether the GEP index at the given position is a dynamic index.
size_t size() const
Returns the amount of indices of the GEPOp.
bool empty() const
Returns true if this GEPOp does not have any indices.
value_type operator[](size_t index) const
Returns the GEP index at the given position.
GEPIndicesAdaptor(DenseI32ArrayAttr rawConstantIndices, DynamicRange values)
Constructs a GEPIndicesAdaptor with the raw constant indices of a GEPOp and the range that is indexed...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
ArrayRef< T > asArrayRef() const
Include the generated interface declarations.
bool satisfiesLLVMModule(Operation *op)
LLVM requires some operations to be inside of a Module operation.
llvm::PointerEmbeddedInt< int32_t, kGEPConstantBitWidth > GEPConstantIndex
Wrapper around a int32_t for use in a PointerUnion.
constexpr int kGEPConstantBitWidth
Bit-width of a 'GEPConstantIndex' within GEPArg.
Value createGlobalString(Location loc, OpBuilder &builder, StringRef name, StringRef value, Linkage linkage, bool useOpaquePointers)
Create an LLVM global containing the string "value" at the module containing surrounding the insertio...
SmallVector< IntT > convertArrayToIndices(ArrayRef< Attribute > attrs)
Convert an array of integer attributes to a vector of integers that can be used as indices in LLVM op...
@ Type
An inlay hint that for a type annotation.
This header declares functions that assit transformations in the MemRef dialect.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...