13#include "mlir/CAPI/Registration.h"
14#include "mlir/CAPI/Wrap.h"
15#include "mlir/IR/Location.h"
16#include "llvm/ADT/Hashing.h"
17#include "llvm/Support/Casting.h"
46 return wrap(cast<ClassType>(
unwrap(type)).getClassName().getAttr());
51 return isa<FrozenBasePathType>(
unwrap(type));
56 return wrap(FrozenBasePathType::getTypeID());
61 return isa<FrozenPathType>(
unwrap(type));
66 return wrap(FrozenPathType::getTypeID());
77 return wrap(cast<ListType>(
unwrap(type)).getElementType());
82 return isa<OptionType>(
unwrap(type));
90 return wrap(cast<OptionType>(
unwrap(type)).getElementType());
100 return isa<StringType>(
unwrap(type));
146 MlirAttribute className,
147 intptr_t nActualParams,
153 StringAttr cppClassName = cast<StringAttr>(
unwrap(className));
156 SmallVector<std::shared_ptr<evaluator::EvaluatorValue>> cppActualParams;
157 for (
unsigned i = 0; i < nActualParams; i++)
158 cppActualParams.push_back(
unwrap(actualParams[i]));
161 auto result = cppEvaluator->
instantiate(cppClassName, cppActualParams);
169 return wrap(result.value());
190 return wrap(llvm::cast<Object>(
unwrap(
object).get())->getType());
200 return llvm::cast<Object>(
unwrap(
object).get()) ==
201 llvm::cast<Object>(
unwrap(other).get());
206 return wrap(llvm::cast<Object>(
unwrap(
object).get())->getFieldNames());
211 MlirAttribute name) {
214 FailureOr<EvaluatorValuePtr> result =
215 llvm::cast<Object>(
unwrap(
object).get())
216 ->getField(cast<StringAttr>(
unwrap(name)));
232 return wrap(
unwrap(evaluatorValue)->getContext());
243 return !evaluatorValue.
ptr;
249 return isa<evaluator::ObjectValue>(
unwrap(evaluatorValue).get());
255 return isa<evaluator::AttributeValue>(
unwrap(evaluatorValue).get());
263 llvm::cast<evaluator::AttributeValue>(
unwrap(evaluatorValue).get())
275 return isa<evaluator::ListValue>(
unwrap(evaluatorValue).get());
283 return evaluatorValue;
288 return cast<evaluator::ListValue>(
unwrap(evaluatorValue).get())
296 return wrap(cast<evaluator::ListValue>(
unwrap(evaluatorValue).get())
297 ->getElements()[pos]);
301 return isa<evaluator::OptionValue>(
unwrap(evaluatorValue).get());
305 auto type = cast<OptionType>(
unwrap(optionType));
306 return wrap(std::make_shared<evaluator::OptionValue>(
307 type,
nullptr, UnknownLoc::get(type.getContext())));
312 auto type = cast<OptionType>(
unwrap(optionType));
313 return wrap(std::make_shared<evaluator::OptionValue>(
314 type,
unwrap(payload), UnknownLoc::get(type.getContext())));
318 return cast<evaluator::OptionValue>(
unwrap(evaluatorValue).get())->hasValue();
323 cast<evaluator::OptionValue>(
unwrap(evaluatorValue).get())->getValue());
327 return isa<evaluator::BasePathValue>(
unwrap(evaluatorValue).get());
335 return isa<evaluator::PathValue>(
unwrap(evaluatorValue).get());
339 const auto *path = cast<evaluator::PathValue>(
unwrap(evaluatorValue).get());
340 return wrap((Attribute)path->getAsString());
345 return unwrap(evaluatorValue)->isUnknown();
351 auto loc = UnknownLoc::get(ctx);
354 unknownValue->markUnknown();
355 return wrap(unknownValue);
360 return wrap(
unwrap(evaluatorValue)->getType());
368 return isa<ReferenceAttr>(
unwrap(attr));
373 (Attribute)cast<ReferenceAttr>(
unwrap(referenceAttr)).getInnerRef());
381 return isa<circt::om::IntegerAttr>(
unwrap(attr));
385 return wrap(cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue());
389 auto integerAttr = cast<mlir::IntegerAttr>(
unwrap(attr));
391 circt::om::IntegerAttr::get(integerAttr.getContext(), integerAttr));
396 mlir::IntegerAttr integerAttr =
397 cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue();
398 SmallVector<char> str;
399 integerAttr.getValue().toString(
400 str, 10, integerAttr.getType().isSignedInteger());
401 return wrap(StringAttr::get(integerAttr.getContext(), str).getValue());
409 return isa<ListAttr>(
unwrap(attr));
413 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
414 return static_cast<intptr_t
>(listAttr.getElements().size());
418 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
419 return wrap(listAttr.getElements()[pos]);
423 const MlirAttribute *elements) {
424 SmallVector<Attribute, 8>
attrs;
427 auto *ctx = type.getContext();
428 return wrap(ListAttr::get(ctx, type, ArrayAttr::get(ctx,
attrs)));
assert(baseType &&"element must be base type")
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MlirType uint64_t numElements
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
static std::unique_ptr< Context > context
static Location getLoc(DefSlot slot)
bool omTypeIsAFrozenBasePathType(MlirType type)
Is the Type a FrozenBasePathType.
bool omEvaluatorValueIsABasePath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a BasePath.
bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
MlirTypeID omOptionTypeGetTypeID(void)
Get the TypeID for an OptionType.
MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute referenceAttr)
bool omTypeIsAStringType(MlirType type)
Is the Type a StringType.
bool omEvaluatorOptionHasValue(OMEvaluatorValue evaluatorValue)
Query whether a fully evaluated, non-unknown Option is present.
static OMEvaluatorValue wrap(EvaluatorValuePtr object)
Define our own wrap and unwrap instead of using the usual macro.
MlirAttribute omEvaluatorPathGetAsString(OMEvaluatorValue evaluatorValue)
Get a string representation of a Path.
bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
bool omEvaluatorValueIsAOption(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Option.
bool omAttrIsAListAttr(MlirAttribute attr)
OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the List.
OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
OMEvaluatorValue omEvaluatorInstantiate(OMEvaluator evaluator, MlirAttribute className, intptr_t nActualParams, OMEvaluatorValue *actualParams)
Use the Evaluator to Instantiate an Object from its class name and actual parameters.
intptr_t omListAttrGetNumElements(MlirAttribute attr)
MlirAttribute omEvaluatorObjectGetFieldNames(OMEvaluatorValue object)
Get an ArrayAttr with the names of the fields in an Object.
OMEvaluatorValue omEvaluatorOptionGetEmpty(MlirType optionType)
Create an empty Option. The type must be an OptionType.
bool omAttrIsAIntegerAttr(MlirAttribute attr)
OMEvaluatorValue omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name)
Get a field from an Object, which must contain a field of that name.
MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
OMEvaluatorValue omEvaluatorOptionGetValue(OMEvaluatorValue evaluatorValue)
Get the payload of a fully evaluated, non-unknown, present Option.
MlirTypeID omListTypeGetTypeID(void)
Get the TypeID for a ListType.
MlirTypeID omFrozenBasePathTypeGetTypeID(void)
Get the TypeID for a FrozenBasePathType.
MlirTypeID omStringTypeGetTypeID(void)
Get the TypeID for a StringType.
MlirType omStringTypeGet(MlirContext ctx)
Get a StringType.
bool omTypeIsAClassType(MlirType type)
Is the Type a ClassType.
MlirIdentifier omClassTypeGetName(MlirType type)
Get the name for a ClassType.
MlirType omOptionTypeGetElementType(MlirType type)
Get the element type of an OptionType.
bool omTypeIsAListType(MlirType type)
Is the Type a ListType.
intptr_t omEvaluatorListGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the List.
MlirAttribute omListAttrGet(MlirType elementType, intptr_t numElements, const MlirAttribute *elements)
MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
MlirType omOptionTypeGet(MlirType elementType)
Get an OptionType.
MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
bool omEvaluatorValueIsUnknown(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Unknown value.
bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a List.
bool omTypeIsAFrozenPathType(MlirType type)
Is the Type a FrozenPathType.
bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
MlirModule omEvaluatorGetModule(OMEvaluator evaluator)
Get the Module the Evaluator is built from.
bool omTypeIsAOptionType(MlirType type)
Is the Type an OptionType.
OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
MlirTypeID omAnyTypeGetTypeID(void)
Get the TypeID for an AnyType.
MlirTypeID omFrozenPathTypeGetTypeID(void)
Get the TypeID for a FrozenPathType.
OMEvaluatorValue omEvaluatorOptionGet(MlirType optionType, OMEvaluatorValue payload)
Create a present Option.
MlirType omEvaluatorObjectGetType(OMEvaluatorValue object)
Get the Type from an Object, which will be a ClassType.
OMEvaluatorValue omEvaluatorUnknownGet(MlirContext context, MlirType type)
Create an Unknown EvaluatorValue.
bool omAttrIsAReferenceAttr(MlirAttribute attr)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
OMEvaluatorValue omEvaluatorValueGetList(OMEvaluatorValue evaluatorValue)
Get the List from an EvaluatorValue, which must contain a List.
bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
MlirType omListTypeGetElementType(MlirType type)
MlirTypeID omClassTypeGetTypeID()
Get the TypeID for a ClassType.
MlirType omEvaluatorValueGetType(OMEvaluatorValue evaluatorValue)
Get the type of an EvaluatorValue.
unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the hash for the object.
bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check if two objects are same.
struct OMEvaluatorValue OMEvaluatorValue
MLIR_CAPI_EXPORTED bool omTypeIsAAnyType(MlirType type)
Is the Type an AnyType.
DEFINE_C_API_PTR_METHODS(SynthLongestPathHistory, llvm::ImmutableListImpl< DebugPoint >) llvm
An Evaluator, which is constructed with an IR module and can instantiate Objects.
FailureOr< evaluator::EvaluatorValuePtr > instantiate(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
Instantiate an Object with its class name and actual parameters.
static std::shared_ptr< EvaluatorValue > get(Attribute attr, LocationAttr loc={})
Base class for evaluator runtime values.
evaluator::EvaluatorValuePtr EvaluatorValuePtr
llvm::hash_code hash_value(const DenseSet< T > &set)
A value type for use in C APIs that just wraps a pointer to an Object.
A value type for use in C APIs that just wraps a pointer to an Evaluator.