CIRCT  20.0.0git
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 
16 #include "circt/Dialect/OM/OMOps.h"
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 
27 #include <queue>
28 #include <utility>
29 
30 namespace circt {
31 namespace om {
32 
33 namespace evaluator {
34 struct EvaluatorValue;
35 
36 /// A value of an object in memory. It is either a composite Object, or a
37 /// primitive Attribute. Further refinement is expected.
38 using EvaluatorValuePtr = std::shared_ptr<EvaluatorValue>;
39 
40 /// The fields of a composite Object, currently represented as a map. Further
41 /// refinement is expected.
43 
44 /// Base class for evaluator runtime values.
45 /// Enables the shared_from_this functionality so Evaluator Value pointers can
46 /// be passed through the CAPI and unwrapped back into C++ smart pointers with
47 /// the appropriate reference count.
48 struct EvaluatorValue : std::enable_shared_from_this<EvaluatorValue> {
49  // Implement LLVM RTTI.
50  enum class Kind { Attr, Object, List, Tuple, Map, Reference, BasePath, Path };
51  EvaluatorValue(MLIRContext *ctx, Kind kind, Location loc)
52  : kind(kind), ctx(ctx), loc(loc) {}
53  Kind getKind() const { return kind; }
54  MLIRContext *getContext() const { return ctx; }
55 
56  // Return true the value is fully evaluated.
57  bool isFullyEvaluated() const { return fullyEvaluated; }
59  assert(!fullyEvaluated && "should not mark twice");
60  fullyEvaluated = true;
61  }
62 
63  /// Return the associated MLIR context.
64  MLIRContext *getContext() { return ctx; }
65 
66  // Return a MLIR type which the value represents.
67  Type getType() const;
68 
69  // Finalize the evaluator value. Strip intermidiate reference values.
70  LogicalResult finalize();
71 
72  // Return the Location associated with the Value.
73  Location getLoc() const { return loc; }
74  // Set the Location associated with the Value.
75  void setLoc(Location l) { loc = l; }
76  // Set the Location, if it is unknown.
77  void setLocIfUnknown(Location l) {
78  if (isa<UnknownLoc>(loc))
79  loc = l;
80  }
81 
82 private:
83  const Kind kind;
84  MLIRContext *ctx;
85  Location loc;
86  bool fullyEvaluated = false;
87  bool finalized = false;
88 };
89 
90 /// Values which can be used as pointers to different values.
91 /// ReferenceValue is replaced with its element and erased at the end of
92 /// evaluation.
94  ReferenceValue(Type type, Location loc)
95  : EvaluatorValue(type.getContext(), Kind::Reference, loc), value(nullptr),
96  type(type) {}
97 
98  // Implement LLVM RTTI.
99  static bool classof(const EvaluatorValue *e) {
100  return e->getKind() == Kind::Reference;
101  }
102 
103  Type getValueType() const { return type; }
104  EvaluatorValuePtr getValue() const { return value; }
105  void setValue(EvaluatorValuePtr newValue) {
106  value = std::move(newValue);
108  }
109 
110  // Finalize the value.
111  LogicalResult finalizeImpl();
112 
113  // Return the first non-reference value that is reachable from the reference.
114  FailureOr<EvaluatorValuePtr> getStrippedValue() const {
115  llvm::SmallPtrSet<ReferenceValue *, 4> visited;
116  auto currentValue = value;
117  while (auto *v = dyn_cast<ReferenceValue>(currentValue.get())) {
118  // Detect a cycle.
119  if (!visited.insert(v).second)
120  return failure();
121  currentValue = v->getValue();
122  }
123  return success(currentValue);
124  }
125 
126 private:
128  Type type;
129 };
130 
131 /// Values which can be directly representable by MLIR attributes.
133  AttributeValue(Attribute attr)
134  : AttributeValue(attr, mlir::UnknownLoc::get(attr.getContext())) {}
135  AttributeValue(Attribute attr, Location loc)
136  : EvaluatorValue(attr.getContext(), Kind::Attr, loc), attr(attr),
137  type(cast<TypedAttr>(attr).getType()) {
139  }
140 
141  // Constructors for partially evaluated AttributeValue.
143  : AttributeValue(mlir::UnknownLoc::get(type.getContext())) {}
144  AttributeValue(Type type, Location loc)
145  : EvaluatorValue(type.getContext(), Kind::Attr, loc), type(type) {}
146 
147  Attribute getAttr() const { return attr; }
148  template <typename AttrTy>
149  AttrTy getAs() const {
150  return dyn_cast<AttrTy>(attr);
151  }
152  static bool classof(const EvaluatorValue *e) {
153  return e->getKind() == Kind::Attr;
154  }
155 
156  // Set Attribute for partially evaluated case.
157  LogicalResult setAttr(Attribute attr);
158 
159  // Finalize the value.
160  LogicalResult finalizeImpl();
161 
162  Type getType() const { return type; }
163 
164 private:
165  Attribute attr = {};
166  Type type;
167 };
168 
169 // This perform finalization to `value`.
170 static inline LogicalResult finalizeEvaluatorValue(EvaluatorValuePtr &value) {
171  if (failed(value->finalize()))
172  return failure();
173  if (auto *ref = llvm::dyn_cast<ReferenceValue>(value.get())) {
174  auto v = ref->getStrippedValue();
175  if (failed(v))
176  return v;
177  value = v.value();
178  }
179  return success();
180 }
181 
182 /// A List which contains variadic length of elements with the same type.
184  ListValue(om::ListType type, SmallVector<EvaluatorValuePtr> elements,
185  Location loc)
186  : EvaluatorValue(type.getContext(), Kind::List, loc), type(type),
187  elements(std::move(elements)) {
189  }
190 
191  void setElements(SmallVector<EvaluatorValuePtr> newElements) {
192  elements = std::move(newElements);
194  }
195 
196  // Finalize the value.
197  LogicalResult finalizeImpl();
198 
199  // Partially evaluated value.
200  ListValue(om::ListType type, Location loc)
201  : EvaluatorValue(type.getContext(), Kind::List, loc), type(type) {}
202 
203  const auto &getElements() const { return elements; }
204 
205  /// Return the type of the value, which is a ListType.
206  om::ListType getListType() const { return type; }
207 
208  /// Implement LLVM RTTI.
209  static bool classof(const EvaluatorValue *e) {
210  return e->getKind() == Kind::List;
211  }
212 
213 private:
214  om::ListType type;
215  SmallVector<EvaluatorValuePtr> elements;
216 };
217 
218 /// A Map value.
220  MapValue(om::MapType type, DenseMap<Attribute, EvaluatorValuePtr> elements,
221  Location loc)
223  elements(std::move(elements)) {
225  }
226 
227  // Partially evaluated value.
228  MapValue(om::MapType type, Location loc)
229  : EvaluatorValue(type.getContext(), Kind::Map, loc), type(type) {}
230 
231  const auto &getElements() const { return elements; }
232  void setElements(DenseMap<Attribute, EvaluatorValuePtr> newElements) {
233  elements = std::move(newElements);
235  }
236 
237  // Finalize the evaluator value.
238  LogicalResult finalizeImpl();
239 
240  /// Return the type of the value, which is a MapType.
241  om::MapType getMapType() const { return type; }
242 
243  /// Return an array of keys in the ascending order.
244  ArrayAttr getKeys();
245 
246  /// Implement LLVM RTTI.
247  static bool classof(const EvaluatorValue *e) {
248  return e->getKind() == Kind::Map;
249  }
250 
251 private:
252  om::MapType type;
253  DenseMap<Attribute, EvaluatorValuePtr> elements;
254 };
255 
256 /// A composite Object, which has a type and fields.
258  ObjectValue(om::ClassOp cls, ObjectFields fields, Location loc)
260  fields(std::move(fields)) {
262  }
263 
264  // Partially evaluated value.
265  ObjectValue(om::ClassOp cls, Location loc)
267 
268  om::ClassOp getClassOp() const { return cls; }
269  const auto &getFields() const { return fields; }
270 
272  fields = std::move(newFields);
274  }
275 
276  /// Return the type of the value, which is a ClassType.
277  om::ClassType getObjectType() const {
278  auto clsConst = const_cast<ClassOp &>(cls);
279  return ClassType::get(clsConst.getContext(),
280  FlatSymbolRefAttr::get(clsConst.getNameAttr()));
281  }
282 
283  Type getType() const { return getObjectType(); }
284 
285  /// Implement LLVM RTTI.
286  static bool classof(const EvaluatorValue *e) {
287  return e->getKind() == Kind::Object;
288  }
289 
290  /// Get a field of the Object by name.
291  FailureOr<EvaluatorValuePtr> getField(StringAttr field);
292  FailureOr<EvaluatorValuePtr> getField(StringRef field) {
293  return getField(StringAttr::get(getContext(), field));
294  }
295 
296  /// Get all the field names of the Object.
297  ArrayAttr getFieldNames();
298 
299  // Finalize the evaluator value.
300  LogicalResult finalizeImpl();
301 
302 private:
303  om::ClassOp cls;
305 };
306 
307 /// Tuple values.
309  using TupleElements = llvm::SmallVector<EvaluatorValuePtr>;
310  TupleValue(TupleType type, TupleElements tupleElements, Location loc)
311  : EvaluatorValue(type.getContext(), Kind::Tuple, loc), type(type),
312  elements(std::move(tupleElements)) {
314  }
315 
316  // Partially evaluated value.
317  TupleValue(TupleType type, Location loc)
318  : EvaluatorValue(type.getContext(), Kind::Tuple, loc), type(type) {}
319 
320  void setElements(TupleElements newElements) {
321  elements = std::move(newElements);
323  }
324 
325  LogicalResult finalizeImpl() {
326  for (auto &&value : elements)
327  if (failed(finalizeEvaluatorValue(value)))
328  return failure();
329 
330  return success();
331  }
332  /// Implement LLVM RTTI.
333  static bool classof(const EvaluatorValue *e) {
334  return e->getKind() == Kind::Tuple;
335  }
336 
337  /// Return the type of the value, which is a TupleType.
338  TupleType getTupleType() const { return type; }
339 
340  const TupleElements &getElements() const { return elements; }
341 
342 private:
343  TupleType type;
345 };
346 
347 /// A Basepath value.
349  BasePathValue(MLIRContext *context);
350 
351  /// Create a path value representing a basepath.
352  BasePathValue(om::PathAttr path, Location loc);
353 
354  om::PathAttr getPath() const;
355 
356  /// Set the basepath which this path is relative to.
357  void setBasepath(const BasePathValue &basepath);
358 
359  /// Finalize the evaluator value.
360  LogicalResult finalizeImpl() { return success(); }
361 
362  /// Implement LLVM RTTI.
363  static bool classof(const EvaluatorValue *e) {
364  return e->getKind() == Kind::BasePath;
365  }
366 
367 private:
368  om::PathAttr path;
369 };
370 
371 /// A Path value.
373  /// Create a path value representing a regular path.
374  PathValue(om::TargetKindAttr targetKind, om::PathAttr path, StringAttr module,
375  StringAttr ref, StringAttr field, Location loc);
376 
377  static PathValue getEmptyPath(Location loc);
378 
379  om::TargetKindAttr getTargetKind() const { return targetKind; }
380 
381  om::PathAttr getPath() const { return path; }
382 
383  StringAttr getModule() const { return module; }
384 
385  StringAttr getRef() const { return ref; }
386 
387  StringAttr getField() const { return field; }
388 
389  StringAttr getAsString() const;
390 
391  void setBasepath(const BasePathValue &basepath);
392 
393  // Finalize the evaluator value.
394  LogicalResult finalizeImpl() { return success(); }
395 
396  /// Implement LLVM RTTI.
397  static bool classof(const EvaluatorValue *e) {
398  return e->getKind() == Kind::Path;
399  }
400 
401 private:
402  om::TargetKindAttr targetKind;
403  om::PathAttr path;
404  StringAttr module;
405  StringAttr ref;
406  StringAttr field;
407 };
408 
409 } // namespace evaluator
410 
413 
414 SmallVector<EvaluatorValuePtr>
415 getEvaluatorValuesFromAttributes(MLIRContext *context,
416  ArrayRef<Attribute> attributes);
417 
418 /// An Evaluator, which is constructed with an IR module and can instantiate
419 /// Objects. Further refinement is expected.
420 struct Evaluator {
421  /// Construct an Evaluator with an IR module.
422  Evaluator(ModuleOp mod);
423 
424  /// Instantiate an Object with its class name and actual parameters.
425  FailureOr<evaluator::EvaluatorValuePtr>
426  instantiate(StringAttr className, ArrayRef<EvaluatorValuePtr> actualParams);
427 
428  /// Get the Module this Evaluator is built from.
429  mlir::ModuleOp getModule();
430 
431  FailureOr<evaluator::EvaluatorValuePtr>
432  getPartiallyEvaluatedValue(Type type, Location loc);
433 
435  SmallVectorImpl<std::shared_ptr<evaluator::EvaluatorValue>> *;
436 
437  using ObjectKey = std::pair<Value, ActualParameters>;
438 
439 private:
440  bool isFullyEvaluated(Value value, ActualParameters key) {
441  return isFullyEvaluated({value, key});
442  }
443 
445  auto val = objects.lookup(key);
446  return val && val->isFullyEvaluated();
447  }
448 
449  FailureOr<EvaluatorValuePtr>
450  getOrCreateValue(Value value, ActualParameters actualParams, Location loc);
451  FailureOr<EvaluatorValuePtr>
452  allocateObjectInstance(StringAttr clasName, ActualParameters actualParams);
453 
454  /// Evaluate a Value in a Class body according to the small expression grammar
455  /// described in the rationale document. The actual parameters are the values
456  /// supplied at the current instantiation of the Class being evaluated.
457  FailureOr<EvaluatorValuePtr>
458  evaluateValue(Value value, ActualParameters actualParams, Location loc);
459 
460  /// Evaluator dispatch functions for the small expression grammar.
461  FailureOr<EvaluatorValuePtr> evaluateParameter(BlockArgument formalParam,
462  ActualParameters actualParams,
463  Location loc);
464 
465  FailureOr<EvaluatorValuePtr>
466  evaluateConstant(ConstantOp op, ActualParameters actualParams, Location loc);
467 
468  FailureOr<EvaluatorValuePtr>
469  evaluateIntegerBinaryArithmetic(IntegerBinaryArithmeticOp op,
470  ActualParameters actualParams, Location loc);
471 
472  /// Instantiate an Object with its class name and actual parameters.
473  FailureOr<EvaluatorValuePtr>
474  evaluateObjectInstance(StringAttr className, ActualParameters actualParams,
475  Location loc, ObjectKey instanceKey = {});
476  FailureOr<EvaluatorValuePtr>
477  evaluateObjectInstance(ObjectOp op, ActualParameters actualParams);
478  FailureOr<EvaluatorValuePtr>
479  evaluateObjectField(ObjectFieldOp op, ActualParameters actualParams,
480  Location loc);
481  FailureOr<EvaluatorValuePtr> evaluateListCreate(ListCreateOp op,
482  ActualParameters actualParams,
483  Location loc);
484  FailureOr<EvaluatorValuePtr> evaluateListConcat(ListConcatOp op,
485  ActualParameters actualParams,
486  Location loc);
487  FailureOr<EvaluatorValuePtr>
488  evaluateTupleCreate(TupleCreateOp op, ActualParameters actualParams,
489  Location loc);
490  FailureOr<EvaluatorValuePtr>
491  evaluateTupleGet(TupleGetOp op, ActualParameters actualParams, Location loc);
492  FailureOr<evaluator::EvaluatorValuePtr>
493  evaluateMapCreate(MapCreateOp op, ActualParameters actualParams,
494  Location loc);
495  FailureOr<evaluator::EvaluatorValuePtr>
496  evaluateBasePathCreate(FrozenBasePathCreateOp op,
497  ActualParameters actualParams, Location loc);
498  FailureOr<evaluator::EvaluatorValuePtr>
499  evaluatePathCreate(FrozenPathCreateOp op, ActualParameters actualParams,
500  Location loc);
501  FailureOr<evaluator::EvaluatorValuePtr>
502  evaluateEmptyPath(FrozenEmptyPathOp op, ActualParameters actualParams,
503  Location loc);
504 
505  FailureOr<ActualParameters>
506  createParametersFromOperands(ValueRange range, ActualParameters actualParams,
507  Location loc);
508 
509  /// The symbol table for the IR module the Evaluator was constructed with.
510  /// Used to look up class definitions.
511  SymbolTable symbolTable;
512 
513  /// This uniquely stores vectors that represent parameters.
514  SmallVector<
515  std::unique_ptr<SmallVector<std::shared_ptr<evaluator::EvaluatorValue>>>>
517 
518  /// A worklist that tracks values which needs to be fully evaluated.
519  std::queue<ObjectKey> worklist;
520 
521  /// Evaluator value storage. Return an evaluator value for the given
522  /// instantiation context (a pair of Value and parameters).
523  DenseMap<ObjectKey, std::shared_ptr<evaluator::EvaluatorValue>> objects;
524 };
525 
526 /// Helper to enable printing objects in Diagnostics.
527 static inline mlir::Diagnostic &
528 operator<<(mlir::Diagnostic &diag,
529  const evaluator::EvaluatorValue &evaluatorValue) {
530  if (auto *attr = llvm::dyn_cast<evaluator::AttributeValue>(&evaluatorValue))
531  diag << attr->getAttr();
532  else if (auto *object =
533  llvm::dyn_cast<evaluator::ObjectValue>(&evaluatorValue))
534  diag << "Object(" << object->getType() << ")";
535  else if (auto *list = llvm::dyn_cast<evaluator::ListValue>(&evaluatorValue))
536  diag << "List(" << list->getType() << ")";
537  else if (auto *map = llvm::dyn_cast<evaluator::MapValue>(&evaluatorValue))
538  diag << "Map(" << map->getType() << ")";
539  else if (llvm::isa<evaluator::BasePathValue>(&evaluatorValue))
540  diag << "BasePath()";
541  else if (llvm::isa<evaluator::PathValue>(&evaluatorValue))
542  diag << "Path()";
543  else
544  assert(false && "unhandled evaluator value");
545  return diag;
546 }
547 
548 /// Helper to enable printing objects in Diagnostics.
549 static inline mlir::Diagnostic &
550 operator<<(mlir::Diagnostic &diag, const EvaluatorValuePtr &evaluatorValue) {
551  return diag << *evaluatorValue.get();
552 }
553 
554 } // namespace om
555 } // namespace circt
556 
557 #endif // CIRCT_DIALECT_OM_EVALUATOR_EVALUATOR_H
assert(baseType &&"element must be base type")
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
static LogicalResult finalizeEvaluatorValue(EvaluatorValuePtr &value)
Definition: Evaluator.h:170
std::shared_ptr< EvaluatorValue > EvaluatorValuePtr
A value of an object in memory.
Definition: Evaluator.h:38
evaluator::EvaluatorValuePtr EvaluatorValuePtr
Definition: Evaluator.h:412
static mlir::Diagnostic & operator<<(mlir::Diagnostic &diag, const evaluator::EvaluatorValue &evaluatorValue)
Helper to enable printing objects in Diagnostics.
Definition: Evaluator.h:528
SmallVector< EvaluatorValuePtr > getEvaluatorValuesFromAttributes(MLIRContext *context, ArrayRef< Attribute > attributes)
Definition: Evaluator.cpp:34
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: om.py:1
An Evaluator, which is constructed with an IR module and can instantiate Objects.
Definition: Evaluator.h:420
FailureOr< evaluator::EvaluatorValuePtr > evaluateBasePathCreate(FrozenBasePathCreateOp op, ActualParameters actualParams, Location loc)
Definition: Evaluator.cpp:693
FailureOr< evaluator::EvaluatorValuePtr > evaluateEmptyPath(FrozenEmptyPathOp op, ActualParameters actualParams, Location loc)
Definition: Evaluator.cpp:726
SymbolTable symbolTable
The symbol table for the IR module the Evaluator was constructed with.
Definition: Evaluator.h:511
FailureOr< evaluator::EvaluatorValuePtr > getPartiallyEvaluatedValue(Type type, Location loc)
Definition: Evaluator.cpp:72
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...
Definition: Evaluator.cpp:336
FailureOr< EvaluatorValuePtr > evaluateConstant(ConstantOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for constants.
Definition: Evaluator.cpp:408
FailureOr< EvaluatorValuePtr > evaluateIntegerBinaryArithmetic(IntegerBinaryArithmeticOp op, ActualParameters actualParams, Location loc)
Definition: Evaluator.cpp:417
mlir::ModuleOp getModule()
Get the Module this Evaluator is built from.
Definition: Evaluator.cpp:29
FailureOr< EvaluatorValuePtr > evaluateObjectField(ObjectFieldOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for Object fields.
Definition: Evaluator.cpp:532
SmallVector< std::unique_ptr< SmallVector< std::shared_ptr< evaluator::EvaluatorValue > > > > actualParametersBuffers
This uniquely stores vectors that represent parameters.
Definition: Evaluator.h:516
bool isFullyEvaluated(Value value, ActualParameters key)
Definition: Evaluator.h:440
std::queue< ObjectKey > worklist
A worklist that tracks values which needs to be fully evaluated.
Definition: Evaluator.h:519
Evaluator(ModuleOp mod)
Construct an Evaluator with an IR module.
Definition: Evaluator.cpp:26
FailureOr< evaluator::EvaluatorValuePtr > evaluateMapCreate(MapCreateOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for Map creation.
Definition: Evaluator.cpp:664
FailureOr< evaluator::EvaluatorValuePtr > instantiate(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
Instantiate an Object with its class name and actual parameters.
Definition: Evaluator.cpp:291
FailureOr< EvaluatorValuePtr > getOrCreateValue(Value value, ActualParameters actualParams, Location loc)
Definition: Evaluator.cpp:108
SmallVectorImpl< std::shared_ptr< evaluator::EvaluatorValue > > * ActualParameters
Definition: Evaluator.h:435
DenseMap< ObjectKey, std::shared_ptr< evaluator::EvaluatorValue > > objects
Evaluator value storage.
Definition: Evaluator.h:523
FailureOr< EvaluatorValuePtr > evaluateListCreate(ListCreateOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for List creation.
Definition: Evaluator.cpp:571
FailureOr< EvaluatorValuePtr > evaluateListConcat(ListConcatOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for List concatenation.
Definition: Evaluator.cpp:594
FailureOr< EvaluatorValuePtr > allocateObjectInstance(StringAttr clasName, ActualParameters actualParams)
std::pair< Value, ActualParameters > ObjectKey
Definition: Evaluator.h:437
FailureOr< EvaluatorValuePtr > evaluateParameter(BlockArgument formalParam, ActualParameters actualParams, Location loc)
Evaluator dispatch functions for the small expression grammar.
Definition: Evaluator.cpp:399
FailureOr< EvaluatorValuePtr > evaluateObjectInstance(StringAttr className, ActualParameters actualParams, Location loc, ObjectKey instanceKey={})
Instantiate an Object with its class name and actual parameters.
Definition: Evaluator.cpp:191
FailureOr< EvaluatorValuePtr > evaluateTupleGet(TupleGetOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for List creation.
Definition: Evaluator.cpp:652
FailureOr< EvaluatorValuePtr > evaluateTupleCreate(TupleCreateOp op, ActualParameters actualParams, Location loc)
Evaluator dispatch function for Tuple creation.
Definition: Evaluator.cpp:633
FailureOr< evaluator::EvaluatorValuePtr > evaluatePathCreate(FrozenPathCreateOp op, ActualParameters actualParams, Location loc)
Definition: Evaluator.cpp:710
FailureOr< ActualParameters > createParametersFromOperands(ValueRange range, ActualParameters actualParams, Location loc)
Evaluator dispatch function for Object instances.
Definition: Evaluator.cpp:496
bool isFullyEvaluated(ObjectKey key)
Definition: Evaluator.h:444
Values which can be directly representable by MLIR attributes.
Definition: Evaluator.h:132
LogicalResult setAttr(Attribute attr)
Definition: Evaluator.cpp:922
static bool classof(const EvaluatorValue *e)
Definition: Evaluator.h:152
AttributeValue(Attribute attr, Location loc)
Definition: Evaluator.h:135
AttributeValue(Type type, Location loc)
Definition: Evaluator.h:144
BasePathValue(MLIRContext *context)
Definition: Evaluator.cpp:825
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition: Evaluator.h:363
LogicalResult finalizeImpl()
Finalize the evaluator value.
Definition: Evaluator.h:360
void setBasepath(const BasePathValue &basepath)
Set the basepath which this path is relative to.
Definition: Evaluator.cpp:839
BasePathValue(om::PathAttr path, Location loc)
Create a path value representing a basepath.
Base class for evaluator runtime values.
Definition: Evaluator.h:48
EvaluatorValue(MLIRContext *ctx, Kind kind, Location loc)
Definition: Evaluator.h:51
MLIRContext * getContext() const
Definition: Evaluator.h:54
MLIRContext * getContext()
Return the associated MLIR context.
Definition: Evaluator.h:64
A List which contains variadic length of elements with the same type.
Definition: Evaluator.h:183
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition: Evaluator.h:209
ListValue(om::ListType type, Location loc)
Definition: Evaluator.h:200
void setElements(SmallVector< EvaluatorValuePtr > newElements)
Definition: Evaluator.h:191
SmallVector< EvaluatorValuePtr > elements
Definition: Evaluator.h:215
ListValue(om::ListType type, SmallVector< EvaluatorValuePtr > elements, Location loc)
Definition: Evaluator.h:184
const auto & getElements() const
Definition: Evaluator.h:203
om::ListType getListType() const
Return the type of the value, which is a ListType.
Definition: Evaluator.h:206
const auto & getElements() const
Definition: Evaluator.h:231
MapValue(om::MapType type, DenseMap< Attribute, EvaluatorValuePtr > elements, Location loc)
Definition: Evaluator.h:220
ArrayAttr getKeys()
Return an array of keys in the ascending order.
Definition: Evaluator.cpp:772
void setElements(DenseMap< Attribute, EvaluatorValuePtr > newElements)
Definition: Evaluator.h:232
MapValue(om::MapType type, Location loc)
Definition: Evaluator.h:228
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition: Evaluator.h:247
om::MapType getMapType() const
Return the type of the value, which is a MapType.
Definition: Evaluator.h:241
DenseMap< Attribute, EvaluatorValuePtr > elements
Definition: Evaluator.h:253
A composite Object, which has a type and fields.
Definition: Evaluator.h:257
const auto & getFields() const
Definition: Evaluator.h:269
om::ClassType getObjectType() const
Return the type of the value, which is a ClassType.
Definition: Evaluator.h:277
FailureOr< EvaluatorValuePtr > getField(StringAttr field)
Get a field of the Object by name.
Definition: Evaluator.cpp:738
ObjectValue(om::ClassOp cls, ObjectFields fields, Location loc)
Definition: Evaluator.h:258
FailureOr< EvaluatorValuePtr > getField(StringRef field)
Definition: Evaluator.h:292
ObjectValue(om::ClassOp cls, Location loc)
Definition: Evaluator.h:265
ArrayAttr getFieldNames()
Get all the field names of the Object.
Definition: Evaluator.cpp:747
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition: Evaluator.h:286
void setFields(llvm::SmallDenseMap< StringAttr, EvaluatorValuePtr > newFields)
Definition: Evaluator.h:271
om::ClassOp getClassOp() const
Definition: Evaluator.h:268
llvm::SmallDenseMap< StringAttr, EvaluatorValuePtr > fields
Definition: Evaluator.h:304
StringAttr getModule() const
Definition: Evaluator.h:383
StringAttr getAsString() const
Definition: Evaluator.cpp:864
LogicalResult finalizeImpl()
Definition: Evaluator.h:394
om::TargetKindAttr getTargetKind() const
Definition: Evaluator.h:379
StringAttr getField() const
Definition: Evaluator.h:387
om::TargetKindAttr targetKind
Definition: Evaluator.h:402
void setBasepath(const BasePathValue &basepath)
Definition: Evaluator.cpp:909
om::PathAttr getPath() const
Definition: Evaluator.h:381
PathValue(om::TargetKindAttr targetKind, om::PathAttr path, StringAttr module, StringAttr ref, StringAttr field, Location loc)
Create a path value representing a regular path.
Definition: Evaluator.cpp:852
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition: Evaluator.h:397
static PathValue getEmptyPath(Location loc)
Definition: Evaluator.cpp:858
StringAttr getRef() const
Definition: Evaluator.h:385
Values which can be used as pointers to different values.
Definition: Evaluator.h:93
EvaluatorValuePtr getValue() const
Definition: Evaluator.h:104
FailureOr< EvaluatorValuePtr > getStrippedValue() const
Definition: Evaluator.h:114
static bool classof(const EvaluatorValue *e)
Definition: Evaluator.h:99
ReferenceValue(Type type, Location loc)
Definition: Evaluator.h:94
void setValue(EvaluatorValuePtr newValue)
Definition: Evaluator.h:105
static bool classof(const EvaluatorValue *e)
Implement LLVM RTTI.
Definition: Evaluator.h:333
const TupleElements & getElements() const
Definition: Evaluator.h:340
TupleValue(TupleType type, Location loc)
Definition: Evaluator.h:317
TupleType getTupleType() const
Return the type of the value, which is a TupleType.
Definition: Evaluator.h:338
llvm::SmallVector< EvaluatorValuePtr > TupleElements
Definition: Evaluator.h:309
TupleValue(TupleType type, TupleElements tupleElements, Location loc)
Definition: Evaluator.h:310
void setElements(TupleElements newElements)
Definition: Evaluator.h:320