Skip to content

Commit 00c0ce0

Browse files
committed
[NFC] [Clang] Remove pre-computed complex float types
As discussed in D109948, pre-computing all complex float types is not necessary and brings extra overhead. This patch removes these defined types, and construct them in-place when needed. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D111387
1 parent b164f23 commit 00c0ce0

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
10911091
CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
10921092
CanQualType BFloat16Ty;
10931093
CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
1094-
CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
1095-
CanQualType Float128ComplexTy;
10961094
CanQualType VoidPtrTy, NullPtrTy;
10971095
CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
10981096
CanQualType BuiltinFnTy;

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,12 +1411,6 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
14111411
if (LangOpts.MatrixTypes)
14121412
InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
14131413

1414-
// C99 6.2.5p11.
1415-
FloatComplexTy = getComplexType(FloatTy);
1416-
DoubleComplexTy = getComplexType(DoubleTy);
1417-
LongDoubleComplexTy = getComplexType(LongDoubleTy);
1418-
Float128ComplexTy = getComplexType(Float128Ty);
1419-
14201414
// Builtin types for 'id', 'Class', and 'SEL'.
14211415
InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId);
14221416
InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass);
@@ -6341,10 +6335,10 @@ QualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size,
63416335
case Float16Rank:
63426336
case HalfRank: llvm_unreachable("Complex half is not supported");
63436337
case Ibm128Rank: llvm_unreachable("Complex __ibm128 is not supported");
6344-
case FloatRank: return FloatComplexTy;
6345-
case DoubleRank: return DoubleComplexTy;
6346-
case LongDoubleRank: return LongDoubleComplexTy;
6347-
case Float128Rank: return Float128ComplexTy;
6338+
case FloatRank: return getComplexType(FloatTy);
6339+
case DoubleRank: return getComplexType(DoubleTy);
6340+
case LongDoubleRank: return getComplexType(LongDoubleTy);
6341+
case Float128Rank: return getComplexType(Float128Ty);
63486342
}
63496343
}
63506344

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -981,21 +981,25 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
981981
}
982982
break;
983983

984-
case DW_ATE_complex_float:
985-
if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatComplexTy))
986-
return GetType(ast.FloatComplexTy);
987-
else if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleComplexTy))
988-
return GetType(ast.DoubleComplexTy);
989-
else if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleComplexTy))
990-
return GetType(ast.LongDoubleComplexTy);
991-
else {
992-
CompilerType complex_float_clang_type =
993-
GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float,
994-
bit_size / 2);
995-
return GetType(
996-
ast.getComplexType(ClangUtil::GetQualType(complex_float_clang_type)));
997-
}
998-
break;
984+
case DW_ATE_complex_float: {
985+
CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
986+
if (QualTypeMatchesBitSize(bit_size, ast, FloatComplexTy))
987+
return GetType(FloatComplexTy);
988+
989+
CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
990+
if (QualTypeMatchesBitSize(bit_size, ast, DoubleComplexTy))
991+
return GetType(DoubleComplexTy);
992+
993+
CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
994+
if (QualTypeMatchesBitSize(bit_size, ast, LongDoubleComplexTy))
995+
return GetType(LongDoubleComplexTy);
996+
997+
CompilerType complex_float_clang_type =
998+
GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float,
999+
bit_size / 2);
1000+
return GetType(
1001+
ast.getComplexType(ClangUtil::GetQualType(complex_float_clang_type)));
1002+
}
9991003

10001004
case DW_ATE_float:
10011005
if (type_name == "float" &&
@@ -2051,11 +2055,11 @@ TypeSystemClang::GetOpaqueCompilerType(clang::ASTContext *ast,
20512055
case eBasicTypeLongDouble:
20522056
return ast->LongDoubleTy.getAsOpaquePtr();
20532057
case eBasicTypeFloatComplex:
2054-
return ast->FloatComplexTy.getAsOpaquePtr();
2058+
return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
20552059
case eBasicTypeDoubleComplex:
2056-
return ast->DoubleComplexTy.getAsOpaquePtr();
2060+
return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
20572061
case eBasicTypeLongDoubleComplex:
2058-
return ast->LongDoubleComplexTy.getAsOpaquePtr();
2062+
return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
20592063
case eBasicTypeObjCID:
20602064
return ast->getObjCIdType().getAsOpaquePtr();
20612065
case eBasicTypeObjCClass:

lldb/unittests/Symbol/TestTypeSystemClang.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ TEST_F(TestTypeSystemClang, TestGetBasicTypeFromEnum) {
6060
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeDouble),
6161
context.DoubleTy));
6262
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeDoubleComplex),
63-
context.DoubleComplexTy));
63+
context.getComplexType(context.DoubleTy)));
6464
EXPECT_TRUE(
6565
context.hasSameType(GetBasicQualType(eBasicTypeFloat), context.FloatTy));
6666
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeFloatComplex),
67-
context.FloatComplexTy));
67+
context.getComplexType(context.FloatTy)));
6868
EXPECT_TRUE(
6969
context.hasSameType(GetBasicQualType(eBasicTypeHalf), context.HalfTy));
7070
EXPECT_TRUE(
@@ -75,8 +75,9 @@ TEST_F(TestTypeSystemClang, TestGetBasicTypeFromEnum) {
7575
context.hasSameType(GetBasicQualType(eBasicTypeLong), context.LongTy));
7676
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeLongDouble),
7777
context.LongDoubleTy));
78-
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeLongDoubleComplex),
79-
context.LongDoubleComplexTy));
78+
EXPECT_TRUE(
79+
context.hasSameType(GetBasicQualType(eBasicTypeLongDoubleComplex),
80+
context.getComplexType(context.LongDoubleTy)));
8081
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeLongLong),
8182
context.LongLongTy));
8283
EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeNullPtr),

0 commit comments

Comments
 (0)