Skip to content

Commit

Permalink
Use map vector to preserve field name ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Oct 10, 2024
1 parent 65948a3 commit 9226a5d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/circt/Dialect/OM/Evaluator/Evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using EvaluatorValuePtr = std::shared_ptr<EvaluatorValue>;

/// The fields of a composite Object, currently represented as a map. Further
/// refinement is expected.
using ObjectFields = SmallDenseMap<StringAttr, EvaluatorValuePtr>;
using ObjectFields = llvm::MapVector<StringAttr, EvaluatorValuePtr>;

/// Base class for evaluator runtime values.
/// Enables the shared_from_this functionality so Evaluator Value pointers can
Expand Down Expand Up @@ -268,7 +268,7 @@ struct ObjectValue : EvaluatorValue {
om::ClassOp getClassOp() const { return cls; }
const auto &getFields() const { return fields; }

void setFields(llvm::SmallDenseMap<StringAttr, EvaluatorValuePtr> newFields) {
void setFields(ObjectFields newFields) {
fields = std::move(newFields);
markFullyEvaluated();
}
Expand Down Expand Up @@ -301,7 +301,7 @@ struct ObjectValue : EvaluatorValue {

private:
om::ClassOp cls;
llvm::SmallDenseMap<StringAttr, EvaluatorValuePtr> fields;
ObjectFields fields;
};

/// Tuple values.
Expand Down
4 changes: 0 additions & 4 deletions lib/Dialect/OM/Evaluator/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,6 @@ ArrayAttr circt::om::Object::getFieldNames() {
for (auto &f : fields)
fieldNames.push_back(f.first);

llvm::sort(fieldNames, [](Attribute a, Attribute b) {
return cast<StringAttr>(a).getValue() < cast<StringAttr>(b).getValue();
});

return ArrayAttr::get(cls.getContext(), fieldNames);
}

Expand Down
4 changes: 2 additions & 2 deletions test/CAPI/om.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void testEvaluator(MlirContext ctx) {
OMEvaluatorValue child = omEvaluatorObjectGetField(object, childFieldName);

MlirAttribute fieldNamesO = omEvaluatorObjectGetFieldNames(object);
// CHECK: ["child", "field"]
// CHECK: ["field", "child"]
mlirAttributeDump(fieldNamesO);

// CHECK: 0
Expand All @@ -129,7 +129,7 @@ void testEvaluator(MlirContext ctx) {

MlirAttribute fieldNamesC = omEvaluatorObjectGetFieldNames(child);

// CHECK: ["bar", "baz", "foo"]
// CHECK: ["foo", "bar", "baz"]
mlirAttributeDump(fieldNamesC);

// CHECK: child object field `foo` is primitive: 1
Expand Down

0 comments on commit 9226a5d

Please sign in to comment.