Skip to content

Commit

Permalink
fix formatting and replace m_PrintTimings with TimePasses
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadSpheroid committed Feb 20, 2024
1 parent ec56e48 commit d6aa1d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
20 changes: 6 additions & 14 deletions tools/ClangPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,9 @@ namespace clad {
};

CladPlugin::CladPlugin(CompilerInstance& CI, DifferentiationOptions& DO)
: m_CI(CI), m_DO(DO), m_HasRuntime(false), m_TG("Clad timers", "Timers for clad funcs"){
: m_CI(CI), m_DO(DO), m_HasRuntime(false),
m_TG("Clad timers", "Timers for clad funcs") {
#if CLANG_VERSION_MAJOR > 8
const clang::CommentOptions::BlockCommandNamesTy cmdargs = m_CI.getCodeGenOpts().CommandLineArgs;
for(const std::string &arg: cmdargs){
if(arg == "-ftime-report") {
m_PrintTimings = true;
break;
}
}
FrontendOptions& Opts = CI.getFrontendOpts();
// Find the path to clad.
llvm::StringRef CladSoPath;
Expand Down Expand Up @@ -166,7 +160,8 @@ namespace clad {
m_PendingInstantiationsInFlight = false;
}
// Necessary to prevent separate timing reports due to expired timers
llvm::Timer dummy("Dummy timer", "Prevent premature printing of timings", m_TG);
llvm::Timer dummy("Dummy timer", "Prevent premature printing of timings",
m_TG);
for (DiffRequest& request : requests)
ProcessDiffRequest(request);
return true; // Happiness
Expand Down Expand Up @@ -247,19 +242,16 @@ namespace clad {
} else {
// Only time the function when it is first encountered
llvm::Timer tm("Clad timer", request.BaseFunctionName, m_TG);
if(m_PrintTimings && !tm.isRunning()){
if (m_CI.getCodeGenOpts().TimePasses && !tm.isRunning())
tm.startTimer();
}
auto deriveResult = m_DerivativeBuilder->Derive(request);
DerivativeDecl = deriveResult.derivative;
OverloadedDerivativeDecl = deriveResult.overload;
if(m_PrintTimings && tm.isRunning()){
if (tm.isRunning())
tm.stopTimer();
}
}
}


if (DerivativeDecl) {
if (!alreadyDerived) {
m_DFC.Add(
Expand Down
3 changes: 1 addition & 2 deletions tools/ClangPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "clang/Basic/Version.h"
#include "clang/Frontend/FrontendPluginRegistry.h"

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

namespace clang {
Expand Down Expand Up @@ -90,7 +90,6 @@ namespace clad {
bool m_HasRuntime = false;
bool m_PendingInstantiationsInFlight = false;
bool m_HandleTopLevelDeclInternal = false;
bool m_PrintTimings = false;
llvm::TimerGroup m_TG;
DerivedFnCollector m_DFC;
public:
Expand Down

0 comments on commit d6aa1d1

Please sign in to comment.