diff options
author | George Rokos <grokos@us.ibm.com> | 2017-05-27 03:03:13 +0000 |
---|---|---|
committer | George Rokos <grokos@us.ibm.com> | 2017-05-27 03:03:13 +0000 |
commit | 29d0f003403fe8289f776d81e0965a93cd0b1670 (patch) | |
tree | 05d17c8e2524309bdb8670573e140b5be576af68 /clang/lib/CodeGen | |
parent | 868bbd40226d6bd9d909e3ae3645e580ff9e2352 (diff) | |
download | bcm5719-llvm-29d0f003403fe8289f776d81e0965a93cd0b1670.tar.gz bcm5719-llvm-29d0f003403fe8289f776d81e0965a93cd0b1670.zip |
[OpenMP] Create COMDAT group for OpenMP offload registration code to avoid multiple copies
Thanks to Sergey Dmitriev for submitting the patch.
Differential Revision: https://reviews.llvm.org/D33509
llvm-svn: 304056
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 13 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 7 |
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 601d662e55e..0644d1b2834 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -2903,6 +2903,19 @@ CGOpenMPRuntime::createOffloadingBinaryDescriptorRegistration() { Desc); CGM.getCXXABI().registerGlobalDtor(CGF, RegUnregVar, UnRegFn, Desc); }); + if (CGM.supportsCOMDAT()) { + // It is sufficient to call registration function only once, so create a + // COMDAT group for registration/unregistration functions and associated + // data. That would reduce startup time and code size. Registration + // function serves as a COMDAT group key. + auto ComdatKey = M.getOrInsertComdat(RegFn->getName()); + RegFn->setLinkage(llvm::GlobalValue::LinkOnceAnyLinkage); + RegFn->setVisibility(llvm::GlobalValue::HiddenVisibility); + RegFn->setComdat(ComdatKey); + UnRegFn->setComdat(ComdatKey); + DeviceImages->setComdat(ComdatKey); + Desc->setComdat(ComdatKey); + } return RegFn; } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index db8f8d32abb..ffbcbfcc291 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -400,8 +400,11 @@ void CodeGenModule::Release() { } if (OpenMPRuntime) if (llvm::Function *OpenMPRegistrationFunction = - OpenMPRuntime->emitRegistrationFunction()) - AddGlobalCtor(OpenMPRegistrationFunction, 0); + OpenMPRuntime->emitRegistrationFunction()) { + auto ComdatKey = OpenMPRegistrationFunction->hasComdat() ? + OpenMPRegistrationFunction : nullptr; + AddGlobalCtor(OpenMPRegistrationFunction, 0, ComdatKey); + } if (PGOReader) { getModule().setProfileSummary(PGOReader->getSummary().getMD(VMContext)); if (PGOStats.hasDiagnostics()) |