CIRCT  19.0.0git
AppID.h
Go to the documentation of this file.
1 //===- AppID.h - AppID related code -----------------------------*- C++ -*-===//
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 // Application IDs are paths through the instance hierarchy with some
10 // application-specific meaning. They allow designers and users to avoid some of
11 // the design's implementation details.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef CIRCT_DIALECT_ESI_APPID_H
16 #define CIRCT_DIALECT_ESI_APPID_H
17 
20 
21 #include "mlir/IR/Operation.h"
22 #include "llvm/ADT/DenseMap.h"
23 
24 namespace circt {
25 namespace esi {
26 
27 /// Get the AppID of a particular operation. Returns null if the operation does
28 /// not have one.
29 AppIDAttr getAppID(Operation *op);
30 
31 /// An index for resolving AppIDPaths to dynamic instances.
32 class AppIDIndex {
33 public:
34  AppIDIndex(Operation *mlirTop);
36 
37  // If invalid, construction failed for some reason (which was emitted via an
38  // error). Since we want to be able to call this class as an analysis, all of
39  // the index construction occurs in the constructor, which doesn't allow for
40  // a LogicalResult return. (This is where exceptions would be useful.)
41  bool isValid() const { return valid; }
42 
43  // Return an array of AppIDAttrs which are contained in the module.
44  ArrayAttr getChildAppIDsOf(hw::HWModuleLike) const;
45 
46  /// Walk the AppID hierarchy rooted at the specified module.
47  LogicalResult
48  walk(hw::HWModuleLike top,
49  function_ref<void(AppIDPathAttr, ArrayRef<Operation *>)> fn) const;
50  LogicalResult
51  walk(StringRef top,
52  function_ref<void(AppIDPathAttr, ArrayRef<Operation *>)> fn) const;
53 
54  /// Return an array of InnerNameRefAttrs representing the relative path to
55  /// 'appid' from 'fromMod'.
56  FailureOr<ArrayAttr> getAppIDPathAttr(hw::HWModuleLike fromMod,
57  AppIDAttr appid, Location loc) const;
58 
59 private:
60  /// Walk the AppID hierarchy rooted at the specified module.
61  LogicalResult
62  walk(hw::HWModuleLike top, hw::HWModuleLike current,
63  SmallVectorImpl<AppIDAttr> &pathStack,
64  SmallVectorImpl<Operation *> &opStack,
65  function_ref<void(AppIDPathAttr, ArrayRef<Operation *>)> fn) const;
66 
67  //===--------------------------------------------------------------------===//
68  // Index construction and storage.
69  //===--------------------------------------------------------------------===//
70  class ModuleAppIDs;
71 
72  /// Construct the index for a module.
73  FailureOr<const ModuleAppIDs *> buildIndexFor(hw::HWModuleLike modToProcess);
74 
75  // Map modules to their cached child app ID indexes.
76  DenseMap<hw::HWModuleLike, ModuleAppIDs *> containerAppIDs;
77 
78  bool valid;
80  Operation *mlirTop;
81 };
82 
83 } // namespace esi
84 } // namespace circt
85 
86 #endif // CIRCT_DIALECT_ESI_APPID_H
An index for resolving AppIDPaths to dynamic instances.
Definition: AppID.h:32
DenseMap< hw::HWModuleLike, ModuleAppIDs * > containerAppIDs
Definition: AppID.h:76
FailureOr< ArrayAttr > getAppIDPathAttr(hw::HWModuleLike fromMod, AppIDAttr appid, Location loc) const
Return an array of InnerNameRefAttrs representing the relative path to 'appid' from 'fromMod'.
bool isValid() const
Definition: AppID.h:41
LogicalResult walk(hw::HWModuleLike top, function_ref< void(AppIDPathAttr, ArrayRef< Operation * >)> fn) const
Walk the AppID hierarchy rooted at the specified module.
AppIDIndex(Operation *mlirTop)
FailureOr< const ModuleAppIDs * > buildIndexFor(hw::HWModuleLike modToProcess)
Construct the index for a module.
LogicalResult walk(hw::HWModuleLike top, hw::HWModuleLike current, SmallVectorImpl< AppIDAttr > &pathStack, SmallVectorImpl< Operation * > &opStack, function_ref< void(AppIDPathAttr, ArrayRef< Operation * >)> fn) const
Walk the AppID hierarchy rooted at the specified module.
ArrayAttr getChildAppIDsOf(hw::HWModuleLike) const
hw::HWSymbolCache symCache
Definition: AppID.h:79
LogicalResult walk(StringRef top, function_ref< void(AppIDPathAttr, ArrayRef< Operation * >)> fn) const
Operation * mlirTop
Definition: AppID.h:80
This stores lookup tables to make manipulating and working with the IR more efficient.
Definition: HWSymCache.h:27
AppIDAttr getAppID(Operation *op)
Get the AppID of a particular operation.
Definition: AppID.cpp:17
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
Definition: esi.py:1