14 #ifndef MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
15 #define MLIR_DIALECT_LLVMIR_LLVMDIALECT_H_
33 #include "llvm/ADT/PointerEmbeddedInt.h"
34 #include "llvm/IR/DerivedTypes.h"
35 #include "llvm/IR/LLVMContext.h"
36 #include "llvm/IR/Module.h"
37 #include "llvm/IR/Type.h"
43 template <
bool mt_only>
53 struct LLVMTypeStorage;
54 struct LLVMDialectImpl;
61 template <
typename Values>
62 class GEPIndicesAdaptor;
68 llvm::PointerEmbeddedInt<int32_t, kGEPConstantBitWidth>;
84 using BaseT::operator=;
90 #define GET_OP_CLASSES
91 #include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"
92 #define GET_OP_CLASSES
93 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.h.inc"
95 #include "mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc"
113 template <
typename DynamicRange>
123 llvm::detail::ValueOfRange<DynamicRange>>::value,
130 : rawConstantIndices(rawConstantIndices), values(std::move(values)) {}
138 assert(index <
size() &&
"index out of bounds");
139 return *std::next(
begin(), index);
144 return rawConstantIndices[index] == GEPOp::kDynamicIndex;
148 size_t size()
const {
return rawConstantIndices.size(); }
151 bool empty()
const {
return rawConstantIndices.empty(); }
154 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
155 value_type, std::ptrdiff_t,
156 value_type *, value_type> {
160 llvm::detail::IterOfRange<const DynamicRange> valuesIter)
161 : base(base), rawConstantIter(rawConstantIter), valuesIter(valuesIter) {
165 if (*rawConstantIter == GEPOp::kDynamicIndex)
173 if (*rawConstantIter == GEPOp::kDynamicIndex)
180 return base == rhs.base && rawConstantIter == rhs.rawConstantIter &&
181 valuesIter == rhs.valuesIter;
187 llvm::detail::IterOfRange<const DynamicRange> valuesIter;
211 StringRef value, Linkage linkage);
219 template <
typename IntT =
int64_t>
222 indices.reserve(attrs.size());
224 indices.push_back(cast<IntegerAttr>(attr).getInt());
230 template <
typename IntT =
int64_t>
232 return convertArrayToIndices<IntT>(attrs.getValue());
241 template <
typename To>
243 :
public CastInfo<To, mlir::LLVM::GEPArg::PointerUnion> {};
245 template <
typename To>
247 :
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.
Value createGlobalString(Location loc, OpBuilder &builder, StringRef name, StringRef value, Linkage linkage)
Create an LLVM global containing the string "value" at the module containing surrounding the insertio...
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.
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.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...