CIRCT 23.0.0git
Loading...
Searching...
No Matches
Evaluator.h
Go to the documentation of this file.
1//===- Evaluator.h - 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 contains the Object Model dialect declaration.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_OM_EVALUATOR_EVALUATOR_H
14#define CIRCT_DIALECT_OM_EVALUATOR_EVALUATOR_H
15
17#include "circt/Support/LLVM.h"
18#include "mlir/IR/BuiltinOps.h"
19#include "mlir/IR/Diagnostics.h"
20#include "mlir/IR/Location.h"
21#include "mlir/IR/MLIRContext.h"
22#include "mlir/IR/SymbolTable.h"
23#include "mlir/Support/LogicalResult.h"
24#include "llvm/ADT/SmallPtrSet.h"
25#include "llvm/ADT/SmallString.h"
26#include "llvm/Support/Debug.h"
27
28#include <queue>
29#include <utility>
30
31namespace circt {
32namespace om {
33
34namespace evaluator {
35class EvaluatorValue;
36
37/// A value of an object in memory. It is either a composite Object, or a
38/// primitive Attribute. Further refinement is expected.
39using EvaluatorValuePtr = std::shared_ptr<EvaluatorValue>;
40
41/// The fields of a composite Object, currently represented as a map. Further
42/// refinement is expected.
44
45/// Base class for evaluator runtime values.
46/// Enables the shared_from_this functionality so Evaluator Value pointers can
47/// be passed through the CAPI and unwrapped back into C++ smart pointers with
48/// the appropriate reference count.
49class EvaluatorValue : public std::enable_shared_from_this<EvaluatorValue> {
50public:
51 // Implement LLVM RTTI.
52 enum class Kind { Attr, Object, List, Reference, BasePath, Path };
53 EvaluatorValue(MLIRContext *ctx, Kind kind, Location loc)
54 : kind(kind), ctx(ctx), loc(loc) {}
55 Kind getKind() const { return kind; }
56 MLIRContext *getContext() const { return ctx; }
57
58 // Return true the value is fully evaluated.
59 // Unknown values are considered fully evaluated.
60 bool isFullyEvaluated() const { return fullyEvaluated; }
62 assert(!fullyEvaluated && "should not mark twice");
63 fullyEvaluated = true;
64 // Increment the counter if one is set.
66 ++(*fullyEvaluatedCounter);
67 }
68
69 /// Set a counter to increment when this value becomes fully evaluated.
70 void setFullyEvaluatedCounter(uint64_t *counter) {
71 fullyEvaluatedCounter = counter;
72 }
73
74 /// Return true if the value is unknown (has unknown in its fan-in).
75 /// A value is unknown if it depends on an UnknownValueOp or if any of its
76 /// inputs are unknown. Unknown values propagate through operations.
77 bool isUnknown() const { return unknown; }
78
79 /// Mark this value as unknown.
80 /// This also marks the value as fully evaluated if it isn't already, since
81 /// unknown values are considered fully evaluated. This maintains the
82 /// invariant that unknown implies fullyEvaluated.
83 void markUnknown() {
84 unknown = true;
85 if (!fullyEvaluated)
87 }
88
89 /// Return the associated MLIR context.
90 MLIRContext *getContext() { return ctx; }
91
92 // Return a MLIR type which the value represents.
93 Type getType() const;
94
95 // Finalize the evaluator value. Strip intermidiate reference values.
96 LogicalResult finalize();
97
98 // Return the Location associated with the Value.
99 Location getLoc() const { return loc; }
100 // Set the Location associated with the Value.
101 void setLoc(Location l) { loc = l; }
102 // Set the Location, if it is unknown.
103 void setLocIfUnknown(Location l) {
104 if (isa<UnknownLoc>(loc))
105 loc = l;
106 }
107
108private:
109 const Kind kind;
110 MLIRContext *ctx;
111 Location loc;
112 bool fullyEvaluated = false;
113 bool finalized = false;
114 bool unknown = false;
115 uint64_t *fullyEvaluatedCounter = nullptr;
116};
117
118/// Values which can be used as pointers to different values.
119/// ReferenceValue is replaced with its element and erased at the end of
120/// evaluation.
122public:
123 ReferenceValue(Type type, Location loc)
125 type(type) {}
126
127 // Implement LLVM RTTI.
128 static bool classof(const EvaluatorValue *e) {
129 return e->getKind() == Kind::Reference;
130 }
131
132 Type getValueType() const { return type; }
133 EvaluatorValuePtr getValue() const { return value; }
135 value = std::move(newValue);
137 }
138
139 // Finalize the value.
140 LogicalResult finalizeImpl();
141
142 // Return the first non-reference value that is reachable from the reference.
143 FailureOr<EvaluatorValuePtr> getStrippedValue() const {
144 llvm::SmallPtrSet<ReferenceValue *, 4> visited;
145 auto currentValue = value;
146 while (auto *v = dyn_cast<ReferenceValue>(currentValue.get())) {
147 // Detect a cycle.
148 if (!visited.insert(v).second)
149 return failure();
150 currentValue = v->getValue();
151 }
152 return success(currentValue);
153 }
154
155private:
157 Type type;
158};
159
160/// Values which can be directly representable by MLIR attributes.
162public:
163 Attribute getAttr() const { return attr; }
164 template <typename AttrTy>
165 AttrTy getAs() const {
166 return dyn_cast<AttrTy>(attr);
167 }
168 static bool classof(const EvaluatorValue *e) {
169 return e->getKind() == Kind::Attr;
170 }
171
172 // Set Attribute for partially evaluated case.
173 LogicalResult setAttr(Attribute attr);
174
175 // Finalize the value.
176 LogicalResult finalizeImpl();
177
178 Type getType() const { return type; }
179
180 // Factory methods that create AttributeValue objects
181 static std::shared_ptr<EvaluatorValue> get(Attribute attr,
182 LocationAttr loc = {});
183 static std::shared_ptr<EvaluatorValue> get(Type type, LocationAttr loc = {});
184
185private:
186 // Make AttributeValue constructible only by the factory methods
187 struct PrivateTag {};
188
189 // Constructor that requires a PrivateTag
190 AttributeValue(PrivateTag, Attribute attr, Location loc)
192 type(cast<TypedAttr>(attr).getType()) {
194 }
195
196 // Constructor for partially evaluated AttributeValue
199
200 Attribute attr = {};
201 Type type;
202
203 // Friend declaration for the factory methods
204 friend std::shared_ptr<EvaluatorValue> get(Attribute attr, LocationAttr loc);
205 friend std::shared_ptr<EvaluatorValue> get(Type type, LocationAttr loc);
206};
207
208// This perform finalization to `value`.
209static inline LogicalResult finalizeEvaluatorValue(EvaluatorValuePtr &value) {
210 if (failed(value->finalize()))
211 return failure();
212 if (auto *ref = llvm::dyn_cast<ReferenceValue>(value.get())) {
213 auto v = ref->getStrippedValue();
214 if (failed(v))
215 return v;
216 value = v.value();
217 }
218 return success();
219}
220
221/// A List which contains variadic length of elements with the same type.
222class ListValue : public EvaluatorValue {
223public:
224 ListValue(om::ListType type, SmallVector<EvaluatorValuePtr> elements,
225 Location loc)
227 elements(std::move(elements)) {
229 }
230
231 void setElements(SmallVector<EvaluatorValuePtr> newElements) {
232 elements = std::move(newElements);
234 }
235
236 // Finalize the value.
237 LogicalResult finalizeImpl();
238
239 // Partially evaluated value.
240 ListValue(om::ListType type, Location loc)
242
243 const auto &getElements() const { return elements; }
244
245 /// Return the type of the value, which is a ListType.
246 om::ListType getListType() const { return type; }
247
248 /// Implement LLVM RTTI.
249 static bool classof(const EvaluatorValue *e) {
250 return e->getKind() == Kind::List;
251 }
252
253private:
254 om::ListType type;
255 SmallVector<EvaluatorValuePtr> elements;
256};
257
258/// A composite Object, which has a type and fields.
260public:
261 ObjectValue(om::ClassLike cls, ObjectFields fields, Location loc)
263 fields(std::move(fields)) {
265 }
266
267 // Partially evaluated value.
268 ObjectValue(om::ClassLike cls, Location loc)
270
271 om::ClassLike getClassOp() const { return cls; }
272 const auto &getFields() const { return fields; }
273
275 fields = std::move(newFields);
277 }
278
279 /// Return the type of the value, which is a ClassType.
280 om::ClassType getObjectType() const {
281 auto clsNonConst = const_cast<om::ClassLike &>(cls);
282 return ClassType::get(clsNonConst.getContext(),
283 FlatSymbolRefAttr::get(clsNonConst.getSymNameAttr()));
284 }
285
286 Type getType() const { return getObjectType(); }
287
288 /// Implement LLVM RTTI.
289 static bool classof(const EvaluatorValue *e) {
290 return e->getKind() == Kind::Object;
291 }
292
293 /// Get a field of the Object by name.
294 FailureOr<EvaluatorValuePtr> getField(StringAttr field);
295 FailureOr<EvaluatorValuePtr> getField(StringRef field) {
296 return getField(StringAttr::get(getContext(), field));
297 }
298
299 /// Get all the field names of the Object.
300 ArrayAttr getFieldNames();
301
302 // Finalize the evaluator value.
303 LogicalResult finalizeImpl();
304
305private:
306 om::ClassLike cls;
308};
309
310/// A Basepath value.
312public:
313 BasePathValue(MLIRContext *context);
314
315 /// Create a path value representing a basepath.
316 BasePathValue(om::PathAttr path, Location loc);
317
318 om::PathAttr getPath() const;
319
320 /// Set the basepath which this path is relative to.
321 void setBasepath(const BasePathValue &basepath);
322
323 /// Finalize the evaluator value.
324 LogicalResult finalizeImpl() { return success(); }
325
326 /// Implement LLVM RTTI.
327 static bool classof(const EvaluatorValue *e) {
328 return e->getKind() == Kind::BasePath;
329 }
330
331private:
332 om::PathAttr path;
333};
334
335/// A Path value.
336class PathValue : public EvaluatorValue {
337public:
338 /// Create a path value representing a regular path.
339 PathValue(om::TargetKindAttr targetKind, om::PathAttr path, StringAttr module,
340 StringAttr ref, StringAttr field, Location loc);
341
342 static PathValue getEmptyPath(Location loc);
343
344 om::TargetKindAttr getTargetKind() const { return targetKind; }
345
346 om::PathAttr getPath() const { return path; }
347
348 StringAttr getModule() const { return module; }
349
350 StringAttr getRef() const { return ref; }
351
352 StringAttr getField() const { return field; }
353
354 StringAttr getAsString() const;
355
356 void setBasepath(const BasePathValue &basepath);
357
358 // Finalize the evaluator value.
359 LogicalResult finalizeImpl() { return success(); }
360
361 /// Implement LLVM RTTI.
362 static bool classof(const EvaluatorValue *e) {
363 return e->getKind() == Kind::Path;
364 }
365
366private:
367 om::TargetKindAttr targetKind;
368 om::PathAttr path;
369 StringAttr module;
370 StringAttr ref;
371 StringAttr field;
372};
373
374} // namespace evaluator
375
378
379SmallVector<EvaluatorValuePtr>
381 ArrayRef<Attribute> attributes);
382
383/// An Evaluator, which is constructed with an IR module and can instantiate
384/// Objects. Further refinement is expected.
386public:
387 /// Construct an Evaluator with an IR module.
388 Evaluator(ModuleOp mod);
389
390 /// Instantiate an Object with its class name and actual parameters.
391 FailureOr<evaluator::EvaluatorValuePtr>
392 instantiate(StringAttr className, ArrayRef<EvaluatorValuePtr> actualParams);
393
394 /// Get the Module this Evaluator is built from.
395 mlir::ModuleOp getModule();
396
397 FailureOr<evaluator::EvaluatorValuePtr>
398 getPartiallyEvaluatedValue(Type type, Location loc);
399
401 SmallVectorImpl<std::shared_ptr<evaluator::EvaluatorValue>> *;
402
403 using ObjectKey = std::pair<Value, ActualParameters>;
404
405 /// Get the number of fully evaluated nodes tracked by this evaluator.
406 uint64_t getFullyEvaluatedCount() const { return fullyEvaluatedCount; }
407
408private:
409 bool isFullyEvaluated(Value value, ActualParameters key) {
410 return isFullyEvaluated({value, key});
411 }
412
414 auto val = objects.lookup(key);
415 return val && val->isFullyEvaluated();
416 }
417
418 /// Attach the evaluation counter to a newly created value.
420 if (value && !value->isFullyEvaluated())
421 value->setFullyEvaluatedCounter(&fullyEvaluatedCount);
422 }
423
424 FailureOr<evaluator::EvaluatorValuePtr>
425 instantiateImpl(StringAttr className,
426 ArrayRef<EvaluatorValuePtr> actualParams);
427
428 FailureOr<EvaluatorValuePtr>
429 getOrCreateValue(Value value, ActualParameters actualParams, Location loc);
430 FailureOr<EvaluatorValuePtr>
431 allocateObjectInstance(StringAttr clasName, ActualParameters actualParams);
432
433 /// Evaluate a Value in a Class body according to the small expression grammar
434 /// described in the rationale document. The actual parameters are the values
435 /// supplied at the current instantiation of the Class being evaluated.
436 FailureOr<EvaluatorValuePtr>
437 evaluateValue(Value value, ActualParameters actualParams, Location loc);
438
439 /// Evaluator dispatch functions for the small expression grammar.
440 FailureOr<EvaluatorValuePtr> evaluateParameter(BlockArgument formalParam,
441 ActualParameters actualParams,
442 Location loc);
443
444 FailureOr<EvaluatorValuePtr>
445 evaluateConstant(ConstantOp op, ActualParameters actualParams, Location loc);
446
447 /// Instantiate an Object with its class name and actual parameters.
448 FailureOr<EvaluatorValuePtr>
449 evaluateObjectInstance(StringAttr className, ActualParameters actualParams,
450 Location loc, ObjectKey instanceKey = {});
451 FailureOr<EvaluatorValuePtr>
452 evaluateObjectInstance(ObjectOp op, ActualParameters actualParams);
453 FailureOr<EvaluatorValuePtr>
454 evaluateElaboratedObject(ElaboratedObjectOp op, ActualParameters actualParams,
455 Location loc);
456 FailureOr<EvaluatorValuePtr>
457 evaluateObjectField(ObjectFieldOp op, ActualParameters actualParams,
458 Location loc);
459 FailureOr<EvaluatorValuePtr> evaluateListCreate(ListCreateOp op,
460 ActualParameters actualParams,
461 Location loc);
462 FailureOr<EvaluatorValuePtr> evaluateListConcat(ListConcatOp op,
463 ActualParameters actualParams,
464 Location loc);
465 FailureOr<EvaluatorValuePtr>
466 evaluateIntegerBinary(IntegerBinaryOp op, ActualParameters actualParams,
467 Location loc);
468 FailureOr<EvaluatorValuePtr>
469 evaluateStringConcat(StringConcatOp op, ActualParameters actualParams,
470 Location loc);
471 FailureOr<EvaluatorValuePtr>
472 evaluateBinaryEquality(BinaryEqualityOp op, ActualParameters actualParams,
473 Location loc);
474 FailureOr<evaluator::EvaluatorValuePtr>
475 evaluateBasePathCreate(FrozenBasePathCreateOp op,
476 ActualParameters actualParams, Location loc);
477 FailureOr<evaluator::EvaluatorValuePtr>
478 evaluatePathCreate(FrozenPathCreateOp op, ActualParameters actualParams,
479 Location loc);
480 FailureOr<evaluator::EvaluatorValuePtr>
481 evaluateEmptyPath(FrozenEmptyPathOp op, ActualParameters actualParams,
482 Location loc);
483 FailureOr<evaluator::EvaluatorValuePtr>
484 evaluateUnknownValue(UnknownValueOp op, Location loc);
485
486 LogicalResult evaluatePropertyAssert(PropertyAssertOp op,
487 ActualParameters actualParams);
488
489 FailureOr<evaluator::EvaluatorValuePtr> createUnknownValue(Type type,
490 Location loc);
491
492 FailureOr<ActualParameters>
493 createParametersFromOperands(ValueRange range, ActualParameters actualParams,
494 Location loc);
495
496 /// The symbol table for the IR module the Evaluator was constructed with.
497 /// Used to look up class definitions.
498 SymbolTable symbolTable;
499
500 /// This uniquely stores vectors that represent parameters.
501 SmallVector<
502 std::unique_ptr<SmallVector<std::shared_ptr<evaluator::EvaluatorValue>>>>
504
505 /// Worklists that track values which need to be fully evaluated.
506 /// We use two worklists to detect cycles: process all items from one,
507 /// and if any become fully evaluated, swap and continue.
508 std::vector<ObjectKey> worklist;
509 std::vector<ObjectKey> nextWorklist;
510
511 /// A queue of pending property assertions to be evaluated after the worklist
512 /// is fully drained. Each entry is a (PropertyAssertOp, ActualParameters)
513 /// pair. Property assertions are deferred because their operands may be
514 /// ReferenceValues that are not yet resolved when the class body is first
515 /// processed.
516 std::queue<std::pair<PropertyAssertOp, ActualParameters>> pendingAsserts;
517
518 /// Evaluator value storage. Return an evaluator value for the given
519 /// instantiation context (a pair of Value and parameters).
520 DenseMap<ObjectKey, std::shared_ptr<evaluator::EvaluatorValue>> objects;
521
522 /// Counter for fully evaluated nodes.
524
525#ifndef NDEBUG
526 /// Current nesting depth for debug output indentation.
527 unsigned debugNesting = 0;
528
529 /// RAII helper to increment/decrement debugNesting.
531 unsigned &depth;
532 DebugNesting(unsigned &depth) : depth(depth) { ++depth; }
534 };
535
536 raw_ostream &dbgs(unsigned extra = 0) {
537 return llvm::dbgs().indent(debugNesting * 2 + extra * 2);
538 }
539
540 llvm::indent indent(unsigned extra = 0) {
541 return llvm::indent(debugNesting, 2) + extra;
542 }
543#endif
544};
545
546/// Helper to enable printing objects in Diagnostics.
547static inline mlir::Diagnostic &
548operator<<(mlir::Diagnostic &diag,
549 const evaluator::EvaluatorValue &evaluatorValue) {
550 if (auto *attr = llvm::dyn_cast<evaluator::AttributeValue>(&evaluatorValue))
551 diag << attr->getAttr();
552 else if (auto *object =
553 llvm::dyn_cast<evaluator::ObjectValue>(&evaluatorValue))
554 diag << "Object(" << object->getType() << ")";
555 else if (auto *list = llvm::dyn_cast<evaluator::ListValue>(&evaluatorValue))
556 diag << "List(" << list->getType() << ")";
557 else if (auto *ref =
558 llvm::dyn_cast<evaluator::ReferenceValue>(&evaluatorValue))
559 diag << "Reference(" << ref->getValueType() << ")";
560 else if (llvm::isa<evaluator::BasePathValue>(&evaluatorValue))
561 diag << "BasePath()";
562 else if (llvm::isa<evaluator::PathValue>(&evaluatorValue))
563 diag << "Path()";
564 else
565 assert(false && "unhandled evaluator value");
566
567 // Add unknown marker if the value is unknown
568 if (evaluatorValue.isUnknown())
569 diag << " [unknown]";
570 return diag;
571}
572
573/// Helper to enable printing objects in Diagnostics.
574static inline mlir::Diagnostic &
575operator<<(mlir::Diagnostic &diag, const EvaluatorValuePtr &evaluatorValue) {
576 return diag << *evaluatorValue.get();
577}
578
579#ifndef NDEBUG
580/// Helper to enable printing objects to raw_ostream (e.g., llvm::dbgs()).
581/// Delegates to the Diagnostic overload via an intermediate string.
582static inline llvm::raw_ostream &
583operator<<(llvm::raw_ostream &os,
584 const evaluator::EvaluatorValue &evaluatorValue) {
585 std::string buf;
586 llvm::raw_string_ostream ss(buf);
587 mlir::Diagnostic diag(UnknownLoc::get(evaluatorValue.getContext()),
588 mlir::DiagnosticSeverity::Note);
589 diag << evaluatorValue;
590 ss << diag;
591 return os << ss.str();
592}
593
594static inline llvm::raw_ostream &
595operator<<(llvm::raw_ostream &os, const EvaluatorValuePtr &evaluatorValue) {
596 if (evaluatorValue)
597 return os << *evaluatorValue.get();
598 return os << "<null>";
599}
600#endif // NDEBUG
601
602} // namespace om
603} // namespace circt
604
605#endif // CIRCT_DIALECT_OM_EVALUATOR_EVALUATOR_H
assert(baseType &&"element must be base type")
static std::unique_ptr< Context > context
An Evaluator, which is constructed with an IR module and can instantiate Objects.
Definition Evaluator.h:385
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)
SymbolTable symbolTable
The symbol table for the IR module the Evaluator was constructed with.
Definition Evaluator.h:498
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.
FailureOr< EvaluatorValuePtr > evaluateStringConcat(StringConcatOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for String concatenation.
void attachCounter(evaluator::EvaluatorValuePtr &value)
Attach the evaluation counter to a newly created value.
Definition Evaluator.h:419
LogicalResult evaluatePropertyAssert(PropertyAssertOp op, ActualParameters actualParams)
Evaluator dispatch function for property assertions.
mlir::ModuleOp getModule()
Get the Module this Evaluator is built from.
FailureOr< EvaluatorValuePtr > evaluateObjectField(ObjectFieldOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for Object fields.
FailureOr< evaluator::EvaluatorValuePtr > createUnknownValue(Type type, Location loc)
Create an unknown value of the specified type.
SmallVector< std::unique_ptr< SmallVector< std::shared_ptr< evaluator::EvaluatorValue > > > > actualParametersBuffers
This uniquely stores vectors that represent parameters.
Definition Evaluator.h:503
std::vector< ObjectKey > nextWorklist
Definition Evaluator.h:509
bool isFullyEvaluated(Value value, ActualParameters key)
Definition Evaluator.h:409
FailureOr< EvaluatorValuePtr > allocateObjectInstance(StringAttr clasName, ActualParameters actualParams)
FailureOr< EvaluatorValuePtr > evaluateIntegerBinary(IntegerBinaryOp op, ActualParameters actualParams, Location loc)
llvm::indent indent(unsigned extra=0)
Definition Evaluator.h:540
unsigned debugNesting
Current nesting depth for debug output indentation.
Definition Evaluator.h:527
FailureOr< evaluator::EvaluatorValuePtr > evaluateUnknownValue(UnknownValueOp op, Location loc)
Evaluate an unknown value.
raw_ostream & dbgs(unsigned extra=0)
Definition Evaluator.h:536
uint64_t fullyEvaluatedCount
Counter for fully evaluated nodes.
Definition Evaluator.h:523
FailureOr< evaluator::EvaluatorValuePtr > instantiate(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
Instantiate an Object with its class name and actual parameters.
FailureOr< EvaluatorValuePtr > getOrCreateValue(Value value, ActualParameters actualParams, Location loc)
SmallVectorImpl< std::shared_ptr< evaluator::EvaluatorValue > > * ActualParameters
Definition Evaluator.h:401
DenseMap< ObjectKey, std::shared_ptr< evaluator::EvaluatorValue > > objects
Evaluator value storage.
Definition Evaluator.h:520
FailureOr< evaluator::EvaluatorValuePtr > instantiateImpl(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
FailureOr< EvaluatorValuePtr > evaluateBinaryEquality(BinaryEqualityOp op, ActualParameters actualParams, Location loc)
FailureOr< EvaluatorValuePtr > evaluateListCreate(ListCreateOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for List creation.
FailureOr< EvaluatorValuePtr > evaluateListConcat(ListConcatOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for List concatenation.
std::pair< Value, ActualParameters > ObjectKey
Definition Evaluator.h:403
std::vector< ObjectKey > worklist
Worklists that track values which need to be fully evaluated.
Definition Evaluator.h:508
FailureOr< EvaluatorValuePtr > evaluateParameter(BlockArgument formalParam, ActualParameters actualParams, Location loc)
Evaluator dispatch functions for the small expression grammar.
FailureOr< EvaluatorValuePtr > evaluateObjectInstance(StringAttr className, ActualParameters actualParams, Location loc, ObjectKey instanceKey={})
Instantiate an Object with its class name and actual parameters.
uint64_t getFullyEvaluatedCount() const
Get the number of fully evaluated nodes tracked by this evaluator.
Definition Evaluator.h:406
FailureOr< evaluator::EvaluatorValuePtr > evaluatePathCreate(FrozenPathCreateOp op, ActualParameters actualParams, Location loc)
FailureOr< ActualParameters > createParametersFromOperands(ValueRange range, ActualParameters actualParams, Location loc)
Evaluator dispatch function for Object instances.
bool isFullyEvaluated(ObjectKey key)
Definition Evaluator.h:413
std::queue< std::pair< PropertyAssertOp, ActualParameters > > pendingAsserts
A queue of pending property assertions to be evaluated after the worklist is fully drained.
Definition Evaluator.h:516
Values which can be directly representable by MLIR attributes.
Definition Evaluator.h:161
LogicalResult setAttr(Attribute attr)
friend std::shared_ptr< EvaluatorValue > get(Attribute attr, LocationAttr loc)
static bool classof(const EvaluatorValue *e)
Definition Evaluator.h:168
AttributeValue(PrivateTag, Attribute attr, Location loc)
Definition Evaluator.h:190
friend std::shared_ptr< EvaluatorValue > get(Type type, LocationAttr loc)
AttributeValue(PrivateTag, Type type, Location loc)
Definition Evaluator.h:197
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition Evaluator.h:327
LogicalResult finalizeImpl()
Finalize the evaluator value.
Definition Evaluator.h:324
void setBasepath(const BasePathValue &basepath)
Set the basepath which this path is relative to.
BasePathValue(om::PathAttr path, Location loc)
Create a path value representing a basepath.
Base class for evaluator runtime values.
Definition Evaluator.h:49
EvaluatorValue(MLIRContext *ctx, Kind kind, Location loc)
Definition Evaluator.h:53
void markUnknown()
Mark this value as unknown.
Definition Evaluator.h:83
MLIRContext * getContext()
Return the associated MLIR context.
Definition Evaluator.h:90
void setFullyEvaluatedCounter(uint64_t *counter)
Set a counter to increment when this value becomes fully evaluated.
Definition Evaluator.h:70
bool isUnknown() const
Return true if the value is unknown (has unknown in its fan-in).
Definition Evaluator.h:77
MLIRContext * getContext() const
Definition Evaluator.h:56
A List which contains variadic length of elements with the same type.
Definition Evaluator.h:222
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition Evaluator.h:249
const auto & getElements() const
Definition Evaluator.h:243
ListValue(om::ListType type, Location loc)
Definition Evaluator.h:240
void setElements(SmallVector< EvaluatorValuePtr > newElements)
Definition Evaluator.h:231
SmallVector< EvaluatorValuePtr > elements
Definition Evaluator.h:255
ListValue(om::ListType type, SmallVector< EvaluatorValuePtr > elements, Location loc)
Definition Evaluator.h:224
om::ListType getListType() const
Return the type of the value, which is a ListType.
Definition Evaluator.h:246
A composite Object, which has a type and fields.
Definition Evaluator.h:259
om::ClassType getObjectType() const
Return the type of the value, which is a ClassType.
Definition Evaluator.h:280
FailureOr< EvaluatorValuePtr > getField(StringAttr field)
Get a field of the Object by name.
const auto & getFields() const
Definition Evaluator.h:272
FailureOr< EvaluatorValuePtr > getField(StringRef field)
Definition Evaluator.h:295
ArrayAttr getFieldNames()
Get all the field names of the Object.
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition Evaluator.h:289
void setFields(llvm::SmallDenseMap< StringAttr, EvaluatorValuePtr > newFields)
Definition Evaluator.h:274
ObjectValue(om::ClassLike cls, Location loc)
Definition Evaluator.h:268
om::ClassLike getClassOp() const
Definition Evaluator.h:271
llvm::SmallDenseMap< StringAttr, EvaluatorValuePtr > fields
Definition Evaluator.h:307
ObjectValue(om::ClassLike cls, ObjectFields fields, Location loc)
Definition Evaluator.h:261
StringAttr getModule() const
Definition Evaluator.h:348
StringAttr StringAttr ref
Definition Evaluator.h:370
om::TargetKindAttr getTargetKind() const
Definition Evaluator.h:344
StringAttr getField() const
Definition Evaluator.h:352
om::TargetKindAttr targetKind
Definition Evaluator.h:367
void setBasepath(const BasePathValue &basepath)
om::PathAttr getPath() const
Definition Evaluator.h:346
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition Evaluator.h:362
static PathValue getEmptyPath(Location loc)
StringAttr getRef() const
Definition Evaluator.h:350
Values which can be used as pointers to different values.
Definition Evaluator.h:121
EvaluatorValuePtr getValue() const
Definition Evaluator.h:133
static bool classof(const EvaluatorValue *e)
Definition Evaluator.h:128
ReferenceValue(Type type, Location loc)
Definition Evaluator.h:123
FailureOr< EvaluatorValuePtr > getStrippedValue() const
Definition Evaluator.h:143
void setValue(EvaluatorValuePtr newValue)
Definition Evaluator.h:134
static LogicalResult finalizeEvaluatorValue(EvaluatorValuePtr &value)
Definition Evaluator.h:209
std::shared_ptr< EvaluatorValue > EvaluatorValuePtr
A value of an object in memory.
Definition Evaluator.h:39
evaluator::EvaluatorValuePtr EvaluatorValuePtr
Definition Evaluator.h:377
static mlir::Diagnostic & operator<<(mlir::Diagnostic &diag, const evaluator::EvaluatorValue &evaluatorValue)
Helper to enable printing objects in Diagnostics.
Definition Evaluator.h:548
SmallVector< EvaluatorValuePtr > getEvaluatorValuesFromAttributes(MLIRContext *context, ArrayRef< Attribute > attributes)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition om.py:1
RAII helper to increment/decrement debugNesting.
Definition Evaluator.h:530