mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 06:06:34 +08:00
This CL removes the dependency of LowerVectorTransfers on the AST version of EDSCs which will be retired. This exhibited a pretty fundamental staging difference in AST-based vs declarative based emission. Since the delayed creation with an AST was staged, the loop order came into existence after the clipping expressions were computed. This now changes as the loops first need to be created declaratively in fixed order and then the clipping expressions are created. Also, due to lack of staging, coalescing cannot be done on the fly anymore and needs to be done either as a pre-pass (current implementation) or as a local transformation on the generated IR (future work). Tests are updated accordingly. PiperOrigin-RevId: 238971631
100 lines
3.3 KiB
C++
100 lines
3.3 KiB
C++
//===- Helpers.cpp - MLIR Declarative Helper Functionality ------*- C++ -*-===//
|
|
//
|
|
// 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/EDSC/Helpers.h"
|
|
#include "mlir/IR/AffineExpr.h"
|
|
#include "mlir/StandardOps/Ops.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::edsc;
|
|
|
|
static SmallVector<ValueHandle, 8> getMemRefSizes(Value *memRef) {
|
|
MemRefType memRefType = memRef->getType().cast<MemRefType>();
|
|
|
|
auto maps = memRefType.getAffineMaps();
|
|
(void)maps;
|
|
assert((maps.empty() || (maps.size() == 1 && maps[0].isIdentity())) &&
|
|
"Layout maps not supported");
|
|
SmallVector<ValueHandle, 8> res;
|
|
res.reserve(memRefType.getShape().size());
|
|
const auto &shape = memRefType.getShape();
|
|
for (unsigned idx = 0, n = shape.size(); idx < n; ++idx) {
|
|
if (shape[idx] == -1) {
|
|
res.push_back(ValueHandle::create<DimOp>(memRef, idx));
|
|
} else {
|
|
res.push_back(static_cast<index_t>(shape[idx]));
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
mlir::edsc::MemRefView::MemRefView(Value *v) : base(v) {
|
|
assert(v->getType().isa<MemRefType>() && "MemRefType expected");
|
|
|
|
auto memrefSizeValues = getMemRefSizes(v);
|
|
for (auto &size : memrefSizeValues) {
|
|
lbs.push_back(static_cast<index_t>(0));
|
|
ubs.push_back(size);
|
|
steps.push_back(1);
|
|
}
|
|
}
|
|
|
|
mlir::edsc::VectorView::VectorView(Value *v) : base(v) {
|
|
auto vectorType = v->getType().cast<VectorType>();
|
|
|
|
for (auto s : vectorType.getShape()) {
|
|
lbs.push_back(static_cast<index_t>(0));
|
|
ubs.push_back(static_cast<index_t>(s));
|
|
steps.push_back(1);
|
|
}
|
|
}
|
|
|
|
/// Operator overloadings.
|
|
ValueHandle mlir::edsc::IndexedValue::operator+(ValueHandle e) {
|
|
using op::operator+;
|
|
return static_cast<ValueHandle>(*this) + e;
|
|
}
|
|
ValueHandle mlir::edsc::IndexedValue::operator-(ValueHandle e) {
|
|
using op::operator-;
|
|
return static_cast<ValueHandle>(*this) - e;
|
|
}
|
|
ValueHandle mlir::edsc::IndexedValue::operator*(ValueHandle e) {
|
|
using op::operator*;
|
|
return static_cast<ValueHandle>(*this) * e;
|
|
}
|
|
ValueHandle mlir::edsc::IndexedValue::operator/(ValueHandle e) {
|
|
using op::operator/;
|
|
return static_cast<ValueHandle>(*this) / e;
|
|
}
|
|
|
|
InstructionHandle mlir::edsc::IndexedValue::operator+=(ValueHandle e) {
|
|
using op::operator+;
|
|
return intrinsics::STORE(*this + e, getBase(), indices);
|
|
}
|
|
InstructionHandle mlir::edsc::IndexedValue::operator-=(ValueHandle e) {
|
|
using op::operator-;
|
|
return intrinsics::STORE(*this - e, getBase(), indices);
|
|
}
|
|
InstructionHandle mlir::edsc::IndexedValue::operator*=(ValueHandle e) {
|
|
using op::operator*;
|
|
return intrinsics::STORE(*this * e, getBase(), indices);
|
|
}
|
|
InstructionHandle mlir::edsc::IndexedValue::operator/=(ValueHandle e) {
|
|
using op::operator/;
|
|
return intrinsics::STORE(*this / e, getBase(), indices);
|
|
}
|