CIRCT  19.0.0git
HWTypeInterfaces.cpp
Go to the documentation of this file.
1 //===- HWTypeInterfaces.cpp - Implement HW type interfaces ------*- 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 // This file implements type interfaces of the HW Dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
15 using namespace mlir;
16 using namespace circt;
17 using namespace hw;
18 using namespace FieldIdImpl;
19 
21  uint64_t fieldID) {
22  std::pair<Type, uint64_t> pair(type, fieldID);
23  while (pair.second) {
24  if (auto ftype = dyn_cast<FieldIDTypeInterface>(pair.first))
25  pair = ftype.getSubTypeByFieldID(pair.second);
26  else
27  llvm::report_fatal_error("fieldID indexing into a non-aggregate type");
28  }
29  return pair.first;
30 }
31 
32 std::pair<Type, uint64_t>
33 circt::hw::FieldIdImpl::getSubTypeByFieldID(Type type, uint64_t fieldID) {
34  if (!fieldID)
35  return {type, 0};
36  if (auto ftype = dyn_cast<FieldIDTypeInterface>(type))
37  return ftype.getSubTypeByFieldID(fieldID);
38 
39  llvm::report_fatal_error("fieldID indexing into a non-aggregate type");
40 }
41 
43  if (auto ftype = dyn_cast<FieldIDTypeInterface>(type))
44  return ftype.getMaxFieldID();
45  return 0;
46 }
47 
48 std::pair<uint64_t, bool>
50  uint64_t index) {
51  if (auto ftype = dyn_cast<FieldIDTypeInterface>(type))
52  return ftype.projectToChildFieldID(fieldID, index);
53  return {0, fieldID == 0};
54 }
55 
57  uint64_t fieldID) {
58  if (auto ftype = dyn_cast<FieldIDTypeInterface>(type))
59  return ftype.getIndexForFieldID(fieldID);
60  return 0;
61 }
62 
63 uint64_t circt::hw::FieldIdImpl::getFieldID(Type type, uint64_t fieldID) {
64  if (auto ftype = dyn_cast<FieldIDTypeInterface>(type))
65  return ftype.getFieldID(fieldID);
66  return 0;
67 }
68 
69 std::pair<uint64_t, uint64_t>
70 circt::hw::FieldIdImpl::getIndexAndSubfieldID(Type type, uint64_t fieldID) {
71  if (auto ftype = dyn_cast<FieldIDTypeInterface>(type))
72  return ftype.getIndexAndSubfieldID(fieldID);
73  return {0, fieldID == 0};
74 }
75 
76 #include "circt/Dialect/HW/HWTypeInterfaces.cpp.inc"
std::pair< uint64_t, uint64_t > getIndexAndSubfieldID(Type type, uint64_t fieldID)
uint64_t getFieldID(Type type, uint64_t index)
std::pair<::mlir::Type, uint64_t > getSubTypeByFieldID(Type, uint64_t fieldID)
std::pair< uint64_t, bool > projectToChildFieldID(Type, uint64_t fieldID, uint64_t index)
::mlir::Type getFinalTypeByFieldID(Type type, uint64_t fieldID)
uint64_t getIndexForFieldID(Type type, uint64_t fieldID)
uint64_t getMaxFieldID(Type)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: hw.py:1