================
@@ -1224,6 +1225,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclOrFunctionDefInternal(
 Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition(
     ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs,
     ParsingDeclSpec *DS, AccessSpecifier AS) {
+  // Add an enclosing time trace scope for a bunch of small scopes with
+  // "EvaluateAsConstExpr".
+  llvm::TimeTraceScope TimeScope("ParseDeclarationOrFunctionDefinition");
----------------
MaggieYingYi wrote:
Hi @AaronBallman ,

Many thanks for your suggestions.

> Should we supply a second argument to the ctor here so that we can include 
> the function name as part of the time trace output?

Good point. I cannot add `function name` as a second argument in the 
`Parser::ParseDeclarationOrFunctionDefinition()` since the function 
definition/declaration is not parsed yet. However, as you suggested, I have 
added a new time trace variable to `Parser::ParseFunctionDefinition()` and 
included the function name as a part of the time trace output in the commit 
https://github.com/llvm/llvm-project/pull/65268/commits/deecf8c2.

> Also, I wonder if we want more or less granularity here. This will fire for 
> function declarations and function definitions, so we could add it to 
> `Parser::ParseFunctionDefinition()` instead to only time function definition 
> parsing, or we could split it up so that we time parsing function signatures 
> separately from parsing the function body so we can more easily see how much 
> time is spent in which activity.

As mentioned above, I have added a new time trace variable of 
`ParseFunctionDefinition`. However, I cannot remove the time trace variable of 
"ParseDeclarationOrFunctionDefinition" since `ParseFunctionDefinition` doesn't 
enclose small time scopes (named EvaluateAsConstExpr) in the function 
declarations. The initial issue is shown in the function declarations (not 
function definitions).

I will use a simple test to show the issue.

1. Source file test.cpp:
```
$ cat test.cpp
consteval double slow_func() {
    double d = 0.0;
    for (int i = 0; i < 100; ++i) {
        d += i;
    }
    return d;
}

void slow_test() {
    constexpr auto slow_value = slow_func();
}

int slow_arr[12 + 34 * 56 + static_cast<int>(slow_func())];
```

2. Compile test.cpp using the clang which is built using the repo of 
yingyi/main/time-trace:
```
$ clang.exe -ftime-trace -ftime-trace-granularity=0  -std=c++20 test.cpp -c -o 
test.o
```

3. View the generated time-trace file of test.json using `chrome://tracing/`.

For `slow_arr`, it uses the `slow_func()` declaration. `EvaluateAsConstantExpr` 
is under the time scope of `ParseDeclarationOrFunctionDefinition` but not under 
the time scope of `ParseFunctionDefinition`.

Therefore, I think we need both time scope variables of 
`ParseDeclarationOrFunctionDefinition` and 
`ParseFunctionDefinition`.

https://github.com/llvm/llvm-project/pull/65268
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to