r226211 - Use a trivial comdat for inline ctor/dtor when not using C5/D5.
Rafael Espindola
rafael.espindola at gmail.com
Thu Jan 15 13:36:08 PST 2015
Author: rafael
Date: Thu Jan 15 15:36:08 2015
New Revision: 226211
URL: http://llvm.org/viewvc/llvm-project?rev=226211&view=rev
Log:
Use a trivial comdat for inline ctor/dtor when not using C5/D5.
When combined with llvm not producing implicit comdats, not doing this would
cause code bloat on ELF and link errors on COFF.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=226211&r1=226210&r2=226211&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jan 15 15:36:08 2015
@@ -1953,6 +1953,13 @@ static bool shouldBeInCOMDAT(CodeGenModu
llvm_unreachable("No such linkage");
}
+void CodeGenModule::maybeSetTrivialComdat(const Decl &D,
+ llvm::GlobalObject &GO) {
+ if (!shouldBeInCOMDAT(*this, D))
+ return;
+ GO.setComdat(TheModule.getOrInsertComdat(GO.getName()));
+}
+
void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
llvm::Constant *Init = nullptr;
QualType ASTTy = D->getType();
@@ -2096,8 +2103,7 @@ void CodeGenModule::EmitGlobalVarDefinit
setTLSMode(GV, *D);
}
- if (shouldBeInCOMDAT(*this, *D))
- GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
+ maybeSetTrivialComdat(*D, *GV);
// Emit the initializer function if necessary.
if (NeedsGlobalCtor || NeedsGlobalDtor)
@@ -2433,8 +2439,7 @@ void CodeGenModule::EmitGlobalFunctionDe
MaybeHandleStaticInExternC(D, Fn);
- if (shouldBeInCOMDAT(*this, *D))
- Fn->setComdat(TheModule.getOrInsertComdat(Fn->getName()));
+ maybeSetTrivialComdat(*D, *Fn);
CodeGenFunction(*this).GenerateCode(D, Fn, FI);
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=226211&r1=226210&r2=226211&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Jan 15 15:36:08 2015
@@ -606,6 +606,7 @@ public:
const TargetInfo &getTarget() const { return Target; }
const llvm::Triple &getTriple() const;
bool supportsCOMDAT() const;
+ void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
CGCXXABI &getCXXABI() const { return *ABI; }
llvm::LLVMContext &getLLVMContext() { return VMContext; }
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=226211&r1=226210&r2=226211&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Jan 15 15:36:08 2015
@@ -3202,5 +3202,7 @@ void ItaniumCXXABI::emitCXXStructor(cons
getMangleContext().mangleCXXCtorComdat(CD, Out);
llvm::Comdat *C = CGM.getModule().getOrInsertComdat(Out.str());
Fn->setComdat(C);
+ } else {
+ CGM.maybeSetTrivialComdat(*MD, *Fn);
}
}
Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=226211&r1=226210&r2=226211&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Thu Jan 15 15:36:08 2015
@@ -22,7 +22,10 @@ namespace test1 {
// CHECK1-NOT: comdat
// COFF doesn't support comdats with arbitrary names (C5/D5).
-// COFF-NOT: comdat
+// COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC2Ev({{.*}} comdat align
+// COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC1Ev({{.*}} comdat align
+// COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvED2Ev({{.*}} comdat align
+// COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvED0Ev({{.*}} comdat align
template <typename T>
struct foobar {
@@ -39,7 +42,7 @@ namespace test2 {
// CHECK1: define internal void @__cxx_global_var_init()
// CHECK1: call void @_ZN5test26foobarIvEC2Ev
-// CHECK1: define linkonce_odr void @_ZN5test26foobarIvEC2Ev(
+// CHECK1: define linkonce_odr void @_ZN5test26foobarIvEC2Ev({{.*}} comdat align
void g();
template <typename T> struct foobar {
foobar() { g(); }
@@ -72,13 +75,13 @@ namespace test4 {
// CHECK1: define internal void @__cxx_global_var_init2()
// CHECK1: call i32 @__cxa_atexit{{.*}}_ZN5test41AD2Ev
- // CHECK1: define linkonce_odr void @_ZN5test41AD2Ev(
+ // CHECK1: define linkonce_odr void @_ZN5test41AD2Ev({{.*}} comdat align
// test that we don't do this optimization at -O0 so that the debugger can
// see both destructors.
// NOOPT: define internal void @__cxx_global_var_init2()
// NOOPT: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD2Ev
- // NOOPT: define linkonce_odr void @_ZN5test41BD2Ev
+ // NOOPT: define linkonce_odr void @_ZN5test41BD2Ev({{.*}} comdat align
struct A {
virtual ~A() {}
};
@@ -93,7 +96,7 @@ namespace test5 {
// CHECK2: define internal void @__cxx_global_var_init3()
// CHECK2: call i32 @__cxa_atexit{{.*}}_ZN5test51AD2Ev
- // CHECK2: define linkonce_odr void @_ZN5test51AD2Ev(
+ // CHECK2: define linkonce_odr void @_ZN5test51AD2Ev({{.*}} comdat align
struct A {
virtual ~A() {}
};
More information about the cfe-commits
mailing list