<div dir="ltr"><div class="gmail_extra">They're intended for use by OpenMP, but I think the CodeGen parts of that haven't quite landed yet. In the mean time, the pragma you found is a good way to get test coverage here. Thanks!<br>
<br><div class="gmail_quote">On Mon, Apr 14, 2014 at 6:00 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Good catch! Turns out CapturedStmt wasn't being handled *at all* by<br>
instrumentation based profiling. I've fixed that in r206231.<br>
<br>
On that note, what are CapturedStmts for? Is the test in r206231<br>
sufficient?<br>
<div><div><br>
Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> writes:<br>
> Should we do the same for CapturedStmt?<br>
><br>
> On 11 Apr 2014 16:14, "Justin Bogner" <<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>> wrote:<br>
><br>
> Author: bogner<br>
> Date: Fri Apr 11 18:06:35 2014<br>
> New Revision: 206081<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=206081&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=206081&view=rev</a><br>
> Log:<br>
> CodeGen: Fix handling of C++11 lambdas in profiling<br>
><br>
> Until now we were generating duplicate counters for lambdas: one set<br>
> in the function where the lambda was declared and another for the<br>
> lambda itself. Instead, we should skip over the bodies of lambdas in<br>
> their containing contexts.<br>
><br>
> Added:<br>
> cfe/trunk/test/Profile/Inputs/cxx-lambda.profdata<br>
> cfe/trunk/test/Profile/cxx-lambda.cpp<br>
> Modified:<br>
> cfe/trunk/lib/CodeGen/CodeGenPGO.cpp<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/</a><br>
> CodeGenPGO.cpp?rev=206081&r1=206080&r2=206081&view=diff<br>
> ==========================================================================<br>
> ====<br>
> --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Fri Apr 11 18:06:35 2014<br>
> @@ -331,9 +331,10 @@ namespace {<br>
> MapRegionCounters(llvm::DenseMap<const Stmt *, unsigned> &CounterMap)<br>
> : NextCounter(0), CounterMap(CounterMap) {}<br>
><br>
> - // Do not traverse the BlockDecl inside a BlockExpr since each<br>
> BlockDecl<br>
> - // is handled as a separate function.<br>
> - bool TraverseBlockExpr(BlockExpr *block) { return true; }<br>
> + // Blocks and lambdas are handled as separate functions, so we need<br>
> not<br>
> + // traverse them in the parent context.<br>
> + bool TraverseBlockExpr(BlockExpr *BE) { return true; }<br>
> + bool TraverseLambdaBody(LambdaExpr *LE) { return true; }<br>
><br>
> bool VisitDecl(const Decl *D) {<br>
> switch (D->getKind()) {<br>
> @@ -431,6 +432,11 @@ namespace {<br>
> Visit(D->getBody());<br>
> }<br>
><br>
> + // Skip lambda expressions. We visit these as FunctionDecls when<br>
> we're<br>
> + // generating them and aren't interested in the body when generating<br>
> a<br>
> + // parent context.<br>
> + void VisitLambdaExpr(const LambdaExpr *LE) {}<br>
> +<br>
> void VisitObjCMethodDecl(const ObjCMethodDecl *D) {<br>
> // Counter tracks entry to the method body.<br>
> RegionCounter Cnt(PGO, D->getBody());<br>
><br>
> Added: cfe/trunk/test/Profile/Inputs/cxx-lambda.profdata<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/</a><br>
> cxx-lambda.profdata?rev=206081&view=auto<br>
> ==========================================================================<br>
> ====<br>
> --- cfe/trunk/test/Profile/Inputs/cxx-lambda.profdata (added)<br>
> +++ cfe/trunk/test/Profile/Inputs/cxx-lambda.profdata Fri Apr 11 18:06:35<br>
> 2014<br>
> @@ -0,0 +1,20 @@<br>
> +cxx-lambda.cpp:_ZZ7lambdasvENK3$_0clEi<br>
> +3<br>
> +3<br>
> +10<br>
> +9<br>
> +9<br>
> +<br>
> +main<br>
> +1<br>
> +1<br>
> +1<br>
> +<br>
> +_Z7lambdasv<br>
> +4<br>
> +4<br>
> +1<br>
> +1<br>
> +10<br>
> +1<br>
> +<br>
><br>
> Added: cfe/trunk/test/Profile/cxx-lambda.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/</a><br>
> cxx-lambda.cpp?rev=206081&view=auto<br>
> ==========================================================================<br>
> ====<br>
> --- cfe/trunk/test/Profile/cxx-lambda.cpp (added)<br>
> +++ cfe/trunk/test/Profile/cxx-lambda.cpp Fri Apr 11 18:06:35 2014<br>
> @@ -0,0 +1,57 @@<br>
> +// Tests for instrumentation of C++11 lambdas<br>
> +<br>
> +// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name<br>
> cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-generate > %tgen<br>
> +// RUN: FileCheck --input-file=%tgen -check-prefix=PGOGEN %s<br>
> +// RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s<br>
> +<br>
> +// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name<br>
> cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%S/Inputs/<br>
> cxx-lambda.profdata > %tuse<br>
> +// RUN: FileCheck --input-file=%tuse -check-prefix=PGOUSE %s<br>
> +// RUN: FileCheck --input-file=%tuse -check-prefix=LMBUSE %s<br>
> +<br>
> +// PGOGEN: @[[LWC:__llvm_profile_counters__Z7lambdasv]] = global [4 x<br>
> i64] zeroinitializer<br>
> +// PGOGEN: @[[MAC:__llvm_profile_counters_main]] = global [1 x i64]<br>
> zeroinitializer<br>
> +// LMBGEN: @[[LFC:"__llvm_profile_counters__ZZ7lambdasvENK3\$_0clEi"]] =<br>
> internal global [3 x i64] zeroinitializer<br>
> +<br>
> +// PGOGEN-LABEL: define void @_Z7lambdasv()<br>
> +// PGOUSE-LABEL: define void @_Z7lambdasv()<br>
> +// PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 0<br>
> +void lambdas() {<br>
> + int i = 1;<br>
> +<br>
> + // LMBGEN-LABEL: define internal zeroext i1 @"_ZZ7lambdasvENK3$_0clEi"(<br>
> + // LMBUSE-LABEL: define internal zeroext i1 @"_ZZ7lambdasvENK3$_0clEi"(<br>
> + // LMBGEN: store {{.*}} @[[LFC]], i64 0, i64 0<br>
> + auto f = [&i](int k) {<br>
> + // LMBGEN: store {{.*}} @[[LFC]], i64 0, i64 1<br>
> + // LMBUSE: br {{.*}} !prof ![[LF1:[0-9]+]]<br>
> + if (i > 0) {}<br>
> + // LMBGEN: store {{.*}} @[[LFC]], i64 0, i64 2<br>
> + // LMBUSE: br {{.*}} !prof ![[LF2:[0-9]+]]<br>
> + return k && i;<br>
> + };<br>
> +<br>
> + // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 1<br>
> + // PGOUSE: br {{.*}} !prof ![[LW1:[0-9]+]]<br>
> + if (i) {}<br>
> +<br>
> + // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 2<br>
> + // PGOUSE: br {{.*}} !prof ![[LW2:[0-9]+]]<br>
> + for (i = 0; i < 10; ++i)<br>
> + f(9 - i);<br>
> +<br>
> + // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 3<br>
> + // PGOUSE: br {{.*}} !prof ![[LW3:[0-9]+]]<br>
> + if (i) {}<br>
> +}<br>
> +<br>
> +// PGOUSE-DAG: ![[LW1]] = metadata !{metadata !"branch_weights", i32 2,<br>
> i32 1}<br>
> +// PGOUSE-DAG: ![[LW2]] = metadata !{metadata !"branch_weights", i32 11,<br>
> i32 2}<br>
> +// PGOUSE-DAG: ![[LW3]] = metadata !{metadata !"branch_weights", i32 2,<br>
> i32 1}<br>
> +<br>
> +// LMBUSE-DAG: ![[LF1]] = metadata !{metadata !"branch_weights", i32 10,<br>
> i32 2}<br>
> +// LMBUSE-DAG: ![[LF2]] = metadata !{metadata !"branch_weights", i32 10,<br>
> i32 2}<br>
> +<br>
> +int main(int argc, const char *argv[]) {<br>
> + lambdas();<br>
> + return 0;<br>
> +}<br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>