1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
//===- IRDLOps.cpp - IRDL dialect -------------------------------*- C++ -*-===//
//
// This file is licensed 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 "mlir/Dialect/IRDL/IR/IRDL.h"
using namespace mlir;
using namespace mlir::irdl;
std::unique_ptr<Constraint> IsOp::getVerifier(
ArrayRef<Value> valueToConstr,
DenseMap<TypeOp, std::unique_ptr<DynamicTypeDefinition>> const &types,
DenseMap<AttributeOp, std::unique_ptr<DynamicAttrDefinition>> const
&attrs) {
return std::make_unique<IsConstraint>(getExpectedAttr());
}
std::unique_ptr<Constraint> ParametricOp::getVerifier(
ArrayRef<Value> valueToConstr,
DenseMap<TypeOp, std::unique_ptr<DynamicTypeDefinition>> const &types,
DenseMap<AttributeOp, std::unique_ptr<DynamicAttrDefinition>> const
&attrs) {
SmallVector<unsigned> constraints;
for (Value arg : getArgs()) {
for (auto [i, value] : enumerate(valueToConstr)) {
if (value == arg) {
constraints.push_back(i);
break;
}
}
}
// Symbol reference case for the base
SymbolRefAttr symRef = getBaseType();
Operation *defOp =
SymbolTable::lookupNearestSymbolFrom(getOperation(), symRef);
if (!defOp) {
emitError() << symRef << " does not refer to any existing symbol";
return nullptr;
}
if (auto typeOp = dyn_cast<TypeOp>(defOp))
return std::make_unique<DynParametricTypeConstraint>(types.at(typeOp).get(),
constraints);
if (auto attrOp = dyn_cast<AttributeOp>(defOp))
return std::make_unique<DynParametricAttrConstraint>(attrs.at(attrOp).get(),
constraints);
llvm_unreachable("verifier should ensure that the referenced operation is "
"either a type or an attribute definition");
}
std::unique_ptr<Constraint> AnyOfOp::getVerifier(
ArrayRef<Value> valueToConstr,
DenseMap<TypeOp, std::unique_ptr<DynamicTypeDefinition>> const &types,
DenseMap<AttributeOp, std::unique_ptr<DynamicAttrDefinition>> const
&attrs) {
SmallVector<unsigned> constraints;
for (Value arg : getArgs()) {
for (auto [i, value] : enumerate(valueToConstr)) {
if (value == arg) {
constraints.push_back(i);
break;
}
}
}
return std::make_unique<AnyOfConstraint>(constraints);
}
std::unique_ptr<Constraint> AllOfOp::getVerifier(
ArrayRef<Value> valueToConstr,
DenseMap<TypeOp, std::unique_ptr<DynamicTypeDefinition>> const &types,
DenseMap<AttributeOp, std::unique_ptr<DynamicAttrDefinition>> const
&attrs) {
SmallVector<unsigned> constraints;
for (Value arg : getArgs()) {
for (auto [i, value] : enumerate(valueToConstr)) {
if (value == arg) {
constraints.push_back(i);
break;
}
}
}
return std::make_unique<AllOfConstraint>(constraints);
}
std::unique_ptr<Constraint> AnyOp::getVerifier(
ArrayRef<Value> valueToConstr,
DenseMap<TypeOp, std::unique_ptr<DynamicTypeDefinition>> const &types,
DenseMap<AttributeOp, std::unique_ptr<DynamicAttrDefinition>> const
&attrs) {
return std::make_unique<AnyAttributeConstraint>();
}
|