Skip to content

Commit

Permalink
Merge branch 'master' into division-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev authored May 8, 2024
2 parents e7558ca + 69a2d0c commit 8f882c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ charset-normalizer==3.1.0
docutils==0.20.1
idna==3.7
imagesize==1.4.1
Jinja2==3.1.3
Jinja2==3.1.4
MarkupSafe==2.1.3
packaging==23.1
Pygments==2.15.1
Expand Down
9 changes: 8 additions & 1 deletion tools/ClangPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ namespace clad {
SetRequestOptions(opts);
DiffCollector collector(DGR, CladEnabledRange, m_DiffRequestGraph, S,
opts);
// We could not delay the processing of derivatives, inform act as if each
// call is final. That would still have vgvassilev/clad#248 unresolved.
if (!m_Multiplexer)
FinalizeTranslationUnit();
}

FunctionDecl* CladPlugin::ProcessDiffRequest(DiffRequest& request) {
Expand Down Expand Up @@ -394,7 +398,7 @@ namespace clad {
SetTBRAnalysisOptions(m_DO, opts);
}

void CladPlugin::HandleTranslationUnit(ASTContext& C) {
void CladPlugin::FinalizeTranslationUnit() {
Sema& S = m_CI.getSema();
// Restore the TUScope that became a 0 in Sema::ActOnEndOfTranslationUnit.
if (!m_CI.getPreprocessor().isIncrementalProcessingEnabled())
Expand All @@ -418,7 +422,10 @@ namespace clad {
// Force emission of the produced pending template instantiations.
LocalInstantiations.perform();
GlobalInstantiations.perform();
}

void CladPlugin::HandleTranslationUnit(ASTContext& C) {
FinalizeTranslationUnit();
SendToMultiplexer();
m_Multiplexer->HandleTranslationUnit(C);
}
Expand Down
14 changes: 14 additions & 0 deletions tools/ClangPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Timer.h"

namespace clang {
Expand Down Expand Up @@ -167,6 +168,14 @@ class CladTimerGroup {
AppendDelayed({CallKind::HandleCXXStaticMemberVarInstantiation, D});
}
bool HandleTopLevelDecl(clang::DeclGroupRef D) override {
if (D.isSingleDecl())
if (auto* FD = llvm::dyn_cast<clang::FunctionDecl>(D.getSingleDecl()))
if (m_DFC.IsDerivative(FD)) {
assert(!m_Multiplexer &&
"Must happen only if we failed to rearrange the consumers");
return true;
}

HandleTopLevelDeclForClad(D);
AppendDelayed({CallKind::HandleTopLevelDecl, D});
return true; // happyness, continue parsing
Expand Down Expand Up @@ -250,6 +259,7 @@ class CladTimerGroup {
"Must start from index 0!");
m_DelayedCalls.push_back(DCI);
}
void FinalizeTranslationUnit();
void SendToMultiplexer();
bool CheckBuiltins();
void SetRequestOptions(RequestOptions& opts) const;
Expand All @@ -258,6 +268,10 @@ class CladTimerGroup {
DelayedCallInfo DCI{CallKind::HandleTopLevelDecl, D};
assert(!llvm::is_contained(m_DelayedCalls, DCI) && "Already exists!");
AppendDelayed(DCI);
// We could not delay the process due to some strange way of
// initialization, inform the consumers now.
if (!m_Multiplexer)
m_CI.getASTConsumer().HandleTopLevelDecl(DCI.m_DGR);
}
void HandleTopLevelDeclForClad(clang::DeclGroupRef DGR);
};
Expand Down

0 comments on commit 8f882c1

Please sign in to comment.