1 //===- Builders.h - MLIR EDSC Builders for StandardOps ----------*- C++ -*-===// 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 #ifndef MLIR_DIALECT_STANDARDOPS_EDSC_BUILDERS_H_ 9 #define MLIR_DIALECT_STANDARDOPS_EDSC_BUILDERS_H_ 10 11 #include "mlir/Dialect/StandardOps/IR/Ops.h" 12 #include "mlir/EDSC/Builders.h" 13 #include "mlir/IR/Builders.h" 14 #include "mlir/IR/Types.h" 15 16 namespace mlir { 17 namespace edsc { 18 19 /// Base class for MemRefBoundsCapture and VectorBoundsCapture. 20 class BoundsCapture { 21 public: rank()22 unsigned rank() const { return lbs.size(); } lb(unsigned idx)23 Value lb(unsigned idx) const { return lbs[idx]; } ub(unsigned idx)24 Value ub(unsigned idx) const { return ubs[idx]; } step(unsigned idx)25 int64_t step(unsigned idx) const { return steps[idx]; } range(unsigned idx)26 std::tuple<Value, Value, int64_t> range(unsigned idx) const { 27 return std::make_tuple(lbs[idx], ubs[idx], steps[idx]); 28 } swapRanges(unsigned i,unsigned j)29 void swapRanges(unsigned i, unsigned j) { 30 if (i == j) 31 return; 32 std::swap(lbs[i], lbs[j]); 33 std::swap(ubs[i], ubs[j]); 34 std::swap(steps[i], steps[j]); 35 } 36 getLbs()37 ArrayRef<Value> getLbs() const { return lbs; } getUbs()38 ArrayRef<Value> getUbs() const { return ubs; } getSteps()39 ArrayRef<int64_t> getSteps() const { return steps; } 40 41 protected: 42 SmallVector<Value, 8> lbs; 43 SmallVector<Value, 8> ubs; 44 SmallVector<int64_t, 8> steps; 45 }; 46 47 /// A MemRefBoundsCapture represents the information required to step through a 48 /// MemRef. It has placeholders for non-contiguous tensors that fit within the 49 /// Fortran subarray model. 50 /// At the moment it can only capture a MemRef with an identity layout map. 51 // TODO: Support MemRefs with layoutMaps. 52 class MemRefBoundsCapture : public BoundsCapture { 53 public: 54 explicit MemRefBoundsCapture(Value v); 55 fastestVarying()56 unsigned fastestVarying() const { return rank() - 1; } 57 58 private: 59 Value base; 60 }; 61 62 /// A VectorBoundsCapture represents the information required to step through a 63 /// Vector accessing each scalar element at a time. It is the counterpart of 64 /// a MemRefBoundsCapture but for vectors. This exists purely for boilerplate 65 /// avoidance. 66 class VectorBoundsCapture : public BoundsCapture { 67 public: 68 explicit VectorBoundsCapture(Value v); 69 explicit VectorBoundsCapture(VectorType t); 70 71 private: 72 Value base; 73 }; 74 75 } // namespace edsc 76 } // namespace mlir 77 78 #endif // MLIR_DIALECT_STANDARDOPS_EDSC_BUILDERS_H_ 79