[PATCH] D136022: [clang] Add time profile for constant evaluation

Evgeny Shulgin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 15 10:25:10 PDT 2022


Izaron created this revision.
Izaron added reviewers: aaron.ballman, cor3ntin, anton-afanasyev, mbs-modular, jloser.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add time profiler for various constexpr evaluation events
so that slow event could be visible on the visualized flame chart.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136022

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -55,6 +55,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/TypeSize.h"
 
 using namespace clang;
@@ -17538,8 +17539,14 @@
   Expr::EvalResult Eval;
   Eval.Diag = &Notes;
   ConstantExpr *CE = Candidate.getPointer();
-  bool Result = CE->EvaluateAsConstantExpr(
-      Eval, SemaRef.getASTContext(), ConstantExprKind::ImmediateInvocation);
+  bool Result;
+  {
+    llvm::TimeTraceScope TimeScope("EvaluateAsConstantExpr", [&] {
+      return CE->getSourceRange().printToString(SemaRef.getSourceManager());
+    });
+    Result = CE->EvaluateAsConstantExpr(Eval, SemaRef.getASTContext(),
+                                        ConstantExprKind::ImmediateInvocation);
+  }
   if (!Result || !Notes.empty()) {
     Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit();
     if (auto *FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr))
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -41,10 +41,11 @@
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/TimeProfiler.h"
 #include <map>
 #include <set>
 
@@ -1736,6 +1737,14 @@
 // This implements C++11 [dcl.constexpr]p3,4, as amended by DR1360.
 bool Sema::CheckConstexprFunctionDefinition(const FunctionDecl *NewFD,
                                             CheckConstexprKind Kind) {
+  llvm::TimeTraceScope TimeScope("CheckConstexprFunctionDefinition", [&] {
+    std::string Name;
+    llvm::raw_string_ostream OS(Name);
+    NewFD->getNameForDiagnostic(OS, Context.getPrintingPolicy(),
+                                /*Qualified=*/true);
+    return Name;
+  });
+
   const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD);
   if (MD && MD->isInstance()) {
     // C++11 [dcl.constexpr]p4:
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -56,6 +56,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstring>
 #include <functional>
@@ -15247,6 +15248,13 @@
   assert(!isValueDependent() &&
          "Expression evaluator can't be called on a dependent expression.");
 
+  llvm::TimeTraceScope TimeScope("EvaluateAsInitializer", [&] {
+    std::string Name;
+    llvm::raw_string_ostream OS(Name);
+    VD->printQualifiedName(OS);
+    return Name;
+  });
+
   // FIXME: Evaluating initializers for large array and record types can cause
   // performance problems. Only do so in C++11 for now.
   if (isPRValue() && (getType()->isArrayType() || getType()->isRecordType()) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136022.468028.patch
Type: text/x-patch
Size: 3319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221015/f048724d/attachment.bin>


More information about the cfe-commits mailing list