2018-07-08 20:51:38 -07:00
|
|
|
//===- Builders.cpp - Helpers for constructing MLIR Classes ---------------===//
|
|
|
|
//
|
|
|
|
// Copyright 2019 The MLIR Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
#include "mlir/IR/Builders.h"
|
2018-07-10 10:59:53 -07:00
|
|
|
#include "mlir/IR/AffineExpr.h"
|
|
|
|
#include "mlir/IR/AffineMap.h"
|
|
|
|
#include "mlir/IR/Attributes.h"
|
2018-08-07 14:24:38 -07:00
|
|
|
#include "mlir/IR/IntegerSet.h"
|
2018-08-27 21:05:16 -07:00
|
|
|
#include "mlir/IR/Location.h"
|
2018-07-08 20:51:38 -07:00
|
|
|
#include "mlir/IR/Module.h"
|
2019-01-03 14:29:52 -08:00
|
|
|
#include "mlir/IR/StandardTypes.h"
|
2019-04-05 12:19:22 -07:00
|
|
|
#include "mlir/Support/Functional.h"
|
2018-07-08 20:51:38 -07:00
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
Builder::Builder(Module *module) : context(module->getContext()) {}
|
|
|
|
|
2018-07-10 10:59:53 -07:00
|
|
|
Identifier Builder::getIdentifier(StringRef str) {
|
|
|
|
return Identifier::get(str, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
Module *Builder::createModule() { return new Module(context); }
|
|
|
|
|
2018-08-27 21:05:16 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Locations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-11-08 12:28:35 -08:00
|
|
|
UnknownLoc Builder::getUnknownLoc() { return UnknownLoc::get(context); }
|
2018-08-27 21:05:16 -07:00
|
|
|
|
|
|
|
UniquedFilename Builder::getUniquedFilename(StringRef filename) {
|
|
|
|
return UniquedFilename::get(filename, context);
|
|
|
|
}
|
|
|
|
|
2018-11-08 12:28:35 -08:00
|
|
|
FileLineColLoc Builder::getFileLineColLoc(UniquedFilename filename,
|
|
|
|
unsigned line, unsigned column) {
|
2018-08-27 21:05:16 -07:00
|
|
|
return FileLineColLoc::get(filename, line, column, context);
|
|
|
|
}
|
|
|
|
|
2018-11-09 11:27:28 -08:00
|
|
|
Location Builder::getFusedLoc(ArrayRef<Location> locs, Attribute metadata) {
|
|
|
|
return FusedLoc::get(locs, metadata, context);
|
|
|
|
}
|
|
|
|
|
2018-07-10 10:59:53 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-07-08 20:51:38 -07:00
|
|
|
// Types.
|
2018-07-10 10:59:53 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-02-12 11:08:04 -08:00
|
|
|
FloatType Builder::getBF16Type() { return FloatType::getBF16(context); }
|
2018-07-08 20:51:38 -07:00
|
|
|
|
2019-02-12 11:08:04 -08:00
|
|
|
FloatType Builder::getF16Type() { return FloatType::getF16(context); }
|
2018-07-08 20:51:38 -07:00
|
|
|
|
2019-02-12 11:08:04 -08:00
|
|
|
FloatType Builder::getF32Type() { return FloatType::getF32(context); }
|
2018-07-08 20:51:38 -07:00
|
|
|
|
2019-02-12 11:08:04 -08:00
|
|
|
FloatType Builder::getF64Type() { return FloatType::getF64(context); }
|
2018-07-08 20:51:38 -07:00
|
|
|
|
2019-02-12 11:08:04 -08:00
|
|
|
IndexType Builder::getIndexType() { return IndexType::get(context); }
|
2018-07-08 20:51:38 -07:00
|
|
|
|
2019-02-12 11:08:04 -08:00
|
|
|
IntegerType Builder::getI1Type() { return IntegerType::get(1, context); }
|
2018-11-28 11:49:26 -08:00
|
|
|
|
2018-10-30 14:59:22 -07:00
|
|
|
IntegerType Builder::getIntegerType(unsigned width) {
|
2019-02-12 11:08:04 -08:00
|
|
|
return IntegerType::get(width, context);
|
2018-07-08 20:51:38 -07:00
|
|
|
}
|
|
|
|
|
2018-10-30 14:59:22 -07:00
|
|
|
FunctionType Builder::getFunctionType(ArrayRef<Type> inputs,
|
|
|
|
ArrayRef<Type> results) {
|
2018-07-08 20:51:38 -07:00
|
|
|
return FunctionType::get(inputs, results, context);
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:39:45 -08:00
|
|
|
MemRefType Builder::getMemRefType(ArrayRef<int64_t> shape, Type elementType,
|
2018-10-30 14:59:22 -07:00
|
|
|
ArrayRef<AffineMap> affineMapComposition,
|
|
|
|
unsigned memorySpace) {
|
2018-08-10 11:56:47 -07:00
|
|
|
return MemRefType::get(shape, elementType, affineMapComposition, memorySpace);
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:39:45 -08:00
|
|
|
VectorType Builder::getVectorType(ArrayRef<int64_t> shape, Type elementType) {
|
2018-07-08 20:51:38 -07:00
|
|
|
return VectorType::get(shape, elementType);
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:39:45 -08:00
|
|
|
RankedTensorType Builder::getTensorType(ArrayRef<int64_t> shape,
|
|
|
|
Type elementType) {
|
2018-07-08 20:51:38 -07:00
|
|
|
return RankedTensorType::get(shape, elementType);
|
|
|
|
}
|
|
|
|
|
2018-10-30 14:59:22 -07:00
|
|
|
UnrankedTensorType Builder::getTensorType(Type elementType) {
|
2018-07-08 20:51:38 -07:00
|
|
|
return UnrankedTensorType::get(elementType);
|
|
|
|
}
|
2018-07-10 10:59:53 -07:00
|
|
|
|
2019-03-19 10:59:02 -07:00
|
|
|
TupleType Builder::getTupleType(ArrayRef<Type> elementTypes) {
|
|
|
|
return TupleType::get(elementTypes, context);
|
|
|
|
}
|
|
|
|
|
2019-04-27 18:35:04 -07:00
|
|
|
NoneType Builder::getNoneType() { return NoneType::get(context); }
|
|
|
|
|
2018-07-10 10:59:53 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Attributes.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-02-28 16:45:30 -08:00
|
|
|
NamedAttribute Builder::getNamedAttr(StringRef name, Attribute val) {
|
|
|
|
return NamedAttribute(getIdentifier(name), val);
|
|
|
|
}
|
|
|
|
|
2019-04-25 09:56:09 -07:00
|
|
|
UnitAttr Builder::getUnitAttr() { return UnitAttr::get(context); }
|
|
|
|
|
2018-10-25 15:46:10 -07:00
|
|
|
BoolAttr Builder::getBoolAttr(bool value) {
|
2018-07-10 10:59:53 -07:00
|
|
|
return BoolAttr::get(value, context);
|
|
|
|
}
|
|
|
|
|
2019-05-31 09:24:48 -07:00
|
|
|
DictionaryAttr Builder::getDictionaryAttr(ArrayRef<NamedAttribute> value) {
|
|
|
|
return DictionaryAttr::get(value, context);
|
|
|
|
}
|
|
|
|
|
2018-12-26 11:48:58 -08:00
|
|
|
IntegerAttr Builder::getI64IntegerAttr(int64_t value) {
|
2018-11-15 17:53:51 -08:00
|
|
|
return IntegerAttr::get(getIntegerType(64), APInt(64, value));
|
|
|
|
}
|
|
|
|
|
2018-12-26 11:48:58 -08:00
|
|
|
IntegerAttr Builder::getI32IntegerAttr(int32_t value) {
|
|
|
|
return IntegerAttr::get(getIntegerType(32), APInt(32, value));
|
|
|
|
}
|
|
|
|
|
2018-11-15 17:53:51 -08:00
|
|
|
IntegerAttr Builder::getIntegerAttr(Type type, int64_t value) {
|
|
|
|
if (type.isIndex())
|
|
|
|
return IntegerAttr::get(type, APInt(64, value));
|
2018-12-17 10:05:56 -08:00
|
|
|
return IntegerAttr::get(type, APInt(type.getIntOrFloatBitWidth(), value));
|
2018-11-15 17:53:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
IntegerAttr Builder::getIntegerAttr(Type type, const APInt &value) {
|
|
|
|
return IntegerAttr::get(type, value);
|
2018-07-10 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2018-12-26 11:48:58 -08:00
|
|
|
FloatAttr Builder::getF64FloatAttr(double value) {
|
2018-12-17 07:19:53 -08:00
|
|
|
return FloatAttr::get(getF64Type(), APFloat(value));
|
|
|
|
}
|
|
|
|
|
2018-12-26 11:48:58 -08:00
|
|
|
FloatAttr Builder::getF32FloatAttr(float value) {
|
2018-11-15 17:53:51 -08:00
|
|
|
return FloatAttr::get(getF32Type(), APFloat(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
FloatAttr Builder::getFloatAttr(Type type, double value) {
|
2018-12-17 07:19:53 -08:00
|
|
|
return FloatAttr::get(type, value);
|
2018-10-20 18:31:49 -07:00
|
|
|
}
|
|
|
|
|
2018-11-15 17:53:51 -08:00
|
|
|
FloatAttr Builder::getFloatAttr(Type type, const APFloat &value) {
|
|
|
|
return FloatAttr::get(type, value);
|
2018-07-10 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2018-10-25 15:46:10 -07:00
|
|
|
StringAttr Builder::getStringAttr(StringRef bytes) {
|
2018-07-10 10:59:53 -07:00
|
|
|
return StringAttr::get(bytes, context);
|
|
|
|
}
|
|
|
|
|
2018-10-25 15:46:10 -07:00
|
|
|
ArrayAttr Builder::getArrayAttr(ArrayRef<Attribute> value) {
|
2018-07-10 10:59:53 -07:00
|
|
|
return ArrayAttr::get(value, context);
|
|
|
|
}
|
|
|
|
|
2018-10-25 15:46:10 -07:00
|
|
|
AffineMapAttr Builder::getAffineMapAttr(AffineMap map) {
|
2018-10-09 16:39:24 -07:00
|
|
|
return AffineMapAttr::get(map);
|
2018-07-18 16:29:21 -07:00
|
|
|
}
|
|
|
|
|
2018-10-25 22:13:03 -07:00
|
|
|
IntegerSetAttr Builder::getIntegerSetAttr(IntegerSet set) {
|
|
|
|
return IntegerSetAttr::get(set);
|
|
|
|
}
|
|
|
|
|
2019-05-06 12:40:43 -07:00
|
|
|
TypeAttr Builder::getTypeAttr(Type type) { return TypeAttr::get(type); }
|
2018-08-03 01:54:46 -07:00
|
|
|
|
2019-03-21 11:39:22 -07:00
|
|
|
FunctionAttr Builder::getFunctionAttr(Function *value) {
|
2019-05-06 12:40:43 -07:00
|
|
|
return FunctionAttr::get(value);
|
2018-08-19 21:17:22 -07:00
|
|
|
}
|
2019-05-22 13:41:23 -07:00
|
|
|
FunctionAttr Builder::getFunctionAttr(StringRef value) {
|
|
|
|
return FunctionAttr::get(value, getContext());
|
|
|
|
}
|
2018-08-19 21:17:22 -07:00
|
|
|
|
2019-05-16 00:12:45 -07:00
|
|
|
ElementsAttr Builder::getSplatElementsAttr(ShapedType type, Attribute elt) {
|
2018-10-10 08:57:51 -07:00
|
|
|
return SplatElementsAttr::get(type, elt);
|
|
|
|
}
|
|
|
|
|
2019-05-16 00:12:45 -07:00
|
|
|
ElementsAttr Builder::getDenseElementsAttr(ShapedType type,
|
2018-10-25 15:46:10 -07:00
|
|
|
ArrayRef<char> data) {
|
2018-10-18 13:54:44 -07:00
|
|
|
return DenseElementsAttr::get(type, data);
|
|
|
|
}
|
|
|
|
|
2019-05-16 00:12:45 -07:00
|
|
|
ElementsAttr Builder::getDenseElementsAttr(ShapedType type,
|
2019-01-17 14:11:05 -08:00
|
|
|
ArrayRef<Attribute> values) {
|
|
|
|
return DenseElementsAttr::get(type, values);
|
|
|
|
}
|
|
|
|
|
2019-05-16 00:12:45 -07:00
|
|
|
ElementsAttr Builder::getDenseIntElementsAttr(ShapedType type,
|
2019-03-21 10:03:40 -07:00
|
|
|
ArrayRef<int64_t> values) {
|
|
|
|
return DenseIntElementsAttr::get(type, values);
|
|
|
|
}
|
|
|
|
|
2019-05-16 00:12:45 -07:00
|
|
|
ElementsAttr Builder::getSparseElementsAttr(ShapedType type,
|
2018-10-25 15:46:10 -07:00
|
|
|
DenseIntElementsAttr indices,
|
|
|
|
DenseElementsAttr values) {
|
2018-10-23 13:44:04 -07:00
|
|
|
return SparseElementsAttr::get(type, indices, values);
|
|
|
|
}
|
|
|
|
|
2019-05-16 00:12:45 -07:00
|
|
|
ElementsAttr Builder::getOpaqueElementsAttr(Dialect *dialect, ShapedType type,
|
2018-10-25 15:46:10 -07:00
|
|
|
StringRef bytes) {
|
2019-02-11 22:51:34 -08:00
|
|
|
return OpaqueElementsAttr::get(dialect, type, bytes);
|
Add support to constant sparse tensor / vector attribute
The SparseElementsAttr uses (COO) Coordinate List encoding to represents a
sparse tensor / vector. Specifically, the coordinates and values are stored as
two dense elements attributes. The first dense elements attribute is a 2-D
attribute with shape [N, ndims], which contains the indices of the elements
with nonzero values in the constant vector/tensor. The second elements
attribute is a 1-D attribute list with shape [N], which supplies the values for
each element in the first elements attribute. ndims is the rank of the
vector/tensor and N is the total nonzero elements.
The syntax is:
`sparse<` (tensor-type | vector-type)`, ` indices-attribute-list, values-attribute-list `>`
Example: a sparse tensor
sparse<vector<3x4xi32>, [[0, 0], [1, 2]], [1, 2]> represents the dense tensor
[[1, 0, 0, 0]
[0, 0, 2, 0]
[0, 0, 0, 0]]
PiperOrigin-RevId: 217764319
2018-10-18 14:02:20 -07:00
|
|
|
}
|
|
|
|
|
2019-04-05 12:19:22 -07:00
|
|
|
ArrayAttr Builder::getI32ArrayAttr(ArrayRef<int32_t> values) {
|
|
|
|
auto attrs = functional::map(
|
|
|
|
[this](int32_t v) -> Attribute { return getI32IntegerAttr(v); }, values);
|
|
|
|
return getArrayAttr(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayAttr Builder::getI64ArrayAttr(ArrayRef<int64_t> values) {
|
|
|
|
auto attrs = functional::map(
|
|
|
|
[this](int64_t v) -> Attribute { return getI64IntegerAttr(v); }, values);
|
|
|
|
return getArrayAttr(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayAttr Builder::getF32ArrayAttr(ArrayRef<float> values) {
|
|
|
|
auto attrs = functional::map(
|
|
|
|
[this](float v) -> Attribute { return getF32FloatAttr(v); }, values);
|
|
|
|
return getArrayAttr(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayAttr Builder::getF64ArrayAttr(ArrayRef<double> values) {
|
|
|
|
auto attrs = functional::map(
|
|
|
|
[this](double v) -> Attribute { return getF64FloatAttr(v); }, values);
|
|
|
|
return getArrayAttr(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayAttr Builder::getStrArrayAttr(ArrayRef<StringRef> values) {
|
|
|
|
auto attrs = functional::map(
|
|
|
|
[this](StringRef v) -> Attribute { return getStringAttr(v); }, values);
|
|
|
|
return getArrayAttr(attrs);
|
|
|
|
}
|
|
|
|
|
2019-01-11 09:12:11 -08:00
|
|
|
Attribute Builder::getZeroAttr(Type type) {
|
|
|
|
switch (type.getKind()) {
|
|
|
|
case StandardTypes::F32:
|
|
|
|
return getF32FloatAttr(0);
|
|
|
|
case StandardTypes::F64:
|
|
|
|
return getF64FloatAttr(0);
|
|
|
|
case StandardTypes::Integer: {
|
|
|
|
auto width = type.cast<IntegerType>().getWidth();
|
|
|
|
if (width == 1)
|
|
|
|
return getBoolAttr(false);
|
|
|
|
return getIntegerAttr(type, APInt(width, 0));
|
|
|
|
}
|
|
|
|
case StandardTypes::Vector:
|
|
|
|
case StandardTypes::RankedTensor: {
|
2019-05-16 00:12:45 -07:00
|
|
|
auto vtType = type.cast<ShapedType>();
|
2019-01-11 09:12:11 -08:00
|
|
|
auto element = getZeroAttr(vtType.getElementType());
|
|
|
|
if (!element)
|
|
|
|
return {};
|
|
|
|
return getSplatElementsAttr(vtType, element);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-07-10 10:59:53 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-08-07 14:24:38 -07:00
|
|
|
// Affine Expressions, Affine Maps, and Integet Sets.
|
2018-07-10 10:59:53 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getAffineMap(unsigned dimCount, unsigned symbolCount,
|
2019-05-29 14:56:41 -07:00
|
|
|
ArrayRef<AffineExpr> results) {
|
|
|
|
return AffineMap::get(dimCount, symbolCount, results);
|
2018-07-10 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2018-10-08 13:47:18 -07:00
|
|
|
AffineExpr Builder::getAffineDimExpr(unsigned position) {
|
2018-10-08 10:20:25 -07:00
|
|
|
return mlir::getAffineDimExpr(position, context);
|
2018-07-10 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2018-10-08 13:47:18 -07:00
|
|
|
AffineExpr Builder::getAffineSymbolExpr(unsigned position) {
|
2018-10-08 10:20:25 -07:00
|
|
|
return mlir::getAffineSymbolExpr(position, context);
|
2018-07-10 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2018-10-08 13:47:18 -07:00
|
|
|
AffineExpr Builder::getAffineConstantExpr(int64_t constant) {
|
2018-10-08 10:20:25 -07:00
|
|
|
return mlir::getAffineConstantExpr(constant, context);
|
2018-07-10 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:45:59 -07:00
|
|
|
IntegerSet Builder::getIntegerSet(unsigned dimCount, unsigned symbolCount,
|
|
|
|
ArrayRef<AffineExpr> constraints,
|
|
|
|
ArrayRef<bool> isEq) {
|
2018-10-25 08:33:02 -07:00
|
|
|
return IntegerSet::get(dimCount, symbolCount, constraints, isEq);
|
2018-08-07 14:24:38 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getConstantAffineMap(int64_t val) {
|
2018-10-03 15:39:12 -07:00
|
|
|
return AffineMap::get(/*dimCount=*/0, /*symbolCount=*/0,
|
2019-05-29 14:56:41 -07:00
|
|
|
{getAffineConstantExpr(val)});
|
2018-08-24 23:38:14 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getDimIdentityMap() {
|
2018-10-08 10:20:25 -07:00
|
|
|
return AffineMap::get(/*dimCount=*/1, /*symbolCount=*/0,
|
2019-05-29 14:56:41 -07:00
|
|
|
{getAffineDimExpr(0)});
|
2018-08-24 23:38:14 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getMultiDimIdentityMap(unsigned rank) {
|
2018-10-08 13:47:18 -07:00
|
|
|
SmallVector<AffineExpr, 4> dimExprs;
|
2018-10-08 11:10:11 -07:00
|
|
|
dimExprs.reserve(rank);
|
|
|
|
for (unsigned i = 0; i < rank; ++i)
|
|
|
|
dimExprs.push_back(getAffineDimExpr(i));
|
2019-05-29 14:56:41 -07:00
|
|
|
return AffineMap::get(/*dimCount=*/rank, /*symbolCount=*/0, dimExprs);
|
2018-10-08 11:10:11 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getSymbolIdentityMap() {
|
2018-10-08 10:20:25 -07:00
|
|
|
return AffineMap::get(/*dimCount=*/0, /*symbolCount=*/1,
|
2019-05-29 14:56:41 -07:00
|
|
|
{getAffineSymbolExpr(0)});
|
2018-08-24 23:38:14 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getSingleDimShiftAffineMap(int64_t shift) {
|
2018-10-03 15:34:57 -07:00
|
|
|
// expr = d0 + shift.
|
2018-10-08 10:20:25 -07:00
|
|
|
auto expr = getAffineDimExpr(0) + shift;
|
2019-05-29 14:56:41 -07:00
|
|
|
return AffineMap::get(/*dimCount=*/1, /*symbolCount=*/0, {expr});
|
2018-09-28 12:17:26 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:39:24 -07:00
|
|
|
AffineMap Builder::getShiftedAffineMap(AffineMap map, int64_t shift) {
|
2018-10-08 13:47:18 -07:00
|
|
|
SmallVector<AffineExpr, 4> shiftedResults;
|
2018-10-09 16:39:24 -07:00
|
|
|
shiftedResults.reserve(map.getNumResults());
|
|
|
|
for (auto resultExpr : map.getResults()) {
|
2018-10-09 10:59:27 -07:00
|
|
|
shiftedResults.push_back(resultExpr + shift);
|
2018-09-28 12:17:26 -07:00
|
|
|
}
|
2019-05-29 14:56:41 -07:00
|
|
|
return AffineMap::get(map.getNumDims(), map.getNumSymbols(), shiftedResults);
|
2018-09-28 12:17:26 -07:00
|
|
|
}
|
|
|
|
|
2018-07-19 09:52:39 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-06-04 19:18:23 -07:00
|
|
|
// OpBuilder.
|
2018-07-24 10:15:13 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-06-04 19:18:23 -07:00
|
|
|
OpBuilder::~OpBuilder() {}
|
2019-05-17 15:57:49 -07:00
|
|
|
|
2018-12-28 21:24:30 -08:00
|
|
|
/// Add new block and set the insertion point to the end of it. If an
|
|
|
|
/// 'insertBefore' block is passed, the block will be placed before the
|
2018-08-24 21:13:19 -07:00
|
|
|
/// specified block. If not, the block will be appended to the end of the
|
|
|
|
/// current function.
|
2019-06-04 19:18:23 -07:00
|
|
|
Block *OpBuilder::createBlock(Block *insertBefore) {
|
2018-12-28 13:07:39 -08:00
|
|
|
Block *b = new Block();
|
2018-08-24 21:13:19 -07:00
|
|
|
|
|
|
|
// If we are supposed to insert before a specific block, do so, otherwise add
|
|
|
|
// the block to the end of the function.
|
|
|
|
if (insertBefore)
|
2019-06-04 19:18:23 -07:00
|
|
|
region->getBlocks().insert(Function::iterator(insertBefore), b);
|
2018-08-24 21:13:19 -07:00
|
|
|
else
|
2019-06-04 19:18:23 -07:00
|
|
|
region->push_back(b);
|
2018-08-24 21:13:19 -07:00
|
|
|
|
2018-12-27 15:06:22 -08:00
|
|
|
setInsertionPointToEnd(b);
|
2018-07-24 10:15:13 -07:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:12:35 -07:00
|
|
|
/// Create an operation given the fields represented as an OperationState.
|
2019-06-04 19:18:23 -07:00
|
|
|
Operation *OpBuilder::createOperation(const OperationState &state) {
|
2019-03-02 21:18:19 -08:00
|
|
|
assert(block && "createOperation() called without setting builder's block");
|
2019-03-27 05:11:58 -07:00
|
|
|
auto *op = Operation::create(state);
|
2019-03-26 17:05:09 -07:00
|
|
|
block->getOperations().insert(insertPoint, op);
|
2018-08-07 09:12:35 -07:00
|
|
|
return op;
|
|
|
|
}
|