20#include <mlir-c/BuiltinAttributes.h>
22#include <mlir-c/Pass.h>
24#include <mlir/CAPI/IR.h>
25#include <mlir/CAPI/Pass.h>
26#include <mlir/CAPI/Registration.h>
27#include <mlir/CAPI/Support.h>
28#include <mlir/CAPI/Wrap.h>
29#include <mlir/IR/Attributes.h>
30#include <mlir/IR/Diagnostics.h>
31#include <mlir/Support/LLVM.h>
33#include <llvm/ADT/STLExtras.h>
34#include <llvm/ADT/SmallVectorExtras.h>
50MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(POD, llzk__pod,
PODDialect)
54static SmallVector<RecordValue>
56 return llvm::map_to_vector(ArrayRef(values, nValues), [](
const auto &record) {
57 return RecordValue {.name = unwrap(record.name), .value = unwrap(record.value)};
68 auto t = unwrap(type);
69 return wrap(RecordAttr::get(t.getContext(), unwrap(name), t));
79 auto initialValues = fromRawRecordValues(nRecords, records);
85 MutableArrayRef<MlirAttribute> dstRef(dst, records.size());
86 llvm::transform(records, dstRef.begin(), [](
auto record) { return wrap(record); });
92lookupRecordImpl(
PodType type, StringRef name, llvm::function_ref<InFlightDiagnostic()> emitError) {
93 auto attr = type.
getRecord(name, emitError);
95 return MlirType {.ptr =
nullptr};
104 return lookupRecordImpl(
pod, unwrap(name), [
pod] {
105 auto *ctx =
pod.getContext();
106 return ctx->getDiagEngine().emit(Builder(ctx).
getUnknownLoc(), DiagnosticSeverity::Error);
113 return lookupRecordImpl(
pod, unwrap(name), [
pod, loc] {
114 return pod.getContext()->getDiagEngine().emit(unwrap(loc), DiagnosticSeverity::Error);
121 return unwrap(op)->emitError();
132 auto recordValues = fromRawRecordValues(nValues, values);
139 auto recordValues = fromRawRecordValues(nValues, values);
147 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,...)
void registerTransformationPasses()
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...