CIRCT 23.0.0git
Loading...
Searching...
No Matches
RTGTestTypes.cpp
Go to the documentation of this file.
1//===- RTGTestTypes.cpp ---------------------------------------------------===//
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
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/ADT/TypeSwitch.h"
19
20using namespace circt;
21using namespace rtgtest;
22
23//===----------------------------------------------------------------------===//
24// TableGen generated logic.
25//===----------------------------------------------------------------------===//
26
27#define GET_TYPEDEF_CLASSES
28#include "circt/Dialect/RTGTest/IR/RTGTestTypes.cpp.inc"
29
30//===----------------------------------------------------------------------===//
31// IntegerRegisterType
32//===----------------------------------------------------------------------===//
33
34bool IntegerRegisterType::isValidContentType(Type type) const {
35 return llvm::isa<IntegerType>(type);
36}
37
38TypedAttr IntegerRegisterType::parseContentValue(llvm::StringRef valueString,
39 Type contentType) const {
40 auto immType = dyn_cast<IntegerType>(contentType);
41 if (!immType)
42 return {};
43
44 APInt intValue;
45 if (valueString.getAsInteger(0, intValue))
46 return {};
47
48 if (intValue.getBitWidth() < immType.getWidth()) {
49 intValue = intValue.zext(immType.getWidth());
50 } else {
51 if (!intValue.isIntN(immType.getWidth()))
52 return {};
53 intValue = intValue.trunc(immType.getWidth());
54 }
55
56 return IntegerAttr::get(
57 IntegerType::get(getContext(), intValue.getBitWidth()), intValue);
58}
59
60std::string IntegerRegisterType::getIntrinsicLabel(Attribute value,
61 llvm::StringRef id) const {
62 return "spike.pre.printreg.x" +
63 std::to_string(
64 cast<rtg::RegisterAttrInterface>(value).getClassIndex()) +
65 "." + id.str();
66}
67
68unsigned IntegerRegisterType::getRegisterClassSize() { return 32; }
69
70rtg::RegisterAttrInterface
71IntegerRegisterType::getRegisterAttrForClassIndex(MLIRContext *ctx,
72 unsigned index) {
73 switch (index) {
74 case 0:
75 return RegZeroAttr::get(ctx);
76 case 1:
77 return RegRaAttr::get(ctx);
78 case 2:
79 return RegSpAttr::get(ctx);
80 case 3:
81 return RegGpAttr::get(ctx);
82 case 4:
83 return RegTpAttr::get(ctx);
84 case 5:
85 return RegT0Attr::get(ctx);
86 case 6:
87 return RegT1Attr::get(ctx);
88 case 7:
89 return RegT2Attr::get(ctx);
90 case 8:
91 return RegS0Attr::get(ctx);
92 case 9:
93 return RegS1Attr::get(ctx);
94 case 10:
95 return RegA0Attr::get(ctx);
96 case 11:
97 return RegA1Attr::get(ctx);
98 case 12:
99 return RegA2Attr::get(ctx);
100 case 13:
101 return RegA3Attr::get(ctx);
102 case 14:
103 return RegA4Attr::get(ctx);
104 case 15:
105 return RegA5Attr::get(ctx);
106 case 16:
107 return RegA6Attr::get(ctx);
108 case 17:
109 return RegA7Attr::get(ctx);
110 case 18:
111 return RegS2Attr::get(ctx);
112 case 19:
113 return RegS3Attr::get(ctx);
114 case 20:
115 return RegS4Attr::get(ctx);
116 case 21:
117 return RegS5Attr::get(ctx);
118 case 22:
119 return RegS6Attr::get(ctx);
120 case 23:
121 return RegS7Attr::get(ctx);
122 case 24:
123 return RegS8Attr::get(ctx);
124 case 25:
125 return RegS9Attr::get(ctx);
126 case 26:
127 return RegS10Attr::get(ctx);
128 case 27:
129 return RegS11Attr::get(ctx);
130 case 28:
131 return RegT3Attr::get(ctx);
132 case 29:
133 return RegT4Attr::get(ctx);
134 case 30:
135 return RegT5Attr::get(ctx);
136 case 31:
137 return RegT6Attr::get(ctx);
138 }
139 return {};
140}
141
142//===----------------------------------------------------------------------===//
143// FloatRegisterType
144//===----------------------------------------------------------------------===//
145
146unsigned FloatRegisterType::getRegisterClassSize() { return 1; }
147
148rtg::RegisterAttrInterface
149FloatRegisterType::getRegisterAttrForClassIndex(MLIRContext *ctx,
150 unsigned index) {
151 switch (index) {
152 case 0:
153 return RegF0Attr::get(ctx);
154 default:
155 return {};
156 }
157}
158
159//===----------------------------------------------------------------------===//
160// Type registration
161//===----------------------------------------------------------------------===//
162
163void circt::rtgtest::RTGTestDialect::registerTypes() {
164 addTypes<
165#define GET_TYPEDEF_LIST
166#include "circt/Dialect/RTGTest/IR/RTGTestTypes.cpp.inc"
167 >();
168}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.