Now that memref supports arbitrary element types, add support for memref of memref and make sure it is properly converted to the LLVM dialect. The type support itself avoids adding the interface to the memref type itself similarly to other built-in types. This allows the shape, and therefore byte size, of the memref descriptor to remain a lowering aspect that is easier to customize and evolve as opposed to sanctifying it in the data layout specification for the memref type itself. Factor out the code previously in a testing pass to live in a dedicated data layout analysis and use that analysis in the conversion to compute the allocation size for memref of memref. Other conversions will be ported separately. Depends On D103827 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D103828
57 lines
2.1 KiB
C++
57 lines
2.1 KiB
C++
//===- TestDataLayoutQuery.cpp - Test Data Layout Queries -----------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "TestDialect.h"
|
|
#include "mlir/Analysis/DataLayoutAnalysis.h"
|
|
#include "mlir/Dialect/DLTI/DLTI.h"
|
|
#include "mlir/IR/BuiltinAttributes.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
using namespace mlir;
|
|
|
|
namespace {
|
|
|
|
/// A pass that finds "test.data_layout_query" operations and attaches to them
|
|
/// attributes containing the results of data layout queries for operation
|
|
/// result types.
|
|
struct TestDataLayoutQuery
|
|
: public PassWrapper<TestDataLayoutQuery, FunctionPass> {
|
|
void runOnFunction() override {
|
|
FuncOp func = getFunction();
|
|
Builder builder(func.getContext());
|
|
const DataLayoutAnalysis &layouts = getAnalysis<DataLayoutAnalysis>();
|
|
|
|
func.walk([&](test::DataLayoutQueryOp op) {
|
|
// Skip the ops with already processed in a deeper call.
|
|
if (op->getAttr("size"))
|
|
return;
|
|
|
|
const DataLayout &layout = layouts.getAbove(op);
|
|
unsigned size = layout.getTypeSize(op.getType());
|
|
unsigned bitsize = layout.getTypeSizeInBits(op.getType());
|
|
unsigned alignment = layout.getTypeABIAlignment(op.getType());
|
|
unsigned preferred = layout.getTypePreferredAlignment(op.getType());
|
|
op->setAttrs(
|
|
{builder.getNamedAttr("size", builder.getIndexAttr(size)),
|
|
builder.getNamedAttr("bitsize", builder.getIndexAttr(bitsize)),
|
|
builder.getNamedAttr("alignment", builder.getIndexAttr(alignment)),
|
|
builder.getNamedAttr("preferred", builder.getIndexAttr(preferred))});
|
|
});
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
namespace mlir {
|
|
namespace test {
|
|
void registerTestDataLayoutQuery() {
|
|
PassRegistration<TestDataLayoutQuery>("test-data-layout-query",
|
|
"Test data layout queries");
|
|
}
|
|
} // namespace test
|
|
} // namespace mlir
|