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