37
37
#include < cassert>
38
38
#include < cstddef>
39
39
#include < cstdint>
40
- #include < memory>
41
40
#include < utility>
42
41
43
42
namespace clang {
@@ -875,8 +874,7 @@ class Sema;
875
874
ConversionFixItGenerator Fix;
876
875
877
876
// / Viable - True to indicate that this overload candidate is viable.
878
- LLVM_PREFERRED_TYPE (bool )
879
- unsigned Viable : 1 ;
877
+ bool Viable : 1 ;
880
878
881
879
// / Whether this candidate is the best viable function, or tied for being
882
880
// / the best viable function.
@@ -885,14 +883,12 @@ class Sema;
885
883
// / was part of the ambiguity kernel: the minimal non-empty set of viable
886
884
// / candidates such that all elements of the ambiguity kernel are better
887
885
// / than all viable candidates not in the ambiguity kernel.
888
- LLVM_PREFERRED_TYPE (bool )
889
- unsigned Best : 1 ;
886
+ bool Best : 1 ;
890
887
891
888
// / IsSurrogate - True to indicate that this candidate is a
892
889
// / surrogate for a conversion to a function pointer or reference
893
890
// / (C++ [over.call.object]).
894
- LLVM_PREFERRED_TYPE (bool )
895
- unsigned IsSurrogate : 1 ;
891
+ bool IsSurrogate : 1 ;
896
892
897
893
// / IgnoreObjectArgument - True to indicate that the first
898
894
// / argument's conversion, which for this function represents the
@@ -901,20 +897,18 @@ class Sema;
901
897
// / implicit object argument is just a placeholder) or a
902
898
// / non-static member function when the call doesn't have an
903
899
// / object argument.
904
- LLVM_PREFERRED_TYPE (bool )
905
- unsigned IgnoreObjectArgument : 1 ;
900
+ bool IgnoreObjectArgument : 1 ;
906
901
907
902
// / True if the candidate was found using ADL.
908
- LLVM_PREFERRED_TYPE (CallExpr::ADLCallKind)
909
- unsigned IsADLCandidate : 1 ;
903
+ CallExpr::ADLCallKind IsADLCandidate : 1 ;
910
904
911
905
// / Whether this is a rewritten candidate, and if so, of what kind?
912
906
LLVM_PREFERRED_TYPE (OverloadCandidateRewriteKind)
913
907
unsigned RewriteKind : 2 ;
914
908
915
909
// / FailureKind - The reason why this candidate is not viable.
916
- LLVM_PREFERRED_TYPE ( OverloadFailureKind)
917
- unsigned FailureKind : 5 ;
910
+ // / Actually an OverloadFailureKind.
911
+ unsigned char FailureKind ;
918
912
919
913
// / The number of call arguments that were explicitly provided,
920
914
// / to be used while performing partial ordering of function templates.
@@ -978,9 +972,7 @@ class Sema;
978
972
private:
979
973
friend class OverloadCandidateSet ;
980
974
OverloadCandidate ()
981
- : IsSurrogate(false ),
982
- IsADLCandidate (static_cast <unsigned >(CallExpr::NotADL)),
983
- RewriteKind(CRK_None) {}
975
+ : IsSurrogate(false ), IsADLCandidate(CallExpr::NotADL), RewriteKind(CRK_None) {}
984
976
};
985
977
986
978
// / OverloadCandidateSet - A set of overload candidates, used in C++
@@ -1078,16 +1070,51 @@ class Sema;
1078
1070
};
1079
1071
1080
1072
private:
1081
- SmallVector<OverloadCandidate, 4 > Candidates;
1082
- llvm::SmallPtrSet<uintptr_t , 4 > Functions;
1073
+ SmallVector<OverloadCandidate, 16 > Candidates;
1074
+ llvm::SmallPtrSet<uintptr_t , 16 > Functions;
1075
+
1076
+ // Allocator for ConversionSequenceLists. We store the first few of these
1077
+ // inline to avoid allocation for small sets.
1078
+ llvm::BumpPtrAllocator SlabAllocator;
1083
1079
1084
1080
SourceLocation Loc;
1085
1081
CandidateSetKind Kind;
1086
1082
OperatorRewriteInfo RewriteInfo;
1087
1083
1084
+ constexpr static unsigned NumInlineBytes =
1085
+ 24 * sizeof (ImplicitConversionSequence);
1086
+ unsigned NumInlineBytesUsed = 0 ;
1087
+ alignas (void *) char InlineSpace[NumInlineBytes];
1088
+
1088
1089
// Address space of the object being constructed.
1089
1090
LangAS DestAS = LangAS::Default;
1090
1091
1092
+ // / If we have space, allocates from inline storage. Otherwise, allocates
1093
+ // / from the slab allocator.
1094
+ // / FIXME: It would probably be nice to have a SmallBumpPtrAllocator
1095
+ // / instead.
1096
+ // / FIXME: Now that this only allocates ImplicitConversionSequences, do we
1097
+ // / want to un-generalize this?
1098
+ template <typename T>
1099
+ T *slabAllocate (unsigned N) {
1100
+ // It's simpler if this doesn't need to consider alignment.
1101
+ static_assert (alignof (T) == alignof (void *),
1102
+ " Only works for pointer-aligned types." );
1103
+ static_assert (std::is_trivial<T>::value ||
1104
+ std::is_same<ImplicitConversionSequence, T>::value,
1105
+ " Add destruction logic to OverloadCandidateSet::clear()." );
1106
+
1107
+ unsigned NBytes = sizeof (T) * N;
1108
+ if (NBytes > NumInlineBytes - NumInlineBytesUsed)
1109
+ return SlabAllocator.Allocate <T>(N);
1110
+ char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
1111
+ assert (uintptr_t (FreeSpaceStart) % alignof (void *) == 0 &&
1112
+ " Misaligned storage!" );
1113
+
1114
+ NumInlineBytesUsed += NBytes;
1115
+ return reinterpret_cast <T *>(FreeSpaceStart);
1116
+ }
1117
+
1091
1118
void destroyCandidates ();
1092
1119
1093
1120
public:
@@ -1136,7 +1163,12 @@ class Sema;
1136
1163
ConversionSequenceList
1137
1164
allocateConversionSequences (unsigned NumConversions) {
1138
1165
ImplicitConversionSequence *Conversions =
1139
- new ImplicitConversionSequence[NumConversions];
1166
+ slabAllocate<ImplicitConversionSequence>(NumConversions);
1167
+
1168
+ // Construct the new objects.
1169
+ for (unsigned I = 0 ; I != NumConversions; ++I)
1170
+ new (&Conversions[I]) ImplicitConversionSequence ();
1171
+
1140
1172
return ConversionSequenceList (Conversions, NumConversions);
1141
1173
}
1142
1174
0 commit comments