MLIR  21.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 //===----------------------------------------------------------------------===//
17 
19  : TypeRange(types.data(), types.size()) {
20  assert(llvm::all_of(types, [](Type t) { return t; }) &&
21  "attempting to construct a TypeRange with null types");
22 }
24  : TypeRange(values.begin().getBase(), values.size()) {}
26  : TypeRange(values.getBase(), values.size()) {}
27 TypeRange::TypeRange(ValueRange values) : TypeRange(OwnerT(), values.size()) {
28  if (count == 0)
29  return;
30  ValueRange::OwnerT owner = values.begin().getBase();
31  if (auto *result = llvm::dyn_cast_if_present<detail::OpResultImpl *>(owner))
32  this->base = result;
33  else if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(owner))
34  this->base = operand;
35  else
36  this->base = cast<const Value *>(owner);
37 }
38 
39 /// See `llvm::detail::indexed_accessor_range_base` for details.
40 TypeRange::OwnerT TypeRange::offset_base(OwnerT object, ptrdiff_t index) {
41  if (const auto *value = llvm::dyn_cast_if_present<const Value *>(object))
42  return {value + index};
43  if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(object))
44  return {operand + index};
45  if (auto *result = llvm::dyn_cast_if_present<detail::OpResultImpl *>(object))
46  return {result->getNextResultAtOffset(index)};
47  return {llvm::dyn_cast_if_present<const Type *>(object) + index};
48 }
49 
50 /// See `llvm::detail::indexed_accessor_range_base` for details.
51 Type TypeRange::dereference_iterator(OwnerT object, ptrdiff_t index) {
52  if (const auto *value = llvm::dyn_cast_if_present<const Value *>(object))
53  return (value + index)->getType();
54  if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(object))
55  return (operand + index)->get().getType();
56  if (auto *result = llvm::dyn_cast_if_present<detail::OpResultImpl *>(object))
57  return result->getNextResultAtOffset(index)->getType();
58  return llvm::dyn_cast_if_present<const Type *>(object)[index];
59 }
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:43
This class implements the result iterators for the Operation class.
Definition: ValueRange.h:247
This class provides an abstraction over the various different ranges of value types.
Definition: TypeRange.h:37
TypeRange(ArrayRef< Type > types=std::nullopt)
Definition: TypeRange.cpp:18
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:387
Include the generated interface declarations.