summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-05-21 11:47:45 +0000
committerPavel Labath <labath@google.com>2018-05-21 11:47:45 +0000
commitb3b0255df97c28731eb000c766bf79c30b760b49 (patch)
tree4ae7eda8e907f17962084d69166d65fe24a5c5ec /clang/lib/CodeGen
parente4a12cfa2fa77bfe2bca79823d75f2f4ddcecb8c (diff)
downloadbcm5719-llvm-b3b0255df97c28731eb000c766bf79c30b760b49.tar.gz
bcm5719-llvm-b3b0255df97c28731eb000c766bf79c30b760b49.zip
[CodeGen] Disable aggressive structor optimizations at -O0, take 2
The first version of the patch (r332228) was flawed because it was putting structors into C5/D5 comdats very eagerly. This is correct only if we can ensure the comdat contains all required versions of the structor (which wasn't the case). This version uses a more nuanced approach: - for local structor symbols we use an alias because we don't have to worry about comdats or other compilation units. - linkonce symbols are emitted separately, as we cannot guarantee we will have all symbols we need to form a comdat (they are emitted lazily, only when referenced). - available_externally symbols are also emitted separately, as the code seemed to be worried about emitting an alias in this case. - other linkage types are not affected by the optimization level. They either get put into a comdat (weak) or get aliased (external). Reviewers: rjmccall, aprantl Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46685 llvm-svn: 332839
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index c77644b56a5..0374e4cf9ac 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3628,12 +3628,22 @@ static StructorCodegen getCodegenToUse(CodeGenModule &CGM,
}
llvm::GlobalValue::LinkageTypes Linkage = CGM.getFunctionLinkage(AliasDecl);
- if (llvm::GlobalValue::isDiscardableIfUnused(Linkage))
- return StructorCodegen::RAUW;
-
+ // All discardable structors can be RAUWed, but we don't want to do that in
+ // unoptimized code, as that makes complete structor symbol disappear
+ // completely, which degrades debugging experience.
+ // Symbols with private linkage can be safely aliased, so we special case them
+ // here.
+ if (llvm::GlobalValue::isLocalLinkage(Linkage))
+ return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW
+ : StructorCodegen::Alias;
+
+ // Linkonce structors cannot be aliased nor placed in a comdat, so these need
+ // to be emitted separately.
// FIXME: Should we allow available_externally aliases?
- if (!llvm::GlobalAlias::isValidLinkage(Linkage))
- return StructorCodegen::RAUW;
+ if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) ||
+ !llvm::GlobalAlias::isValidLinkage(Linkage))
+ return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW
+ : StructorCodegen::Emit;
if (llvm::GlobalValue::isWeakForLinker(Linkage)) {
// Only ELF and wasm support COMDATs with arbitrary names (C5/D5).
OpenPOWER on IntegriCloud