MLIR 23.0.0git
TypeRange.cpp
Go to the documentation of this file.
1//===- TypeRange.cpp ------------------------------------------------------===//
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#include "mlir/IR/TypeRange.h"
10
11using namespace mlir;
12
13//===----------------------------------------------------------------------===//
14// TypeRange
15//===----------------------------------------------------------------------===//
16
18 : TypeRange(types.data(), types.size()) {
19 assert(llvm::all_of(types, [](Type t) { return t; }) &&
20 "attempting to construct a TypeRange with null types");
21}
23 : TypeRange(values.begin().getBase(), values.size()) {}
25 : TypeRange(values.getBase(), values.size()) {}
26TypeRange::TypeRange(ValueRange values) : TypeRange(OwnerT(), values.size()) {
27 if (count == 0)
28 return;
29 ValueRange::OwnerT owner = values.begin().getBase();
30 if (auto *result = llvm::dyn_cast_if_present<detail::OpResultImpl *>(owner))
31 this->base = result;
32 else if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(owner))
33 this->base = operand;
34 else if (auto *repeated =
35 llvm::dyn_cast_if_present<const Repeated<Value> *>(owner))
36 this->base = repeated;
37 else
38 this->base = cast<const Value *>(owner);
39}
40
41/// See `llvm::detail::indexed_accessor_range_base` for details.
42TypeRange::OwnerT TypeRange::offset_base(OwnerT object, ptrdiff_t index) {
43 if (const auto *value = llvm::dyn_cast_if_present<const Value *>(object))
44 return {value + index};
45 if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(object))
46 return {operand + index};
47 if (auto *result = llvm::dyn_cast_if_present<detail::OpResultImpl *>(object))
48 return {result->getNextResultAtOffset(index)};
49 // All elements are identical; the owner pointer never advances.
50 if (llvm::isa<const Repeated<Type> *, const Repeated<Value> *>(object))
51 return object;
52 return {llvm::dyn_cast_if_present<const Type *>(object) + index};
53}
54
55/// See `llvm::detail::indexed_accessor_range_base` for details.
56Type TypeRange::dereference_iterator(OwnerT object, ptrdiff_t index) {
57 if (const auto *value = llvm::dyn_cast_if_present<const Value *>(object))
58 return (value + index)->getType();
59 if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(object))
60 return (operand + index)->get().getType();
61 if (auto *result = llvm::dyn_cast_if_present<detail::OpResultImpl *>(object))
62 return result->getNextResultAtOffset(index)->getType();
63 if (auto *repeated =
64 llvm::dyn_cast_if_present<const Repeated<Type> *>(object))
65 return repeated->value();
66 if (auto *repeated =
67 llvm::dyn_cast_if_present<const Repeated<Value> *>(object))
68 return repeated->value().getType();
69 return llvm::dyn_cast_if_present<const Type *>(object)[index];
70}
static Value getBase(Value v)
Looks through known "view-like" ops to find the base memref.
This class implements the operand iterators for the Operation class.
Definition ValueRange.h:44
This class implements the result iterators for the Operation class.
Definition ValueRange.h:248
TypeRange(ArrayRef< Type > types={})
Definition TypeRange.cpp:17
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
PointerUnion< const Value *, OpOperand *, detail::OpResultImpl *, const Repeated< Value > * > OwnerT
The type representing the owner of a ValueRange.
Definition ValueRange.h:393
Include the generated interface declarations.