MLIR  14.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 #include "mlir/IR/Operation.h"
11 
12 using namespace mlir;
13 
14 //===----------------------------------------------------------------------===//
15 // TypeRange
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()) {}
27  : TypeRange(values.data(), values.size()) {}
28 TypeRange::TypeRange(ValueRange values) : TypeRange(OwnerT(), values.size()) {
29  if (count == 0)
30  return;
31  ValueRange::OwnerT owner = values.begin().getBase();
32  if (auto *result = owner.dyn_cast<detail::OpResultImpl *>())
33  this->base = result;
34  else if (auto *operand = owner.dyn_cast<OpOperand *>())
35  this->base = operand;
36  else
37  this->base = owner.get<const Value *>();
38 }
39 
40 /// See `llvm::detail::indexed_accessor_range_base` for details.
41 TypeRange::OwnerT TypeRange::offset_base(OwnerT object, ptrdiff_t index) {
42  if (const auto *value = object.dyn_cast<const Value *>())
43  return {value + index};
44  if (auto *operand = object.dyn_cast<OpOperand *>())
45  return {operand + index};
46  if (auto *result = object.dyn_cast<detail::OpResultImpl *>())
47  return {result->getNextResultAtOffset(index)};
48  return {object.dyn_cast<const Type *>() + index};
49 }
50 
51 /// See `llvm::detail::indexed_accessor_range_base` for details.
52 Type TypeRange::dereference_iterator(OwnerT object, ptrdiff_t index) {
53  if (const auto *value = object.dyn_cast<const Value *>())
54  return (value + index)->getType();
55  if (auto *operand = object.dyn_cast<OpOperand *>())
56  return (operand + index)->get().getType();
57  if (auto *result = object.dyn_cast<detail::OpResultImpl *>())
58  return result->getNextResultAtOffset(index)->getType();
59  return object.dyn_cast<const Type *>()[index];
60 }
Include the generated interface declarations.
This class implements the result iterators for the Operation class.
static constexpr const bool value
TypeRange(ArrayRef< Type > types=llvm::None)
Definition: TypeRange.cpp:17
U dyn_cast() const
Definition: Types.h:244
This class provides an abstraction over the various different ranges of value types.
Definition: TypeRange.h:38
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:72
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:84
This class represents an operand of an operation.
Definition: Value.h:249
This class implements the operand iterators for the Operation class.
This class provides the implementation for an operation result.
Definition: Value.h:347
This class provides an abstraction over the different types of ranges over Values.