21#include <mlir/CAPI/IR.h>
22#include <mlir/CAPI/Registration.h>
23#include <mlir/CAPI/Support.h>
24#include <mlir/CAPI/Wrap.h>
25#include <mlir/IR/Attributes.h>
26#include <mlir/IR/Diagnostics.h>
27#include <mlir/Support/LLVM.h>
29#include <llvm/ADT/STLExtras.h>
30#include <llvm/ADT/SmallVectorExtras.h>
43MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(POD, llzk__pod,
PODDialect)
47static SmallVector<RecordValue>
49 return llvm::map_to_vector(ArrayRef(values, nValues), [](
const auto &record) {
50 return RecordValue {.name = unwrap(record.name), .value = unwrap(record.value)};
61 auto t = unwrap(type);
62 return wrap(RecordAttr::get(t.getContext(), unwrap(name), t));
72 auto initialValues = fromRawRecordValues(nRecords, records);
78 MutableArrayRef<MlirAttribute> dstRef(dst, records.size());
79 llvm::transform(records, dstRef.begin(), [](
auto record) { return wrap(record); });
85lookupRecordImpl(
PodType type, StringRef name, llvm::function_ref<InFlightDiagnostic()> emitError) {
86 auto attr = type.
getRecord(name, emitError);
88 return MlirType {.ptr =
nullptr};
97 return lookupRecordImpl(
pod, unwrap(name), [
pod] {
98 auto *ctx =
pod.getContext();
99 return ctx->getDiagEngine().emit(Builder(ctx).
getUnknownLoc(), DiagnosticSeverity::Error);
106 return lookupRecordImpl(
pod, unwrap(name), [
pod, loc] {
107 return pod.getContext()->getDiagEngine().emit(unwrap(loc), DiagnosticSeverity::Error);
114 return unwrap(op)->emitError();
125 auto recordValues = fromRawRecordValues(nValues, values);
132 auto recordValues = fromRawRecordValues(nValues, values);
140 auto recordValues = fromRawRecordValues(nValues, values);
void llzkPod_PodTypeGetRecords(MlirType type, MlirAttribute *dst)
Writes the records into the given array that must have been previously allocated with enough space.
MlirType llzkPod_PodTypeLookupRecord(MlirType type, MlirStringRef name)
Lookups a record type by name.
MlirAttribute llzkPod_RecordAttrGetInferredContext(MlirIdentifier name, MlirType type)
Creates a new llzk::pod::RecordAttr using the MlirContext of the given type.
MlirType llzkPod_PodTypeLookupRecordWithinLocation(MlirType type, MlirStringRef name, MlirLocation loc)
Lookups a record type by name.
MlirType llzkPod_PodTypeLookupRecordWithinOperation(MlirType type, MlirStringRef name, MlirOperation op)
Lookups a record type by name.
MlirType llzkPod_PodTypeGetFromInitialValues(MlirContext context, intptr_t nRecords, LlzkRecordValue const *records)
Creates an llzk::pod::PodType using a list of values for inferring the records.
MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Helper for unwrapping the C arguments for the map operands.
::llvm::FailureOr<::mlir::Type > getRecord(::llvm::StringRef name, ::llvm::function_ref<::mlir::InFlightDiagnostic()>) const
Searches a record by name.
static PodType fromInitialValues(::mlir::MLIRContext *ctx, InitializedRecords init)
Creates a new type from a set of initialized records.
#define LLZK_DEFINE_OP_BUILD_METHOD(dialect, op,...)
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix,...)
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
mlir::Location getUnknownLoc(mlir::MLIRContext *context)
auto unwrap_cast(auto &from)
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
MlirValueRange * mapOperands
Information needed to define a pod RecordAttr given a name and a value that will be stored in the rec...