From: Samuel Benzaquen Date: Tue, 11 Jun 2013 18:51:07 +0000 (+0000) Subject: Reduce the number of symbols on the object file. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf69590039a186e80b165619c8ac1aef599301b3;p=clang Reduce the number of symbols on the object file. Summary: Some compilers where failing with this file because the number of symbols was above 2**15. - Replace std::list<> and std::vector<> with plain arrays. - Change VariadicMatcherCreateCallback to be a function template, and a single class that wraps the instantiations. - Remove some more unnecessary template arguments and function calls. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D948 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183768 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ASTMatchers/Dynamic/Marshallers.h b/lib/ASTMatchers/Dynamic/Marshallers.h index 2cc5f7cdaa..4ba33b8d2d 100644 --- a/lib/ASTMatchers/Dynamic/Marshallers.h +++ b/lib/ASTMatchers/Dynamic/Marshallers.h @@ -20,9 +20,7 @@ #ifndef LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H #define LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H -#include #include -#include #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/Dynamic/Diagnostics.h" @@ -77,9 +75,22 @@ public: }; /// \brief Simple callback implementation. Marshaller and function are provided. -template +/// +/// This class wraps a function of arbitrary signature and a marshaller +/// function into a MatcherCreateCallback. +/// The marshaller is in charge of taking the VariantValue arguments, checking +/// their types, unpacking them and calling the underlying function. +template class FixedArgCountMatcherCreateCallback : public MatcherCreateCallback { public: + /// FIXME: Use void(*)() as FuncType on this interface to remove the template + /// argument of this class. The marshaller can cast the function pointer back + /// to the original type. + typedef DynTypedMatcher *(*MarshallerType)(FuncType, StringRef, + const SourceRange &, + ArrayRef, + Diagnostics *); + /// \param Marshaller Function to unpack the arguments and call \c Func /// \param Func Matcher construct function. This is the function that /// compile-time matcher expressions would use to create the matcher. @@ -98,14 +109,32 @@ private: const std::string MatcherName; }; -/// \brief Helper function to do template argument deduction. -template -MatcherCreateCallback * -createMarshallerCallback(MarshallerType Marshaller, FuncType Func, - StringRef MatcherName) { - return new FixedArgCountMatcherCreateCallback( - Marshaller, Func, MatcherName); -} +/// \brief Simple callback implementation. Free function is wrapped. +/// +/// This class simply wraps a free function with the right signature to export +/// it as a MatcherCreateCallback. +/// This allows us to have one implementation of the interface for as many free +/// functions as we want, reducing the number of symbols and size of the +/// object file. +class FreeFuncMatcherCreateCallback : public MatcherCreateCallback { +public: + typedef DynTypedMatcher *(*RunFunc)(StringRef MatcherName, + const SourceRange &NameRange, + ArrayRef Args, + Diagnostics *Error); + + FreeFuncMatcherCreateCallback(RunFunc Func, StringRef MatcherName) + : Func(Func), MatcherName(MatcherName.str()) {} + + DynTypedMatcher *run(const SourceRange &NameRange, ArrayRef Args, + Diagnostics *Error) const { + return Func(MatcherName, NameRange, Args, Error); + } + +private: + const RunFunc Func; + const std::string MatcherName; +}; /// \brief Helper macros to check the arguments on all marshaller functions. #define CHECK_ARG_COUNT(count) \ @@ -158,53 +187,60 @@ DynTypedMatcher *matcherMarshall2(ReturnType (*Func)(ArgType1, ArgType2), ArgTypeTraits::get(Args[1].Value)).clone(); } +#undef CHECK_ARG_COUNT +#undef CHECK_ARG_TYPE + /// \brief Variadic marshaller function. template -class VariadicMatcherCreateCallback : public MatcherCreateCallback { -public: - explicit VariadicMatcherCreateCallback(StringRef MatcherName) - : MatcherName(MatcherName.str()) {} - +DynTypedMatcher *VariadicMatcherCreateCallback(StringRef MatcherName, + const SourceRange &NameRange, + ArrayRef Args, + Diagnostics *Error) { typedef ast_matchers::internal::Matcher DerivedMatcherType; - - DynTypedMatcher *run(const SourceRange &NameRange, ArrayRef Args, - Diagnostics *Error) const { - std::list References; - std::vector InnerArgs(Args.size()); - for (size_t i = 0, e = Args.size(); i != e; ++i) { - CHECK_ARG_TYPE(i, DerivedMatcherType); - References.push_back( - ArgTypeTraits::get(Args[i].Value)); - InnerArgs[i] = &References.back(); + DerivedMatcherType **InnerArgs = new DerivedMatcherType *[Args.size()](); + + bool HasError = false; + for (size_t i = 0, e = Args.size(); i != e; ++i) { + if (!Args[i].Value.isTypedMatcher()) { + Error->pushErrorFrame(Args[i].Range, Error->ET_RegistryWrongArgType) + << MatcherName << (i + 1); + HasError = true; + break; } - return ast_matchers::internal::makeDynCastAllOfComposite( - ArrayRef(InnerArgs)).clone(); + InnerArgs[i] = + new DerivedMatcherType(Args[i].Value.getTypedMatcher()); } -private: - const std::string MatcherName; -}; + DynTypedMatcher *Out = NULL; + if (!HasError) { + Out = ast_matchers::internal::makeDynCastAllOfComposite( + ArrayRef(InnerArgs, Args.size())).clone(); + } -#undef CHECK_ARG_COUNT -#undef CHECK_ARG_TYPE + for (size_t i = 0, e = Args.size(); i != e; ++i) { + delete InnerArgs[i]; + } + delete[] InnerArgs; + return Out; +} /// Helper functions to select the appropriate marshaller functions. -/// They detects the number of arguments, arguments types and return type. +/// They detect the number of arguments, arguments types and return type. /// \brief 0-arg overload template MatcherCreateCallback *makeMatcherAutoMarshall(ReturnType (*Func)(), StringRef MatcherName) { - return createMarshallerCallback(matcherMarshall0, Func, - MatcherName); + return new FixedArgCountMatcherCreateCallback( + matcherMarshall0, Func, MatcherName); } /// \brief 1-arg overload template MatcherCreateCallback *makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1), StringRef MatcherName) { - return createMarshallerCallback(matcherMarshall1, Func, - MatcherName); + return new FixedArgCountMatcherCreateCallback( + matcherMarshall1, Func, MatcherName); } /// \brief 2-arg overload @@ -212,8 +248,8 @@ template MatcherCreateCallback *makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1, ArgType2), StringRef MatcherName) { - return createMarshallerCallback( - matcherMarshall2, Func, MatcherName); + return new FixedArgCountMatcherCreateCallback< + ReturnType (*)(ArgType1, ArgType2)>(matcherMarshall2, Func, MatcherName); } /// \brief Variadic overload. @@ -221,8 +257,8 @@ template MatcherCreateCallback *makeMatcherAutoMarshall( ast_matchers::internal::VariadicAllOfMatcher Func, StringRef MatcherName) { - return new VariadicMatcherCreateCallback( - MatcherName); + return new FreeFuncMatcherCreateCallback( + &VariadicMatcherCreateCallback, MatcherName); } template @@ -230,7 +266,8 @@ MatcherCreateCallback * makeMatcherAutoMarshall(ast_matchers::internal::VariadicDynCastAllOfMatcher< BaseType, MatcherType> Func, StringRef MatcherName) { - return new VariadicMatcherCreateCallback(MatcherName); + return new FreeFuncMatcherCreateCallback( + &VariadicMatcherCreateCallback, MatcherName); } } // namespace internal