CIRCT 24.0.0git
Loading...
Searching...
No Matches
Evaluator.cpp
Go to the documentation of this file.
1//===- Evaluator.cpp - Object Model dialect evaluator ---------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Object Model dialect Evaluator.
10//
11//===----------------------------------------------------------------------===//
12
15#include "mlir/IR/Builders.h"
16#include "mlir/IR/BuiltinAttributeInterfaces.h"
17#include "mlir/IR/Location.h"
18#include "mlir/IR/SymbolTable.h"
19#include "mlir/IR/Verifier.h"
20#include "mlir/Pass/PassManager.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/ScopeExit.h"
23#include "llvm/ADT/TypeSwitch.h"
24#include "llvm/ADT/iterator_range.h"
25#include "llvm/Support/Debug.h"
26
27#define DEBUG_TYPE "om-evaluator"
28
29using namespace mlir;
30using namespace circt::om;
31
32/// The evaluator represents registry values as lists.
33static Type getRuntimeType(Type type) {
34 if (auto registry = dyn_cast<RegistryType>(type))
35 return ListType::get(registry.getElementType());
36 return type;
37}
38
39namespace {
40
41LogicalResult verifyActualParameters(ClassLike classLike,
42 ArrayRef<EvaluatorValuePtr> actualParams) {
43 auto formalParamNames =
44 classLike.getFormalParamNames().getAsRange<StringAttr>();
45 auto formalParamTypes = classLike.getBodyBlock()->getArgumentTypes();
46
47 if (actualParams.size() != formalParamTypes.size()) {
48 auto error = classLike.emitError("actual parameter list length (")
49 << actualParams.size() << ") does not match formal "
50 << "parameter list length (" << formalParamTypes.size() << ")";
51 auto &diag = error.attachNote() << "actual parameters: ";
52 bool isFirst = true;
53 for (const auto &param : actualParams) {
54 if (isFirst)
55 isFirst = false;
56 else
57 diag << ", ";
58 diag << param;
59 }
60 error.attachNote(classLike.getLoc())
61 << "formal parameters: " << formalParamTypes;
62 return failure();
63 }
64
65 for (auto [actualParam, formalParamName, formalParamType] :
66 llvm::zip(actualParams, formalParamNames, formalParamTypes)) {
67 if (!actualParam || !actualParam.get())
68 return classLike.emitError("actual parameter for ")
69 << formalParamName << " is null";
70
71 // Subtyping: if formal param is any type, any actual param may be passed.
72 if (isa<AnyType>(formalParamType))
73 continue;
74
75 Type actualParamType = actualParam->getType();
76 assert(actualParamType && "actualParamType must be non-null!");
77
78 if (actualParamType != formalParamType &&
79 actualParamType != getRuntimeType(formalParamType)) {
80 auto error = classLike.emitError("actual parameter for ")
81 << formalParamName << " has invalid type";
82 error.attachNote() << "actual parameter: " << *actualParam;
83 error.attachNote() << "format parameter type: " << formalParamType;
84 return failure();
85 }
86 }
87 return success();
88}
89
90/// A helper class that builds the scratch IR for evaluating an object. This is
91/// used to convert from the evaluator's API (which uses opaque pointers to
92/// evaluator values) into actual MLIR IR.
93class ScratchIRBuilder {
94public:
95 struct InstantiationInfo {
96 StringAttr className;
97 SmallVector<EvaluatorValuePtr> actualParams;
98 };
99
100 ScratchIRBuilder(ModuleOp module, SymbolTable &symbolTable,
101 ClassLike rootClass)
102 : module(module), symbolTable(symbolTable), rootClass(rootClass),
103 wrapperClass(createWrapperClass(rootClass)) {}
104
105 FailureOr<InstantiationInfo> run(ArrayRef<EvaluatorValuePtr> actualParams);
106
107private:
108 /// Create the temporary class that owns all scratch IR.
109 ClassOp createWrapperClass(ClassLike rootClass);
110
111 /// Convert an API input value into scratch IR, preserving opaque any-typed
112 /// inputs and rejecting runtime references/cycles.
113 FailureOr<Value> materializeInput(const EvaluatorValuePtr &value,
114 Location loc, Type expectedType);
115 /// Import a fully evaluated list as a list or registry allocation.
116 FailureOr<Value> materializeContainerInput(evaluator::ListValue *listValue,
117 Location loc, Type type);
118 /// Convert a fully evaluated option into scratch IR.
119 FailureOr<Value> materializeOptionInput(evaluator::OptionValue *optionValue,
120 Location loc);
121 /// Convert a fully evaluated object value into scratch IR.
122 FailureOr<Value> materializeObjectInput(evaluator::ObjectValue *objectValue,
123 Location loc);
124 /// Add a wrapper class parameter for an input that must stay opaque.
125 FailureOr<Value> createWrapperArgument(EvaluatorValuePtr value, Location loc,
126 Type argType);
127
128 ModuleOp module;
129 SymbolTable &symbolTable;
130 ClassLike rootClass;
131 ClassOp wrapperClass;
132 // Preserve input aliases within scratch IR. Include the expected type because
133 // a runtime list can be imported as either a list or a registry.
134 DenseMap<std::pair<evaluator::EvaluatorValue *, Type>, Value> importedValues;
135
136 // A set of object values that have been imported into the scratch IR, used to
137 // detect mutual references in the inputs.
138 SmallPtrSet<evaluator::ObjectValue *, 8> activeObjectImports;
139
140 SmallVector<Attribute> wrapperArgNames;
141 SmallVector<EvaluatorValuePtr> wrapperActualParams;
142};
143
144FailureOr<ScratchIRBuilder::InstantiationInfo>
145ScratchIRBuilder::run(ArrayRef<EvaluatorValuePtr> actualParams) {
146 auto *ctx = module.getContext();
147 assert(rootClass && "root class must be resolved before building scratch IR");
148 auto rootLoc = rootClass.getLoc();
149 auto rootClassName = rootClass.getSymNameAttr();
150
151 OpBuilder builder(wrapperClass.getFieldsOp());
152 builder.setInsertionPoint(wrapperClass.getFieldsOp());
153 SmallVector<Value> importedActualValues;
154 importedActualValues.reserve(actualParams.size());
155 auto formalTypes = rootClass.getBodyBlock()->getArgumentTypes();
156 for (auto [actual, expectedType] : llvm::zip(actualParams, formalTypes)) {
157 auto imported = materializeInput(actual, rootLoc, expectedType);
158 if (failed(imported))
159 return failure();
160 importedActualValues.push_back(*imported);
161 }
162
163 // Update wrapper class after materializing actual parameters.
164 wrapperClass->setAttr(wrapperClass.getFormalParamNamesAttrName(),
165 builder.getArrayAttr(wrapperArgNames));
166
167 wrapperClass.updateFields(
168 {rootLoc},
169 {ObjectOp::create(
170 builder, rootLoc,
171 ClassType::get(ctx, FlatSymbolRefAttr::get(rootClassName)),
172 rootClassName, importedActualValues)
173 .getResult()},
174 {builder.getStringAttr("root")});
175
176 // When this flag is present, skip the verifier for mlir::ModuleOp.
177 // Still verify the wrapper class.
178 auto skipGlobalVerifier =
179 module->getAttrOfType<UnitAttr>("om.evaluator_skip_global_verifier");
180 PassManager pm(ctx);
181 ElaborateObjectOptions options;
182 if (skipGlobalVerifier) {
183 if (failed(verify(wrapperClass)))
184 return failure();
185 pm.enableVerifier(false);
186 } else if (failed(verify(module)))
187 return failure();
188
189 auto wrapperName = wrapperClass.getSymNameAttr();
190 options.targetClass = wrapperName.getValue().str();
191 pm.addPass(createElaborateObject(std::move(options)));
192 if (failed(pm.run(module)))
193 return failure();
194
195 // If module verification was skipped, verify the wrapper class instead. The
196 // pass manager has already run the full verifier otherwise.
197 if (skipGlobalVerifier && failed(verify(wrapperClass)))
198 return failure();
199
200 return InstantiationInfo{wrapperName, std::move(wrapperActualParams)};
201}
202
203ClassOp ScratchIRBuilder::createWrapperClass(ClassLike rootClass) {
204 OpBuilder builder(module.getBody(), module.getBody()->end());
205 builder.setInsertionPointToEnd(module.getBody());
206
207 auto wrapper = ClassOp::create(builder, rootClass.getLoc(),
208 Twine("__om_evaluator_wrapper_") +
209 rootClass.getSymName());
210 (void)symbolTable.insert(wrapper);
211 Block *body = &wrapper.getBody().emplaceBlock();
212 builder.setInsertionPointToEnd(body);
213 ClassFieldsOp::create(builder, rootClass.getLoc(), ValueRange(), ArrayAttr{});
214 return wrapper;
215}
216
217FailureOr<Value>
218// Materializing nested lists and objects requires recursion.
219// NOLINTNEXTLINE(misc-no-recursion)
220ScratchIRBuilder::materializeInput(const EvaluatorValuePtr &value, Location loc,
221 Type expectedType) {
222 if (!value)
223 return emitError(loc, "cannot materialize null OM evaluator value");
224
225 loc = value->getLoc();
226 if (!expectedType)
227 return emitError(loc, "cannot import OM evaluator value without an "
228 "expected type");
229
230 // Keep any-typed values opaque at the wrapper boundary.
231 if (isa<AnyType>(expectedType))
232 return createWrapperArgument(value, loc, expectedType);
233
234 auto key = std::make_pair(value.get(), expectedType);
235 if (auto it = importedValues.find(key); it != importedValues.end())
236 return it->second;
237
238 if (value->isUnknown()) {
239 OpBuilder builder(wrapperClass.getFieldsOp());
240 auto result = UnknownValueOp::create(builder, loc, expectedType);
241 importedValues[key] = result.getResult();
242 return result.getResult();
243 }
244
245 return llvm::TypeSwitch<evaluator::EvaluatorValue *, FailureOr<Value>>(
246 value.get())
247 .Case([&](evaluator::AttributeValue *attrValue) -> FailureOr<Value> {
248 auto attr = attrValue->getAttr();
249 if (!attr)
250 return emitError(loc, "cannot import OM attribute value without an "
251 "attribute");
252 OpBuilder builder(wrapperClass.getFieldsOp());
253 auto result = ConstantOp::create(builder, loc, cast<TypedAttr>(attr));
254 importedValues[key] = result.getResult();
255 return result.getResult();
256 })
257 // NOLINTNEXTLINE(misc-no-recursion)
258 .Case([&](evaluator::ListValue *listValue) -> FailureOr<Value> {
259 auto result = materializeContainerInput(listValue, loc, expectedType);
260 if (succeeded(result))
261 importedValues[key] = *result;
262 return result;
263 })
264 // NOLINTNEXTLINE(misc-no-recursion)
265 .Case([&](evaluator::ObjectValue *objectValue) -> FailureOr<Value> {
266 auto result = materializeObjectInput(objectValue, loc);
267 if (succeeded(result))
268 importedValues[key] = *result;
269 return result;
270 })
271 // NOLINTNEXTLINE(misc-no-recursion)
272 .Case([&](evaluator::OptionValue *optionValue) -> FailureOr<Value> {
273 auto result = materializeOptionInput(optionValue, loc);
274 if (succeeded(result))
275 importedValues[key] = *result;
276 return result;
277 })
278 .Default([&](evaluator::EvaluatorValue *) -> FailureOr<Value> {
279 auto result = createWrapperArgument(value, loc, expectedType);
280 if (succeeded(result))
281 importedValues[key] = *result;
282 return result;
283 });
284}
285
286FailureOr<Value>
287// NOLINTNEXTLINE(misc-no-recursion,llvm-prefer-static-over-anonymous-namespace)
288ScratchIRBuilder::materializeContainerInput(evaluator::ListValue *listValue,
289 Location loc, Type type) {
290 if (!listValue->isFullyEvaluated())
291 return emitError(loc, "cannot import partially evaluated OM list value");
292
293 auto listType = cast<ListType>(getRuntimeType(type));
294 SmallVector<Value> elementValues;
295 elementValues.reserve(listValue->getElements().size());
296 for (const auto &elementValue : listValue->getElements()) {
297 auto materializedElement =
298 materializeInput(elementValue, loc, listType.getElementType());
299 if (failed(materializedElement))
300 return failure();
301 elementValues.push_back(*materializedElement);
302 }
303
304 OpBuilder builder(wrapperClass.getFieldsOp());
305 if (auto registryType = dyn_cast<RegistryType>(type))
306 return RegistryCreateOp::create(builder, loc, registryType, elementValues)
307 .getResult();
308
309 auto result = ListCreateOp::create(builder, loc, listType, elementValues);
310 return result.getResult();
311}
312
313FailureOr<Value>
314// NOLINTNEXTLINE(misc-no-recursion,llvm-prefer-static-over-anonymous-namespace)
315ScratchIRBuilder::materializeOptionInput(evaluator::OptionValue *optionValue,
316 Location loc) {
317 if (!optionValue->isFullyEvaluated())
318 return emitError(loc, "cannot import partially evaluated OM option value");
319
320 auto optionType = optionValue->getOptionType();
321 Value payload;
322 if (optionValue->hasValue()) {
323 auto materialized = materializeInput(optionValue->getValue(), loc,
324 optionType.getElementType());
325 if (failed(materialized))
326 return failure();
327 payload = *materialized;
328 }
329
330 OpBuilder builder(wrapperClass.getFieldsOp());
331 auto result = OptionCreateOp::create(builder, loc, optionType, payload);
332 return result.getResult();
333}
334
335FailureOr<Value>
336// NOLINTNEXTLINE(misc-no-recursion)
337ScratchIRBuilder::materializeObjectInput(evaluator::ObjectValue *objectValue,
338 Location loc) {
339 // TODO: Currently we only support importing object values that don't have
340 // mutual references with other object values in the inputs for the
341 // simplicity. We could construct mutually referencing object values with a
342 // backedge builder but currently we don't have a use case for that.
343 if (!activeObjectImports.insert(objectValue).second)
344 return emitError(loc, "cannot import mutually referential OM objects");
345
346 llvm::scope_exit popActiveObjectImport(
347 [&] { activeObjectImports.erase(objectValue); });
348
349 auto classLike = objectValue->getClassOp();
350 SmallVector<Value> fieldValues;
351 auto fieldNames = classLike.getFieldNames();
352 fieldValues.reserve(fieldNames.size());
353 for (auto fieldName : fieldNames) {
354 auto fieldNameAttr = cast<StringAttr>(fieldName);
355 auto field = objectValue->getField(fieldNameAttr);
356 if (failed(field))
357 return failure();
358 auto materializedField = materializeInput(
359 field.value(), loc, classLike.getFieldType(fieldNameAttr).value());
360 if (failed(materializedField))
361 return failure();
362 fieldValues.push_back(*materializedField);
363 }
364
365 OpBuilder builder(wrapperClass.getFieldsOp());
366 auto result =
367 ElaboratedObjectOp::create(builder, loc, classLike, fieldValues);
368 return result.getResult();
369}
370
371FailureOr<Value>
372ScratchIRBuilder::createWrapperArgument(EvaluatorValuePtr value, Location loc,
373 Type argType) {
374 Builder builder(module.getContext());
375 wrapperArgNames.push_back(
376 builder.getStringAttr(Twine("arg") + Twine(wrapperArgNames.size())));
377 wrapperActualParams.push_back(value);
378 return wrapperClass.getBodyBlock()->addArgument(argType, loc);
379}
380
381} // namespace
382
383/// Construct an Evaluator with an IR module.
385
386/// Get the Module this Evaluator is built from.
388 return cast<ModuleOp>(symbolTable.getOp());
389}
390
391SmallVector<evaluator::EvaluatorValuePtr>
393 ArrayRef<Attribute> attributes) {
394 SmallVector<evaluator::EvaluatorValuePtr> values;
395 values.reserve(attributes.size());
396 for (auto attr : attributes)
397 values.push_back(evaluator::AttributeValue::get(cast<TypedAttr>(attr)));
398 return values;
399}
400
402 return llvm::TypeSwitch<const EvaluatorValue *, Type>(this)
403 .Case<AttributeValue>([](auto *attr) -> Type { return attr->getType(); })
404 .Case<ObjectValue>([](auto *object) { return object->getObjectType(); })
405 .Case<ListValue>([](auto *list) { return list->getListType(); })
406 .Case([](const OptionValue *option) { return option->getOptionType(); })
407 .Case<BasePathValue>(
408 [this](auto *tuple) { return FrozenBasePathType::get(ctx); })
409 .Case<PathValue>(
410 [this](auto *tuple) { return FrozenPathType::get(ctx); });
411}
412
413FailureOr<evaluator::EvaluatorValuePtr>
415 using namespace circt::om::evaluator;
416
417 auto result =
418 TypeSwitch<mlir::Type, FailureOr<evaluator::EvaluatorValuePtr>>(
419 getRuntimeType(type))
420 .Case([&](circt::om::ListType type) {
422 std::make_shared<evaluator::ListValue>(type, loc);
423 return success(result);
424 })
425 .Case([&](circt::om::OptionType type) {
427 std::make_shared<evaluator::OptionValue>(type, loc);
428 return success(result);
429 })
430 .Case([&](circt::om::ClassType type)
431 -> FailureOr<evaluator::EvaluatorValuePtr> {
432 auto classDef =
433 symbolTable.lookup<ClassLike>(type.getClassName().getValue());
434 if (!classDef)
435 return symbolTable.getOp()->emitError("unknown class name ")
436 << type.getClassName();
437
438 // Create an ObjectValue for both ClassOp and ClassExternOp
440 std::make_shared<evaluator::ObjectValue>(classDef, loc);
441
442 return success(result);
443 })
444 .Case([&](circt::om::StringType type) {
447 return success(result);
448 })
449 .Default([&](auto type) { return failure(); });
450
451 return result;
452}
453
454FailureOr<evaluator::EvaluatorValuePtr> circt::om::Evaluator::getOrCreateValue(
455 Value value, ActualParameters actualParams, Location loc) {
456 LLVM_DEBUG(dbgs() << "- get: " << value << "\n");
457
458 auto it = objects.find(value);
459 if (it != objects.end()) {
460 auto evalVal = it->second;
461 evalVal->setLocIfUnknown(loc);
462 return evalVal;
463 }
464
465 FailureOr<evaluator::EvaluatorValuePtr> result =
466 TypeSwitch<Value, FailureOr<evaluator::EvaluatorValuePtr>>(value)
467 .Case([&](BlockArgument arg) {
468 return evaluateParameter(arg, actualParams, loc);
469 })
470 .Case([&](OpResult result) {
471 return TypeSwitch<Operation *,
472 FailureOr<evaluator::EvaluatorValuePtr>>(
473 result.getDefiningOp())
474 .Case([&](ConstantOp op) {
475 return evaluateConstant(op, actualParams, loc);
476 })
477 .Case<AnyCastOp>([&](AnyCastOp op) {
478 return getOrCreateValue(op.getInput(), actualParams, loc);
479 })
480 .Case<FrozenBasePathCreateOp>([&](FrozenBasePathCreateOp op) {
482 std::make_shared<evaluator::BasePathValue>(
483 op.getPathAttr(), loc);
484 return success(result);
485 })
486 .Case<FrozenPathCreateOp>([&](FrozenPathCreateOp op) {
488 std::make_shared<evaluator::PathValue>(
489 op.getTargetKindAttr(), op.getPathAttr(),
490 op.getModuleAttr(), op.getRefAttr(),
491 op.getFieldAttr(), loc);
492 return success(result);
493 })
494 .Case<FrozenEmptyPathOp>([&](FrozenEmptyPathOp op) {
496 std::make_shared<evaluator::PathValue>(
498 return success(result);
499 })
500 .Case<RegistryCreateOp, ListCreateOp, ListConcatOp,
501 OptionCreateOp>([&](auto op) {
502 return getPartiallyEvaluatedValue(op.getType(), loc);
503 })
504 .Case<ElaboratedObjectOp>([&](auto op) {
505 return getPartiallyEvaluatedValue(op.getType(), op.getLoc());
506 })
507 .Case<UnknownValueOp>(
508 [&](auto op) { return evaluateUnknownValue(op, loc); })
509 .Default([&](Operation *op) {
510 auto error = op->emitError("unable to evaluate value");
511 error.attachNote() << "value: " << value;
512 return error;
513 });
514 });
515 if (failed(result))
516 return result;
517
518 objects[value] = result.value();
519 return result;
520}
521
522FailureOr<evaluator::EvaluatorValuePtr>
524 ActualParameters actualParams,
525 Location loc) {
526#ifndef NDEBUG
527 DebugNesting nestOne(debugNesting);
528#endif
529 LLVM_DEBUG(dbgs() << "object:\n");
530#ifndef NDEBUG
531 DebugNesting nestTwo(debugNesting);
532#endif
533 LLVM_DEBUG(dbgs() << "name: " << className << "\n");
534
535 auto classDef = symbolTable.lookup<ClassLike>(className);
536 if (!classDef)
537 return symbolTable.getOp()->emitError("unknown class name ") << className;
538
539 // If this is an external class, create an ObjectValue and mark it unknown
540 if (isa<ClassExternOp>(classDef)) {
542 std::make_shared<evaluator::ObjectValue>(classDef, loc);
543 result->markUnknown();
544 LLVM_DEBUG(dbgs(1) << "extern: <unknown-value>\n");
545 return result;
546 }
547
548 // Otherwise, it's a regular class, proceed normally
549 ClassOp cls = cast<ClassOp>(classDef);
550
551 if (failed(verifyActualParameters(cls, actualParams)))
552 return failure();
553
554 // Instantiate the fields.
556
557 auto *context = cls.getContext();
558 {
559 LLVM_DEBUG(dbgs() << "ops:\n");
560#ifndef NDEBUG
561 DebugNesting nestOne(debugNesting);
562#endif
563 // Allocate placeholders for all class-body results before evaluating any
564 // fields. This allows later operations to refer to earlier or later
565 // results without requiring a retry worklist.
566 for (auto &op : cls.getOps())
567 for (auto result : op.getResults())
568 if (failed(getOrCreateValue(result, actualParams,
569 UnknownLoc::get(context))))
570 return failure();
571
572 // Evaluate every operation after all placeholders have been allocated.
573 for (auto &op : cls.getOps())
574 for (auto result : op.getResults()) {
575 auto evaluated = evaluateValue(result, actualParams, op.getLoc());
576 if (failed(evaluated))
577 return failure();
578 }
579 }
580
581 LLVM_DEBUG(dbgs() << "fields:\n");
582 auto fieldNames = cls.getFieldNames();
583 auto operands = cls.getFieldsOp()->getOperands();
584 for (size_t i = 0; i < fieldNames.size(); ++i) {
585 auto name = fieldNames[i];
586 auto value = operands[i];
587 auto fieldLoc = cls.getFieldLocByIndex(i);
588 LLVM_DEBUG(dbgs() << "- name: " << name << "\n"
589 << indent(1) << "evaluate:\n");
590#ifndef NDEBUG
591 DebugNesting nestOne(debugNesting);
592#endif
593 FailureOr<evaluator::EvaluatorValuePtr> result =
594 evaluateValue(value, actualParams, fieldLoc);
595 if (failed(result))
596 return result;
597
598 LLVM_DEBUG(dbgs() << "value: " << result.value() << "\n");
599 fields[cast<StringAttr>(name)] = result.value();
600 }
601
602 // If it's external call, just allocate new ObjectValue.
604 std::make_shared<evaluator::ObjectValue>(cls, fields, loc);
605 // Object is already fully evaluated when created with fields.
606 assert(result->isFullyEvaluated() &&
607 "object with fields should be fully evaluated");
608 return result;
609}
610
611/// Instantiate an Object with its class name and actual parameters.
612FailureOr<std::shared_ptr<evaluator::EvaluatorValue>>
614 StringAttr className, ArrayRef<evaluator::EvaluatorValuePtr> actualParams) {
615 LLVM_DEBUG(dbgs() << "instantiate:\n");
616#ifndef NDEBUG
617 DebugNesting nest(debugNesting);
618#endif
619 LLVM_DEBUG({
620 dbgs() << "class: " << className << "\n" << indent() << "params:\n";
621 for (auto &param : actualParams)
622 dbgs() << "- " << param << "\n";
623 });
624
625 auto rootClass = symbolTable.lookup<ClassLike>(className);
626 if (!rootClass)
627 return symbolTable.getOp()->emitError("unknown class name ") << className;
628 if (failed(verifyActualParameters(rootClass, actualParams)))
629 return failure();
630
631 ScratchIRBuilder scratchBuilder(getModule(), symbolTable, rootClass);
632 auto transformedInstantiation = scratchBuilder.run(actualParams);
633 if (failed(transformedInstantiation))
634 return failure();
635
636 auto wrapper = instantiateImpl(transformedInstantiation->className,
637 transformedInstantiation->actualParams);
638 if (failed(wrapper))
639 return failure();
640
641 auto root =
642 cast<evaluator::ObjectValue>(wrapper.value().get())->getField("root");
643 if (failed(root))
644 return failure();
645 return root.value();
646}
647
648FailureOr<std::shared_ptr<evaluator::EvaluatorValue>>
650 StringAttr className, ArrayRef<evaluator::EvaluatorValuePtr> actualParams) {
651 auto classDef = symbolTable.lookup<ClassLike>(className);
652 if (!classDef)
653 return symbolTable.getOp()->emitError("unknown class name ") << className;
654
655 // If this is an external class, create an ObjectValue and mark it unknown
656 if (isa<ClassExternOp>(classDef)) {
658 std::make_shared<evaluator::ObjectValue>(
659 classDef, UnknownLoc::get(classDef.getContext()));
660 result->markUnknown();
661 LLVM_DEBUG(dbgs(1) << "result: <unknown extern>\n");
662 return result;
663 }
664
665 // Otherwise, it's a regular class, proceed normally
666 ClassOp cls = cast<ClassOp>(classDef);
667
668 auto loc = cls.getLoc();
669 LLVM_DEBUG(dbgs() << "evaluate object:\n");
670 auto result = evaluateObjectInstance(className, actualParams, loc);
671
672 if (failed(result))
673 return failure();
674
675 LLVM_DEBUG(dbgs() << "result: " << result.value() << "\n");
676 return result;
677}
678
679FailureOr<evaluator::EvaluatorValuePtr>
681 Location loc) {
682 auto evaluatorValue = getOrCreateValue(value, actualParams, loc).value();
683
684 LLVM_DEBUG(dbgs() << "- eval: " << value << "\n");
685
686 // Return if the value is already evaluated.
687 if (evaluatorValue->isFullyEvaluated()) {
688 LLVM_DEBUG(dbgs(1) << "fully evaluated: " << evaluatorValue << "\n");
689 return evaluatorValue;
690 }
691
692 return llvm::TypeSwitch<Value, FailureOr<evaluator::EvaluatorValuePtr>>(value)
693 .Case([&](BlockArgument arg) {
694 return evaluateParameter(arg, actualParams, loc);
695 })
696 .Case([&](OpResult result) {
697 return TypeSwitch<Operation *, FailureOr<evaluator::EvaluatorValuePtr>>(
698 result.getDefiningOp())
699 .Case([&](ConstantOp op) {
700 return evaluateConstant(op, actualParams, loc);
701 })
702 .Case([&](ElaboratedObjectOp op) {
703 return evaluateElaboratedObject(op, actualParams, loc);
704 })
705 // Evaluating nested collections recursively dispatches here.
706 // NOLINTNEXTLINE(misc-no-recursion)
707 .Case<ListCreateOp, RegistryCreateOp>([&](auto op) {
708 return evaluateCollectionCreate(op, actualParams, loc);
709 })
710 .Case([&](ListConcatOp op) {
711 return evaluateListConcat(op, actualParams, loc);
712 })
713 .Case([&](OptionCreateOp op) {
714 return evaluateOptionCreate(op, actualParams, loc);
715 })
716 .Case([&](AnyCastOp op) {
717 return evaluateValue(op.getInput(), actualParams, loc);
718 })
719 .Case([&](FrozenBasePathCreateOp op) {
720 return evaluateBasePathCreate(op, actualParams, loc);
721 })
722 .Case([&](FrozenPathCreateOp op) {
723 return evaluatePathCreate(op, actualParams, loc);
724 })
725 .Case([&](FrozenEmptyPathOp op) {
726 return evaluateEmptyPath(op, actualParams, loc);
727 })
728 .Case<UnknownValueOp>([&](UnknownValueOp op) {
729 return evaluateUnknownValue(op, loc);
730 })
731 .Default([&](Operation *op) {
732 auto error = op->emitError("unable to evaluate value");
733 error.attachNote() << "value: " << value;
734 return error;
735 });
736 });
737}
738
739/// Evaluator dispatch function for parameters.
740FailureOr<evaluator::EvaluatorValuePtr> circt::om::Evaluator::evaluateParameter(
741 BlockArgument formalParam, ActualParameters actualParams, Location loc) {
742 auto val = actualParams[formalParam.getArgNumber()];
743 val->setLoc(loc);
744 return success(val);
745}
746
747/// Evaluator dispatch function for constants.
748FailureOr<circt::om::evaluator::EvaluatorValuePtr>
750 ActualParameters actualParams,
751 Location loc) {
752 // For list constants, create ListValue.
753 return success(om::evaluator::AttributeValue::get(op.getValue(), loc));
754}
755
756FailureOr<evaluator::EvaluatorValuePtr>
758 ActualParameters actualParams,
759 Location loc) {
760 auto objectValue = getOrCreateValue(op, actualParams, loc);
761 if (failed(objectValue))
762 return failure();
763 auto *object = cast<evaluator::ObjectValue>(objectValue.value().get());
764 if (object->isFullyEvaluated())
765 return objectValue;
766
767 auto classLike =
768 symbolTable.lookup<ClassLike>(op.getClassNameAttr().getAttr());
769 if (!classLike)
770 return symbolTable.getOp()->emitError("unknown class name ")
771 << op.getClassNameAttr();
772
773 auto fieldNames = classLike.getFieldNames();
774 auto fieldValues = op.getFieldValues();
775 if (fieldNames.size() != fieldValues.size())
776 return op.emitError("field value list doesn't match class field list, "
777 "expected ")
778 << fieldNames.size() << " values but got " << fieldValues.size();
779
781 auto classOp = dyn_cast<ClassOp>(classLike.getOperation());
782 for (auto [index, fieldNameAndValue] :
783 llvm::enumerate(llvm::zip(fieldNames, fieldValues))) {
784 auto [fieldName, fieldValue] = fieldNameAndValue;
785 auto fieldLoc = classOp ? classOp.getFieldLocByIndex(index) : loc;
786 auto fieldResult = getOrCreateValue(fieldValue, actualParams, fieldLoc);
787 if (failed(fieldResult))
788 return failure();
789
790 fields[cast<StringAttr>(fieldName)] = fieldResult.value();
791 }
792
793 object->setFields(std::move(fields));
794 return objectValue;
795}
796
797/// Evaluator dispatch function for list and registry creation.
798FailureOr<evaluator::EvaluatorValuePtr>
799// Evaluating nested collections requires recursion.
800// NOLINTNEXTLINE(misc-no-recursion)
802 ActualParameters actualParams,
803 Location loc) {
804 // Evaluate the Object itself, in case it hasn't been evaluated yet.
805 SmallVector<evaluator::EvaluatorValuePtr> values;
806 auto list = getOrCreateValue(op->getResult(0), actualParams, loc);
807 if (failed(list))
808 return failure();
809 bool hasUnknown = false;
810 for (auto operand : op->getOperands()) {
811 auto result = evaluateValue(operand, actualParams, loc);
812 if (failed(result))
813 return result;
814 if (!result.value()->isFullyEvaluated())
815 return list;
816 // Check if any operand is unknown.
817 if (result.value()->isUnknown())
818 hasUnknown = true;
819 values.push_back(result.value());
820 }
821
822 // Set the list elements (this also marks the list as fully evaluated).
823 llvm::cast<evaluator::ListValue>(list.value().get())
824 ->setElements(std::move(values));
825
826 // If any operand is unknown, mark the list as unknown.
827 // markUnknown() checks if already fully evaluated before calling
828 // markFullyEvaluated().
829 if (hasUnknown)
830 list.value()->markUnknown();
831
832 return list;
833}
834
835/// Evaluator dispatch function for List concatenation.
836FailureOr<evaluator::EvaluatorValuePtr>
838 ActualParameters actualParams,
839 Location loc) {
840 // Evaluate the List concat op itself, in case it hasn't been evaluated yet.
841 SmallVector<evaluator::EvaluatorValuePtr> values;
842 auto list = getOrCreateValue(op, actualParams, loc);
843
844 bool hasUnknown = false;
845 for (auto operand : op.getOperands()) {
846 auto result = evaluateValue(operand, actualParams, loc);
847 if (failed(result))
848 return result;
849 if (!result.value()->isFullyEvaluated())
850 return list;
851 // Check if any operand is unknown.
852 if (result.value()->isUnknown())
853 hasUnknown = true;
854
855 auto *subList = llvm::cast<evaluator::ListValue>(result.value().get());
856
857 // Append each EvaluatorValue from the sublist.
858 for (const auto &subValue : subList->getElements())
859 values.push_back(subValue);
860 }
861
862 // Return the concatenated list.
863 llvm::cast<evaluator::ListValue>(list.value().get())
864 ->setElements(std::move(values));
865
866 // If any operand is unknown, mark the result as unknown.
867 // markUnknown() checks if already fully evaluated before calling
868 // markFullyEvaluated().
869 if (hasUnknown)
870 list.value()->markUnknown();
871
872 return list;
873}
874
876 OptionCreateOp op, ActualParameters actualParams, Location loc) {
877 auto result = getOrCreateValue(op, actualParams, loc);
878 if (failed(result))
879 return failure();
880 auto *option = cast<evaluator::OptionValue>(result.value().get());
881 if (option->isFullyEvaluated())
882 return result;
883
884 EvaluatorValuePtr payload;
885 if (auto value = op.getValue()) {
886 // Reuse the payload's placeholder to allow forward references and cycles.
887 auto valueResult = getOrCreateValue(value, actualParams, loc);
888 if (failed(valueResult))
889 return failure();
890 payload = *valueResult;
891 }
892 option->setValue(std::move(payload));
893 return result;
894}
895
896FailureOr<evaluator::EvaluatorValuePtr>
898 ActualParameters actualParams,
899 Location loc) {
900 // Evaluate the Object itself, in case it hasn't been evaluated yet.
901 auto valueResult = getOrCreateValue(op, actualParams, loc).value();
902 auto *path = llvm::cast<evaluator::BasePathValue>(valueResult.get());
903 auto result = evaluateValue(op.getBasePath(), actualParams, loc);
904 if (failed(result))
905 return result;
906 auto &value = result.value();
907 if (!value->isFullyEvaluated())
908 return valueResult;
909
910 // If the base path is unknown, mark the result as unknown.
911 if (result.value()->isUnknown()) {
912 valueResult->markUnknown();
913 return valueResult;
914 }
915
916 path->setBasepath(*llvm::cast<evaluator::BasePathValue>(value.get()));
917 return valueResult;
918}
919
920FailureOr<evaluator::EvaluatorValuePtr>
922 ActualParameters actualParams,
923 Location loc) {
924 // Evaluate the Object itself, in case it hasn't been evaluated yet.
925 auto valueResult = getOrCreateValue(op, actualParams, loc).value();
926 auto *path = llvm::cast<evaluator::PathValue>(valueResult.get());
927 auto result = evaluateValue(op.getBasePath(), actualParams, loc);
928 if (failed(result))
929 return result;
930 auto &value = result.value();
931 if (!value->isFullyEvaluated())
932 return valueResult;
933
934 // If the base path is unknown, mark the result as unknown.
935 if (result.value()->isUnknown()) {
936 valueResult->markUnknown();
937 return valueResult;
938 }
939
940 path->setBasepath(*llvm::cast<evaluator::BasePathValue>(value.get()));
941 return valueResult;
942}
943
944FailureOr<evaluator::EvaluatorValuePtr> circt::om::Evaluator::evaluateEmptyPath(
945 FrozenEmptyPathOp op, ActualParameters actualParams, Location loc) {
946 auto valueResult = getOrCreateValue(op, actualParams, loc).value();
947 return valueResult;
948}
949
950/// Create an unknown value of the specified type
951FailureOr<evaluator::EvaluatorValuePtr>
953 using namespace circt::om::evaluator;
954
955 // Create an unknown value of the appropriate type by switching on the type
956 auto result =
957 TypeSwitch<Type, FailureOr<EvaluatorValuePtr>>(type)
958 .Case([&](ListType type) -> FailureOr<EvaluatorValuePtr> {
959 // Create an empty list
960 return success(std::make_shared<ListValue>(type, loc));
961 })
962 .Case([&](OptionType type) -> FailureOr<EvaluatorValuePtr> {
963 return success(std::make_shared<OptionValue>(type, loc));
964 })
965 .Case([&](ClassType type) -> FailureOr<EvaluatorValuePtr> {
966 // Look up the class definition
967 auto classDef =
968 symbolTable.lookup<ClassLike>(type.getClassName().getValue());
969 if (!classDef)
970 return symbolTable.getOp()->emitError("unknown class name ")
971 << type.getClassName();
972
973 // Create an ObjectValue for both ClassOp and ClassExternOp
974 return success(std::make_shared<ObjectValue>(classDef, loc));
975 })
976 .Case([&](FrozenBasePathType type) -> FailureOr<EvaluatorValuePtr> {
977 // Create an empty basepath
978 return success(std::make_shared<BasePathValue>(type.getContext()));
979 })
980 .Case([&](FrozenPathType type) -> FailureOr<EvaluatorValuePtr> {
981 // Create an empty path
982 return success(
983 std::make_shared<PathValue>(PathValue::getEmptyPath(loc)));
984 })
985 .Default([&](Type type) -> FailureOr<EvaluatorValuePtr> {
986 // For all other types (primitives like integer, string,
987 // etc.), create an AttributeValue
988 return success(AttributeValue::get(type, LocationAttr(loc)));
989 });
990
991 // Mark the result as unknown if successful.
992 if (succeeded(result))
993 result->get()->markUnknown();
994
995 return result;
996}
997
998/// Evaluate an unknown value
999FailureOr<evaluator::EvaluatorValuePtr>
1000circt::om::Evaluator::evaluateUnknownValue(UnknownValueOp op, Location loc) {
1001 return createUnknownValue(op.getType(), loc);
1002}
1003
1004//===----------------------------------------------------------------------===//
1005// ObjectValue
1006//===----------------------------------------------------------------------===//
1007
1008/// Get a field of the Object by name.
1009FailureOr<EvaluatorValuePtr>
1011 auto field = fields.find(name);
1012 if (field == fields.end())
1013 return cls.emitError("field ") << name << " does not exist";
1014 return success(fields[name]);
1015}
1016
1017/// Get an ArrayAttr with the names of the fields in the Object. Sort the fields
1018/// so there is always a stable order.
1020 SmallVector<Attribute> fieldNames;
1021 for (auto &f : fields)
1022 fieldNames.push_back(f.first);
1023
1024 llvm::sort(fieldNames, [](Attribute a, Attribute b) {
1025 return cast<StringAttr>(a).getValue() < cast<StringAttr>(b).getValue();
1026 });
1027
1028 return ArrayAttr::get(cls.getContext(), fieldNames);
1029}
1030
1031//===----------------------------------------------------------------------===//
1032// BasePathValue
1033//===----------------------------------------------------------------------===//
1034
1036 : EvaluatorValue(context, Kind::BasePath, UnknownLoc::get(context)),
1037 path(PathAttr::get(context, {})) {
1038 markFullyEvaluated();
1039}
1040
1041evaluator::BasePathValue::BasePathValue(PathAttr path, Location loc)
1042 : EvaluatorValue(path.getContext(), Kind::BasePath, loc), path(path) {}
1043
1046 return path;
1047}
1048
1051 auto newPath = llvm::to_vector(basepath.path.getPath());
1052 auto oldPath = path.getPath();
1053 newPath.append(oldPath.begin(), oldPath.end());
1054 path = PathAttr::get(path.getContext(), newPath);
1056}
1057
1058//===----------------------------------------------------------------------===//
1059// PathValue
1060//===----------------------------------------------------------------------===//
1061
1063 StringAttr module, StringAttr ref,
1064 StringAttr field, Location loc)
1067
1069 PathValue path(nullptr, nullptr, nullptr, nullptr, nullptr, loc);
1070 path.markFullyEvaluated();
1071 return path;
1072}
1073
1075 // If the module is null, then this is a path to a deleted object.
1076 if (!targetKind)
1077 return StringAttr::get(getContext(), "OMDeleted:");
1078 SmallString<64> result;
1079 switch (targetKind.getValue()) {
1080 case TargetKind::DontTouch:
1081 result += "OMDontTouchedReferenceTarget";
1082 break;
1083 case TargetKind::Instance:
1084 result += "OMInstanceTarget";
1085 break;
1086 case TargetKind::MemberInstance:
1087 result += "OMMemberInstanceTarget";
1088 break;
1089 case TargetKind::MemberReference:
1090 result += "OMMemberReferenceTarget";
1091 break;
1092 case TargetKind::Reference:
1093 result += "OMReferenceTarget";
1094 break;
1095 }
1096 result += ":~";
1097 if (!path.getPath().empty())
1098 result += path.getPath().front().module;
1099 else
1100 result += module.getValue();
1101 result += '|';
1102 for (const auto &elt : path) {
1103 result += elt.module.getValue();
1104 result += '/';
1105 result += elt.instance.getValue();
1106 result += ':';
1107 }
1108 if (!module.getValue().empty())
1109 result += module.getValue();
1110 if (!ref.getValue().empty()) {
1111 result += '>';
1112 result += ref.getValue();
1113 }
1114 if (!field.getValue().empty())
1115 result += field.getValue();
1116 return StringAttr::get(field.getContext(), result);
1117}
1118
1121 auto newPath = llvm::to_vector(basepath.getPath().getPath());
1122 auto oldPath = path.getPath();
1123 newPath.append(oldPath.begin(), oldPath.end());
1124 path = PathAttr::get(path.getContext(), newPath);
1126}
1127
1128//===----------------------------------------------------------------------===//
1129// AttributeValue
1130//===----------------------------------------------------------------------===//
1131
1133 if (cast<TypedAttr>(attr).getType() != this->type)
1134 return mlir::emitError(getLoc(), "cannot set AttributeValue of type ")
1135 << this->type << " to Attribute " << attr;
1136 if (isFullyEvaluated())
1137 return mlir::emitError(
1138 getLoc(),
1139 "cannot set AttributeValue that has already been fully evaluated");
1140 this->attr = attr;
1142 return success();
1143}
1144
1145std::shared_ptr<evaluator::EvaluatorValue>
1147 auto type = cast<TypedAttr>(attr).getType();
1148 auto *context = type.getContext();
1149 if (!loc)
1150 loc = UnknownLoc::get(context);
1151
1152 // Special handling for ListType to create proper ListValue objects instead of
1153 // AttributeValue objects.
1154 if (auto listType = dyn_cast<circt::om::ListType>(type)) {
1155 SmallVector<EvaluatorValuePtr> elements;
1156 auto listAttr = cast<om::ListAttr>(attr);
1158 listAttr.getContext(), listAttr.getElements().getValue());
1159 elements.append(values.begin(), values.end());
1160 auto list = std::make_shared<evaluator::ListValue>(listType, elements, loc);
1161 return list;
1162 }
1163
1164 return std::shared_ptr<AttributeValue>(
1166}
1167
1168std::shared_ptr<evaluator::EvaluatorValue>
1170 auto *context = type.getContext();
1171 if (!loc)
1172 loc = UnknownLoc::get(context);
1173
1174 // Lists, registries, and options use container values rather than
1175 // AttributeValue. Registries are represented as lists at runtime.
1176 if (auto listType = dyn_cast<ListType>(getRuntimeType(type)))
1177 return std::make_shared<evaluator::ListValue>(listType, loc);
1178 if (auto optionType = dyn_cast<circt::om::OptionType>(type))
1179 return std::make_shared<evaluator::OptionValue>(optionType, loc);
1180 // Create the AttributeValue with the private tag
1181 return std::shared_ptr<AttributeValue>(
1183}
assert(baseType &&"element must be base type")
static std::unique_ptr< Context > context
static Type getRuntimeType(Type type)
The evaluator represents registry values as lists.
Definition Evaluator.cpp:33
static Location getLoc(DefSlot slot)
Definition Mem2Reg.cpp:193
false return failure()
Parse an optional keyword or string and set instance into 'result'.
return success()
FailureOr< evaluator::EvaluatorValuePtr > evaluateBasePathCreate(FrozenBasePathCreateOp op, ActualParameters actualParams, Location loc)
FailureOr< EvaluatorValuePtr > evaluateElaboratedObject(ElaboratedObjectOp op, ActualParameters actualParams, Location loc)
FailureOr< evaluator::EvaluatorValuePtr > evaluateEmptyPath(FrozenEmptyPathOp op, ActualParameters actualParams, Location loc)
FailureOr< evaluator::EvaluatorValuePtr > instantiate(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
Instantiate an Object with its class name and actual parameters.
SymbolTable symbolTable
The symbol table for the IR module the Evaluator was constructed with.
Definition Evaluator.h:414
FailureOr< evaluator::EvaluatorValuePtr > getPartiallyEvaluatedValue(Type type, Location loc)
FailureOr< EvaluatorValuePtr > evaluateValue(Value value, ActualParameters actualParams, Location loc)
Evaluate a Value in a Class body according to the small expression grammar described in the rationale...
FailureOr< EvaluatorValuePtr > evaluateConstant(ConstantOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for constants.
DenseMap< Value, std::shared_ptr< evaluator::EvaluatorValue > > objects
Evaluator value storage for the current instantiation.
Definition Evaluator.h:417
FailureOr< EvaluatorValuePtr > evaluateOptionCreate(OptionCreateOp op, ActualParameters actualParams, Location loc)
mlir::ModuleOp getModule()
Get the Module this Evaluator is built from.
ArrayRef< EvaluatorValuePtr > ActualParameters
Definition Evaluator.h:358
FailureOr< evaluator::EvaluatorValuePtr > createUnknownValue(Type type, Location loc)
Create an unknown value of the specified type.
FailureOr< EvaluatorValuePtr > evaluateCollectionCreate(Operation *op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for list and registry creation.
FailureOr< EvaluatorValuePtr > evaluateObjectInstance(StringAttr className, ActualParameters actualParams, Location loc)
Instantiate an Object with its class name and actual parameters.
llvm::indent indent(unsigned extra=0)
Definition Evaluator.h:434
unsigned debugNesting
Current nesting depth for debug output indentation.
Definition Evaluator.h:421
FailureOr< evaluator::EvaluatorValuePtr > evaluateUnknownValue(UnknownValueOp op, Location loc)
Evaluate an unknown value.
Evaluator(ModuleOp mod)
Construct an Evaluator with an IR module.
raw_ostream & dbgs(unsigned extra=0)
Definition Evaluator.h:430
FailureOr< EvaluatorValuePtr > getOrCreateValue(Value value, ActualParameters actualParams, Location loc)
FailureOr< evaluator::EvaluatorValuePtr > instantiateImpl(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
FailureOr< EvaluatorValuePtr > evaluateListConcat(ListConcatOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for List concatenation.
FailureOr< EvaluatorValuePtr > evaluateParameter(BlockArgument formalParam, ActualParameters actualParams, Location loc)
Evaluator dispatch functions for the small expression grammar.
FailureOr< evaluator::EvaluatorValuePtr > evaluatePathCreate(FrozenPathCreateOp op, ActualParameters actualParams, Location loc)
Values which can be directly representable by MLIR attributes.
Definition Evaluator.h:103
LogicalResult setAttr(Attribute attr)
AttributeValue(PrivateTag, Attribute attr, Location loc)
Definition Evaluator.h:129
static std::shared_ptr< EvaluatorValue > get(Attribute attr, LocationAttr loc={})
BasePathValue(MLIRContext *context)
void setBasepath(const BasePathValue &basepath)
Set the basepath which this path is relative to.
Base class for evaluator runtime values.
Definition Evaluator.h:47
EvaluatorValue(MLIRContext *ctx, Kind kind, Location loc)
Definition Evaluator.h:51
MLIRContext * getContext() const
Definition Evaluator.h:54
const auto & getElements() const
Definition Evaluator.h:166
FailureOr< EvaluatorValuePtr > getField(StringAttr field)
Get a field of the Object by name.
ArrayAttr getFieldNames()
Get all the field names of the Object.
om::ClassLike getClassOp() const
Definition Evaluator.h:238
llvm::SmallDenseMap< StringAttr, EvaluatorValuePtr > fields
Definition Evaluator.h:271
An option whose payload may be unevaluated to support forward references and cycles.
Definition Evaluator.h:184
const EvaluatorValuePtr & getValue() const
Definition Evaluator.h:211
om::OptionType getOptionType() const
Definition Evaluator.h:203
om::TargetKindAttr targetKind
Definition Evaluator.h:325
void setBasepath(const BasePathValue &basepath)
PathValue(om::TargetKindAttr targetKind, om::PathAttr path, StringAttr module, StringAttr ref, StringAttr field, Location loc)
Create a path value representing a regular path.
static PathValue getEmptyPath(Location loc)
void error(Twine message)
Definition LSPUtils.cpp:16
SmallDenseMap< StringAttr, EvaluatorValuePtr > ObjectFields
The fields of a composite Object, currently represented as a map.
Definition Evaluator.h:41
std::shared_ptr< EvaluatorValue > EvaluatorValuePtr
A value of an object in memory.
Definition Evaluator.h:37
SmallVector< EvaluatorValuePtr > getEvaluatorValuesFromAttributes(MLIRContext *context, ArrayRef< Attribute > attributes)
evaluator::EvaluatorValuePtr EvaluatorValuePtr
Definition Evaluator.h:335
int run(Type[Generator] generator=CppGenerator, List[str] cmdline_args=sys.argv)
RAII helper to increment/decrement debugNesting.
Definition Evaluator.h:424