[cfe-commits] r149253 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp
Benjamin Kramer
benny.kra at googlemail.com
Mon Jan 30 08:17:40 PST 2012
Author: d0k
Date: Mon Jan 30 10:17:39 2012
New Revision: 149253
URL: http://llvm.org/viewvc/llvm-project?rev=149253&view=rev
Log:
SmallBitVectorize the deduced parameter set.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=149253&r1=149252&r2=149253&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 30 10:17:39 2012
@@ -45,6 +45,7 @@
class APSInt;
template <typename ValueT> struct DenseMapInfo;
template <typename ValueT, typename ValueInfoT> class DenseSet;
+ class SmallBitVector;
}
namespace clang {
@@ -4702,14 +4703,14 @@
void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used);
+ llvm::SmallBitVector &Used);
void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
- SmallVectorImpl<bool> &Deduced) {
+ llvm::SmallBitVector &Deduced) {
return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
}
static void MarkDeducedTemplateParameters(ASTContext &Ctx,
FunctionTemplateDecl *FunctionTemplate,
- SmallVectorImpl<bool> &Deduced);
+ llvm::SmallBitVector &Deduced);
//===--------------------------------------------------------------------===//
// C++ Template Instantiation
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=149253&r1=149252&r2=149253&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Jan 30 10:17:39 2012
@@ -24,6 +24,7 @@
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
@@ -2526,7 +2527,7 @@
// Figure out which template parameters are deduced (or have default
// arguments).
- SmallVector<bool, 16> Deduced;
+ llvm::SmallBitVector Deduced;
Sema::MarkDeducedTemplateParameters(Ctx, FunTmpl, Deduced);
unsigned LastDeducibleArgument;
for (LastDeducibleArgument = Deduced.size(); LastDeducibleArgument > 0;
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=149253&r1=149252&r2=149253&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Jan 30 10:17:39 2012
@@ -26,6 +26,7 @@
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/PartialDiagnostic.h"
+#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/StringExtras.h"
using namespace clang;
using namespace sema;
@@ -5090,17 +5091,13 @@
// partial specialization are deducible from the template
// arguments. If not, this class template partial specialization
// will never be used.
- SmallVector<bool, 8> DeducibleParams;
- DeducibleParams.resize(TemplateParams->size());
+ llvm::SmallBitVector DeducibleParams(TemplateParams->size());
MarkUsedTemplateParameters(Partial->getTemplateArgs(), true,
TemplateParams->getDepth(),
DeducibleParams);
- unsigned NumNonDeducible = 0;
- for (unsigned I = 0, N = DeducibleParams.size(); I != N; ++I)
- if (!DeducibleParams[I])
- ++NumNonDeducible;
- if (NumNonDeducible) {
+ if (!DeducibleParams.all()) {
+ unsigned NumNonDeducible = DeducibleParams.size()-DeducibleParams.count();
Diag(TemplateNameLoc, diag::warn_partial_specs_not_deducible)
<< (NumNonDeducible > 1)
<< SourceRange(TemplateNameLoc, RAngleLoc);
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=149253&r1=149252&r2=149253&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Jan 30 10:17:39 2012
@@ -20,7 +20,7 @@
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
-#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/SmallBitVector.h"
#include "TreeTransform.h"
#include <algorithm>
@@ -736,7 +736,7 @@
SmallVector<unsigned, 2> PackIndices;
QualType Pattern = Expansion->getPattern();
{
- llvm::BitVector SawIndices(TemplateParams->size());
+ llvm::SmallBitVector SawIndices(TemplateParams->size());
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
@@ -1745,7 +1745,7 @@
// parameter packs expanded by the pack expansion.
SmallVector<unsigned, 2> PackIndices;
{
- llvm::BitVector SawIndices(TemplateParams->size());
+ llvm::SmallBitVector SawIndices(TemplateParams->size());
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
@@ -3021,7 +3021,7 @@
QualType ParamPattern = ParamExpansion->getPattern();
SmallVector<unsigned, 2> PackIndices;
{
- llvm::BitVector SawIndices(TemplateParams->size());
+ llvm::SmallBitVector SawIndices(TemplateParams->size());
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
@@ -3474,7 +3474,7 @@
MarkUsedTemplateParameters(ASTContext &Ctx, QualType T,
bool OnlyDeduced,
unsigned Level,
- SmallVectorImpl<bool> &Deduced);
+ llvm::SmallBitVector &Deduced);
/// \brief If this is a non-static member function,
static void MaybeAddImplicitObjectParameterType(ASTContext &Context,
@@ -3622,8 +3622,7 @@
}
// Figure out which template parameters were used.
- SmallVector<bool, 4> UsedParameters;
- UsedParameters.resize(TemplateParams->size());
+ llvm::SmallBitVector UsedParameters(TemplateParams->size());
switch (TPOC) {
case TPOC_Call: {
unsigned NumParams = std::min(NumCallArguments,
@@ -4006,7 +4005,7 @@
const TemplateArgument &TemplateArg,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used);
+ llvm::SmallBitVector &Used);
/// \brief Mark the template parameters that are used by the given
/// expression.
@@ -4015,7 +4014,7 @@
const Expr *E,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used) {
+ llvm::SmallBitVector &Used) {
// We can deduce from a pack expansion.
if (const PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(E))
E = Expansion->getPattern();
@@ -4046,7 +4045,7 @@
NestedNameSpecifier *NNS,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used) {
+ llvm::SmallBitVector &Used) {
if (!NNS)
return;
@@ -4063,7 +4062,7 @@
TemplateName Name,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used) {
+ llvm::SmallBitVector &Used) {
if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
if (TemplateTemplateParmDecl *TTP
= dyn_cast<TemplateTemplateParmDecl>(Template)) {
@@ -4087,7 +4086,7 @@
MarkUsedTemplateParameters(ASTContext &Ctx, QualType T,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used) {
+ llvm::SmallBitVector &Used) {
if (T.isNull())
return;
@@ -4320,7 +4319,7 @@
const TemplateArgument &TemplateArg,
bool OnlyDeduced,
unsigned Depth,
- SmallVectorImpl<bool> &Used) {
+ llvm::SmallBitVector &Used) {
switch (TemplateArg.getKind()) {
case TemplateArgument::Null:
case TemplateArgument::Integral:
@@ -4365,7 +4364,7 @@
void
Sema::MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
bool OnlyDeduced, unsigned Depth,
- SmallVectorImpl<bool> &Used) {
+ llvm::SmallBitVector &Used) {
// C++0x [temp.deduct.type]p9:
// If the template argument list of P contains a pack expansion that is not
// the last template argument, the entire template argument list is a
@@ -4384,7 +4383,7 @@
void
Sema::MarkDeducedTemplateParameters(ASTContext &Ctx,
FunctionTemplateDecl *FunctionTemplate,
- SmallVectorImpl<bool> &Deduced) {
+ llvm::SmallBitVector &Deduced) {
TemplateParameterList *TemplateParams
= FunctionTemplate->getTemplateParameters();
Deduced.clear();
@@ -4404,14 +4403,9 @@
TemplateParameterList *TemplateParams
= FunctionTemplate->getTemplateParameters();
- SmallVector<bool, 4> Deduced;
- Deduced.resize(TemplateParams->size());
+ llvm::SmallBitVector Deduced(TemplateParams->size());
::MarkUsedTemplateParameters(S.Context, T, true, TemplateParams->getDepth(),
Deduced);
- for (unsigned I = 0, N = Deduced.size(); I != N; ++I)
- if (Deduced[I])
- return true;
-
- return false;
+ return Deduced.any();
}
More information about the cfe-commits
mailing list