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/InstrTypes.h"
37 #include "llvm/IR/LLVMContext.h"
38 #include "llvm/IR/Module.h"
39 #include "llvm/IR/Type.h"
45 template <
bool mt_only>
55 struct LLVMTypeStorage;
56 struct LLVMDialectImpl;
63 template <
typename Values>
64 class GEPIndicesAdaptor;
70 llvm::PointerEmbeddedInt<int32_t, kGEPConstantBitWidth>;
86 using BaseT::operator=;
99 #define GET_OP_CLASSES
100 #include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"
101 #define GET_OP_CLASSES
102 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.h.inc"
104 #include "mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc"
122 template <
typename DynamicRange>
132 llvm::detail::ValueOfRange<DynamicRange>>::value,
139 : rawConstantIndices(rawConstantIndices), values(std::move(values)) {}
147 assert(index <
size() &&
"index out of bounds");
148 return *std::next(
begin(), index);
153 return rawConstantIndices[index] == GEPOp::kDynamicIndex;
157 size_t size()
const {
return rawConstantIndices.size(); }
160 bool empty()
const {
return rawConstantIndices.empty(); }
163 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
164 value_type, std::ptrdiff_t,
165 value_type *, value_type> {
169 llvm::detail::IterOfRange<const DynamicRange> valuesIter)
170 : base(base), rawConstantIter(rawConstantIter), valuesIter(valuesIter) {
174 if (*rawConstantIter == GEPOp::kDynamicIndex)
182 if (*rawConstantIter == GEPOp::kDynamicIndex)
189 return base == rhs.base && rawConstantIter == rhs.rawConstantIter &&
190 valuesIter == rhs.valuesIter;
196 llvm::detail::IterOfRange<const DynamicRange> valuesIter;
220 StringRef value, Linkage linkage);
228 template <
typename IntT =
int64_t>
231 indices.reserve(attrs.size());
233 indices.push_back(cast<IntegerAttr>(attr).getInt());
239 template <
typename IntT =
int64_t>
241 return convertArrayToIndices<IntT>(attrs.getValue());
250 template <
typename To>
252 :
public CastInfo<To, mlir::LLVM::GEPArg::PointerUnion> {};
254 template <
typename To>
256 :
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
The OpAsmOpInterface, see OpAsmInterface.td for more details.
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...