diff options
author | Zequan Wu <zequanwu@google.com> | 2021-04-28 21:25:51 -0700 |
---|---|---|
committer | Zequan Wu <zequanwu@google.com> | 2021-04-29 15:39:30 -0700 |
commit | cab48e2f0e00648ef0494ce114f4e00a3ded330f (patch) | |
tree | 92ee0f177afd896a2eb994b6f4c27e66933f4799 /llvm/lib/IR/Value.cpp | |
parent | be01b091afd820c5784ba960241ea6140529b654 (diff) | |
download | llvm-cab48e2f0e00648ef0494ce114f4e00a3ded330f.zip llvm-cab48e2f0e00648ef0494ce114f4e00a3ded330f.tar.gz llvm-cab48e2f0e00648ef0494ce114f4e00a3ded330f.tar.bz2 |
[CodeGen] don't emit addrsig symbol if it's used only by metadata
Value only used by metadata can be removed from .addrsig table.
This solves the undefined symbol error when enabling addrsig table on COFF LTO.
Differential Revision: https://reviews.llvm.org/D101512
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 47a5be4..8d6918c 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -980,6 +980,27 @@ bool Value::isSwiftError() const { return Alloca->isSwiftError(); } +bool Value::isTransitiveUsedByMetadataOnly() const { + if (use_empty()) + return false; + llvm::SmallVector<const User *, 32> WorkList; + llvm::SmallPtrSet<const User *, 32> Visited; + WorkList.insert(WorkList.begin(), user_begin(), user_end()); + while (!WorkList.empty()) { + const User *U = WorkList.back(); + WorkList.pop_back(); + Visited.insert(U); + // If it is transitively used by a global value or a non-constant value, + // it's obviously not only used by metadata. + if (!isa<Constant>(U) || isa<GlobalValue>(U)) + return false; + for (const User *UU : U->users()) + if (!Visited.count(UU)) + WorkList.push_back(UU); + } + return true; +} + //===----------------------------------------------------------------------===// // ValueHandleBase Class //===----------------------------------------------------------------------===// |