diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2018-02-10 14:04:45 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2018-02-10 14:04:45 +0000 |
commit | c963abc492c42effaeea2dfc61d1177f08c3a44f (patch) | |
tree | c1efeacb5153a6b8ef2894ec8761c1110434c240 /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | 8d0b5771e42ee079be1cb3475a65af2220847a44 (diff) |
[Templight] Template Instantiation Observer
This patch adds a base-class called TemplateInstantiationObserver which gets
notified whenever a template instantiation is entered or exited during
semantic analysis. This is a base class used to implement the template
profiling and debugging tool called
Templight (https://github.com/mikael-s-persson/templight).
The patch also makes a few more changes:
* ActiveTemplateInstantiation class is moved out of the Sema class (so it can be used with inclusion of Sema.h).
* CreateFrontendAction function in front-end utilities is given external linkage (not longer a hidden static function).
* TemplateInstObserverChain data member added to Sema class to hold the list of template-inst observers.
* Notifications to the template-inst observer are added at the key places where templates are instantiated.
Patch by: Abel Sinkovics!
Differential Revision: https://reviews.llvm.org/D5767
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 313d99cf45..489d026027 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -25,6 +25,7 @@ #include "clang/Sema/PrettyDeclStackTrace.h" #include "clang/Sema/Template.h" #include "clang/Sema/TemplateDeduction.h" +#include "clang/Sema/TemplateInstCallback.h" using namespace clang; using namespace sema; @@ -199,6 +200,10 @@ bool Sema::CodeSynthesisContext::isInstantiationRecord() const { case DeclaringSpecialMember: case DefiningSynthesizedFunction: return false; + + // This function should never be called when Kind's value is Memoization. + case Memoization: + break; } llvm_unreachable("Invalid SynthesisKind!"); @@ -235,6 +240,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate( !SemaRef.InstantiatingSpecializations .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind)) .second; + atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); } } @@ -394,8 +400,10 @@ void Sema::InstantiatingTemplate::Clear() { std::make_pair(Active.Entity, Active.Kind)); } - SemaRef.popCodeSynthesisContext(); + atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, + SemaRef.CodeSynthesisContexts.back()); + SemaRef.popCodeSynthesisContext(); Invalid = true; } } @@ -626,7 +634,7 @@ void Sema::PrintInstantiationStack() { << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; break; - case CodeSynthesisContext::DefiningSynthesizedFunction: + case CodeSynthesisContext::DefiningSynthesizedFunction: { // FIXME: For synthesized members other than special members, produce a note. auto *MD = dyn_cast<CXXMethodDecl>(Active->Entity); auto CSM = MD ? getSpecialMember(MD) : CXXInvalid; @@ -637,6 +645,10 @@ void Sema::PrintInstantiationStack() { } break; } + + case CodeSynthesisContext::Memoization: + break; + } } } @@ -682,6 +694,9 @@ Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { // This happens in a context unrelated to template instantiation, so // there is no SFINAE. return None; + + case CodeSynthesisContext::Memoization: + break; } // The inner context was transparent for SFINAE. If it occurred within a |