Skip to content

Commit 8a9f2de

Browse files
committed
[SYCL-PTX] Review comment: handle type description logic using a flag rather than directly in type emission.
Signed-off-by: Victor Lomuller <[email protected]>
1 parent 02b7975 commit 8a9f2de

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

clang/utils/TableGen/ClangProgModelBuiltinEmitter.cpp

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,21 @@ class JSONBuiltinInterfaceEmitter : public BuiltinNameEmitter {
254254
// Return a string representing the "base" type (ignores pointers).
255255
std::string GetBaseTypeAsStr() const;
256256

257+
enum UnderlyingType { BOOL, INT, UINT, FLOAT, BUILTIN };
258+
257259
llvm::StringRef Name;
258-
// True if the underlying type is compiler opaque type.
259-
bool IsOpaque;
260260
// Size of the vector (if applicable).
261261
int VecWidth;
262262
// Size of the element in bits.
263263
int ElementSize;
264-
// Is a integer.
265-
bool IsInteger;
266-
// Is a signed integer.
267-
bool IsSigned;
268-
// Is a float.
269-
bool IsFloat;
264+
// The underlying type represented by the record.
265+
UnderlyingType ElementType;
270266
// Is a pointer.
271267
bool IsPointer;
272268
// "const" qualifier.
273269
bool IsConst;
274270
// "volatile" qualifier.
275271
bool IsVolatile;
276-
// Is a builtin type.
277-
bool IsBuiltin;
278272
std::string AddrSpace;
279273
};
280274

@@ -922,18 +916,23 @@ void BuiltinNameEmitter::EmitQualTypeFinder() {
922916
OS << "\n} // Bultin2Qual\n";
923917
}
924918

925-
JSONBuiltinInterfaceEmitter::TypeDesc::TypeDesc(const Record *T) {
926-
Name = T->getValueAsString("Name");
927-
IsInteger = T->getValueAsBit("IsInteger");
928-
IsSigned = T->getValueAsBit("IsSigned");
929-
IsFloat = T->getValueAsBit("IsFloat");
930-
ElementSize = T->getValueAsInt("ElementSize");
931-
VecWidth = T->getValueAsInt("VecWidth");
932-
IsConst = T->getValueAsBit("IsConst");
933-
IsVolatile = T->getValueAsBit("IsVolatile");
934-
IsPointer = T->getValueAsBit("IsPointer");
935-
IsBuiltin =
936-
!T->isSubClassOf("FundamentalType") && !T->isSubClassOf("VectorType");
919+
JSONBuiltinInterfaceEmitter::TypeDesc::TypeDesc(const Record *T)
920+
: Name(T->getValueAsString("Name")),
921+
VecWidth(T->getValueAsInt("VecWidth")),
922+
ElementSize(T->getValueAsInt("ElementSize")),
923+
IsPointer(T->getValueAsBit("IsPointer")),
924+
IsConst(T->getValueAsBit("IsConst")),
925+
IsVolatile(T->getValueAsBit("IsVolatile")) {
926+
if (T->getValueAsBit("IsInteger")) {
927+
if (ElementSize == 1)
928+
ElementType = BOOL;
929+
else
930+
ElementType = T->getValueAsBit("IsSigned") ? INT : UINT;
931+
}
932+
if (T->getValueAsBit("IsFloat"))
933+
ElementType = FLOAT;
934+
if (!T->isSubClassOf("FundamentalType") && !T->isSubClassOf("VectorType"))
935+
ElementType = BUILTIN;
937936

938937
AddrSpace = StringSwitch<const char *>(T->getValueAsString("AddrSpace"))
939938
.Case("clang::LangAS::Default", "")
@@ -945,31 +944,31 @@ JSONBuiltinInterfaceEmitter::TypeDesc::TypeDesc(const Record *T) {
945944
}
946945

947946
std::string JSONBuiltinInterfaceEmitter::TypeDesc::GetBaseTypeAsStr() const {
948-
if (Name == "void") {
947+
if (Name == "void")
949948
return Name.str();
950-
}
951949

952950
llvm::SmallString<32> Buffer;
953951
{
954952
llvm::raw_svector_ostream TypeStr(Buffer);
955953
TypeStr << TypePrefix;
956-
if (IsBuiltin) {
954+
if (VecWidth != 1)
955+
TypeStr << "_vec" << VecWidth;
956+
switch (ElementType) {
957+
case BOOL:
958+
TypeStr << "_bool_t";
959+
break;
960+
case INT:
961+
TypeStr << "_int" << ElementSize << "_t";
962+
break;
963+
case UINT:
964+
TypeStr << "_uint" << ElementSize << "_t";
965+
break;
966+
case FLOAT:
967+
TypeStr << "_fp" << ElementSize << "_t";
968+
break;
969+
case BUILTIN:
957970
TypeStr << "_" << Name;
958-
} else {
959-
if (VecWidth != 1)
960-
TypeStr << "_vec" << VecWidth;
961-
if (IsInteger) {
962-
if (ElementSize == 1)
963-
TypeStr << "_bool";
964-
else
965-
TypeStr << (IsSigned ? "_int" : "_uint") << ElementSize;
966-
} else {
967-
if (IsFloat)
968-
TypeStr << "_fp" << ElementSize;
969-
else
970-
llvm_unreachable("Unknown type");
971-
}
972-
TypeStr << "_t";
971+
break;
973972
}
974973
}
975974

0 commit comments

Comments
 (0)