CIRCT 23.0.0git
Loading...
Searching...
No Matches
LayerSet.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#ifndef CIRCT_DIALECT_FIRRTL_LAYERSET_H
10#define CIRCT_DIALECT_FIRRTL_LAYERSET_H
11
12#include "circt/Support/LLVM.h"
13#include "mlir/IR/BuiltinAttributes.h"
14
15namespace circt {
16namespace firrtl {
17
18/// Compares two `SymbolRefAttr` lexicographically, returning true if LHS should
19/// be ordered before RHS.
21 bool operator()(SymbolRefAttr lhs, SymbolRefAttr rhs) const {
22 auto cmp = lhs.getRootReference().compare(rhs.getRootReference());
23 if (cmp == -1)
24 return true;
25 if (cmp == 1)
26 return false;
27 auto lhsNested = lhs.getNestedReferences();
28 auto rhsNested = rhs.getNestedReferences();
29 auto lhsNestedSize = lhsNested.size();
30 auto rhsNestedSize = rhsNested.size();
31 auto e = std::min(lhsNestedSize, rhsNestedSize);
32 for (unsigned i = 0; i < e; ++i) {
33 auto cmp = lhsNested[i].getAttr().compare(rhsNested[i].getAttr());
34 if (cmp == -1)
35 return true;
36 if (cmp == 1)
37 return false;
38 }
39 return lhsNestedSize < rhsNestedSize;
40 }
41};
42
44
45} // namespace firrtl
46} // namespace circt
47
48#endif // CIRCT_DIALECT_FIRRTL_LAYERSET_H
SmallSet< SymbolRefAttr, 4, LayerSetCompare > LayerSet
Definition LayerSet.h:43
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Compares two SymbolRefAttr lexicographically, returning true if LHS should be ordered before RHS.
Definition LayerSet.h:20
bool operator()(SymbolRefAttr lhs, SymbolRefAttr rhs) const
Definition LayerSet.h:21