diff options
author | Vedant Kumar <vsk@apple.com> | 2017-02-24 01:15:19 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-02-24 01:15:19 +0000 |
commit | 9970e5fa39d67048aeaf8b52b3479acde3ee4ecb (patch) | |
tree | 8697873450ff0b6b5e7635008bbeefec38ff202c | |
parent | 9049fa85ca1df4c5e6468a8ae2f70e4ae5e25a25 (diff) |
[profiling] PR31992: Don't skip interesting non-base constructors
Fix the fact that we don't assign profile counters to constructors in
classes with virtual bases, or constructors with variadic parameters.
Differential Revision: https://reviews.llvm.org/D30131
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296062 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGClass.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 2 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenPGO.cpp | 12 | ||||
-rw-r--r-- | test/Profile/Inputs/cxx-class.proftext | 11 | ||||
-rw-r--r-- | test/Profile/cxx-class.cpp | 36 | ||||
-rw-r--r-- | test/Profile/cxx-structors.cpp | 16 |
6 files changed, 74 insertions, 6 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index a305ae62ca..dce1e817d0 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -689,7 +689,8 @@ void CodeGenFunction::EmitInitializerForField(FieldDecl *Field, LValue LHS, /// complete-to-base constructor delegation optimization, i.e. /// emitting the complete constructor as a simple call to the base /// constructor. -static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor) { +bool CodeGenFunction::IsConstructorDelegationValid( + const CXXConstructorDecl *Ctor) { // Currently we disable the optimization for classes with virtual // bases because (1) the addresses of parameter variables need to be diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 3bb80887a4..72105802b4 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1564,6 +1564,8 @@ public: SourceLocation Loc = SourceLocation(), SourceLocation StartLoc = SourceLocation()); + static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor); + void EmitConstructorBody(FunctionArgList &Args); void EmitDestructorBody(FunctionArgList &Args); void emitImplicitAssignmentOperatorBody(FunctionArgList &Args); diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 3d3a0cce2a..530ee9b4e9 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -626,10 +626,14 @@ void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) { // Constructors and destructors may be represented by several functions in IR. // If so, instrument only base variant, others are implemented by delegation // to the base one, it would be counted twice otherwise. - if (CGM.getTarget().getCXXABI().hasConstructorVariants() && - ((isa<CXXConstructorDecl>(D) && GD.getCtorType() != Ctor_Base) || - (isa<CXXDestructorDecl>(D) && GD.getDtorType() != Dtor_Base))) { - return; + if (CGM.getTarget().getCXXABI().hasConstructorVariants()) { + if (isa<CXXDestructorDecl>(D) && GD.getDtorType() != Dtor_Base) + return; + + if (const auto *CCD = dyn_cast<CXXConstructorDecl>(D)) + if (GD.getCtorType() != Ctor_Base && + CodeGenFunction::IsConstructorDelegationValid(CCD)) + return; } CGM.ClearUnusedCoverageMapping(D); setFuncName(Fn); diff --git a/test/Profile/Inputs/cxx-class.proftext b/test/Profile/Inputs/cxx-class.proftext index b4645edf93..77645fbc20 100644 --- a/test/Profile/Inputs/cxx-class.proftext +++ b/test/Profile/Inputs/cxx-class.proftext @@ -39,3 +39,14 @@ _ZN6SimpleC2Ei 100 99 +_ZN7DerivedC1Ev +10 +2 +100 +99 + +_ZN7DerivedD2Ev +10 +2 +100 +99 diff --git a/test/Profile/cxx-class.cpp b/test/Profile/cxx-class.cpp index dbc9337785..ab90d195cd 100644 --- a/test/Profile/cxx-class.cpp +++ b/test/Profile/cxx-class.cpp @@ -5,6 +5,8 @@ // RUN: FileCheck --input-file=%tgen -check-prefix=DTRGEN %s // RUN: FileCheck --input-file=%tgen -check-prefix=MTHGEN %s // RUN: FileCheck --input-file=%tgen -check-prefix=WRPGEN %s +// RUN: FileCheck --input-file=%tgen -check-prefix=VCTRGEN %s +// RUN: FileCheck --input-file=%tgen -check-prefix=VDTRGEN %s // RUN: llvm-profdata merge %S/Inputs/cxx-class.proftext -o %t.profdata // RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -triple %itanium_abi_triple > %tuse @@ -12,10 +14,12 @@ // RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s // RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s // RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s +// RUN: FileCheck --input-file=%tuse -check-prefix=VCTRUSE %s +// RUN: FileCheck --input-file=%tuse -check-prefix=VDTRUSE %s class Simple { - int Member; public: + int Member; // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei( // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei( // CTRGEN: store {{.*}} @[[SCC:__profc__ZN6SimpleC2Ei]], i64 0, i64 0 @@ -56,6 +60,35 @@ public: // MTHUSE: ![[SM1]] = !{!"branch_weights", i32 100, i32 2} }; +class Derived : virtual public Simple { +public: + // VCTRGEN-LABEL: define {{.*}} @_ZN7DerivedC1Ev( + // VCTRUSE-LABEL: define {{.*}} @_ZN7DerivedC1Ev( + // VCTRGEN: store {{.*}} @[[SCC:__profc__ZN7DerivedC1Ev]], i64 0, i64 0 + Derived() : Simple(0) { + // VCTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1 + // VCTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]] + if (Member) {} + // VCTRGEN-NOT: store {{.*}} @[[SCC]], + // VCTRUSE-NOT: br {{.*}} !prof ![0-9]+ + // VCTRUSE: ret + } + // VCTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2} + + // VDTRGEN-LABEL: define {{.*}} @_ZN7DerivedD2Ev( + // VDTRUSE-LABEL: define {{.*}} @_ZN7DerivedD2Ev( + // VDTRGEN: store {{.*}} @[[SDC:__profc__ZN7DerivedD2Ev]], i64 0, i64 0 + ~Derived() { + // VDTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1 + // VDTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]] + if (Member) {} + // VDTRGEN-NOT: store {{.*}} @[[SDC]], + // VDTRUSE-NOT: br {{.*}} !prof ![0-9]+ + // VDTRUSE: ret + } + // VDTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2} +}; + // WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv( // WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv( // WRPGEN: store {{.*}} @[[SWC:__profc__Z14simple_wrapperv]], i64 0, i64 0 @@ -63,6 +96,7 @@ void simple_wrapper() { // WRPGEN: store {{.*}} @[[SWC]], i64 0, i64 1 // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]] for (int I = 0; I < 100; ++I) { + Derived d; Simple S(I); S.method(); } diff --git a/test/Profile/cxx-structors.cpp b/test/Profile/cxx-structors.cpp index 578fc308bc..8e0fac163d 100644 --- a/test/Profile/cxx-structors.cpp +++ b/test/Profile/cxx-structors.cpp @@ -16,12 +16,28 @@ struct Bar : public Foo { ~Bar(); }; +struct Baz : virtual public Foo { + Baz() {} + Baz(int x) : Foo(x) {} + ~Baz(); +}; + +struct Quux : public Foo { + Quux(const char *y, ...) : Foo(0) {} +}; + Foo foo; Foo foo2(1); Bar bar; +Baz baz; +Baz baz2(1); +Quux qux("fi", "fo", "fum"); // Profile data for complete constructors and destructors must absent. +// INSTR: @__profc__ZN3BazC1Ev = +// INSTR: @__profc__ZN3BazC1Ei = +// INSTR: @__profc__ZN4QuuxC1EPKcz = // INSTR: @__profc_main = // INSTR: @__profc__ZN3FooC2Ev = // INSTR: @__profc__ZN3FooD2Ev = |