aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ModuleSummaryIndex.cpp
diff options
context:
space:
mode:
authorevgeny <eleviant@accesssoftek.com>2020-01-15 19:29:01 +0300
committerevgeny <eleviant@accesssoftek.com>2020-01-15 19:29:01 +0300
commit10cadee5ce86e80d7486855199d329951f38af01 (patch)
tree9af9164ab50e8b7cee108cbe50f0473e9b1fd09c /llvm/lib/IR/ModuleSummaryIndex.cpp
parent3f3017e162ec4208399dcf633c99bdac788c06fd (diff)
downloadllvm-10cadee5ce86e80d7486855199d329951f38af01.zip
llvm-10cadee5ce86e80d7486855199d329951f38af01.tar.gz
llvm-10cadee5ce86e80d7486855199d329951f38af01.tar.bz2
[ThinLTO] Always import constants
This patch imports constant variables even when they can't be internalized (which results in promotion). This offers some extra constant folding opportunities. Differential revision: https://reviews.llvm.org/D70404
Diffstat (limited to 'llvm/lib/IR/ModuleSummaryIndex.cpp')
-rw-r--r--llvm/lib/IR/ModuleSummaryIndex.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp
index 180f9626..301df9a 100644
--- a/llvm/lib/IR/ModuleSummaryIndex.cpp
+++ b/llvm/lib/IR/ModuleSummaryIndex.cpp
@@ -221,7 +221,8 @@ bool ModuleSummaryIndex::canImportGlobalVar(GlobalValueSummary *S,
// c) Link error (external declaration with internal definition).
// However we do not promote objects referenced by writeonly GV
// initializer by means of converting it to 'zeroinitializer'
- return !isReadOnly(GVS) && !isWriteOnly(GVS) && GVS->refs().size();
+ return !GVS->isConstant() && !isReadOnly(GVS) && !isWriteOnly(GVS) &&
+ GVS->refs().size();
};
auto *GVS = cast<GlobalVarSummary>(S->getBaseObject());
@@ -405,6 +406,12 @@ static bool hasWriteOnlyFlag(const GlobalValueSummary *S) {
return false;
}
+static bool hasConstantFlag(const GlobalValueSummary *S) {
+ if (auto *GVS = dyn_cast<GlobalVarSummary>(S))
+ return GVS->isConstant();
+ return false;
+}
+
void ModuleSummaryIndex::exportToDot(
raw_ostream &OS,
const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) const {
@@ -482,6 +489,8 @@ void ModuleSummaryIndex::exportToDot(
A.addComment("immutable");
if (Flags.Live && hasWriteOnlyFlag(SummaryIt.second))
A.addComment("writeOnly");
+ if (Flags.Live && hasConstantFlag(SummaryIt.second))
+ A.addComment("constant");
}
if (Flags.DSOLocal)
A.addComment("dsoLocal");