[PATCH] D137441: [IR] Allow available_externally GlobalAlias
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 4 09:46:12 PDT 2022
MaskRay created this revision.
MaskRay added reviewers: rnk, tejohnson, xur, nikic.
Herald added subscribers: jeroen.dobbelaere, StephenFan, jdoerfert, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
GlobalVariable and Function can be available_externally. GlobalAlias is used
similarly. Allowing available_externally is a natural extension and helps
ThinLTO discard GlobalAlias in a non-prevailing COMDAT (see D135427 <https://reviews.llvm.org/D135427>).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137441
Files:
llvm/docs/LangRef.rst
llvm/include/llvm/IR/GlobalAlias.h
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/alias.ll
Index: llvm/test/Verifier/alias.ll
===================================================================
--- llvm/test/Verifier/alias.ll
+++ llvm/test/Verifier/alias.ll
@@ -1,4 +1,4 @@
-; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=Alias
declare void @f()
@@ -31,3 +31,7 @@
@test3_c = alias i32, i32* @test3_b
; CHECK: Alias cannot point to an interposable alias
; CHECK-NEXT: i32* @test3_c
+
+ at test4_a = available_externally alias i32, i32* @test3_a
+ at test4_b = available_externally alias void(), void()* @f2
+ at test4_c = available_externally alias i32, i32* @test4_a
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -816,8 +816,8 @@
void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited,
const GlobalAlias &GA, const Constant &C) {
if (const auto *GV = dyn_cast<GlobalValue>(&C)) {
- Check(!GV->isDeclarationForLinker(), "Alias must point to a definition",
- &GA);
+ Check(GA.hasAvailableExternallyLinkage() || !GV->isDeclarationForLinker(),
+ "Alias must point to a definition", &GA);
if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
Check(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA);
@@ -844,8 +844,10 @@
}
void Verifier::visitGlobalAlias(const GlobalAlias &GA) {
- Check(GlobalAlias::isValidLinkage(GA.getLinkage()),
- "Alias should have private, internal, linkonce, weak, linkonce_odr, "
+ Check(GlobalAlias::isValidLinkage(GA.getLinkage()) ||
+ GA.hasAvailableExternallyLinkage(),
+ "Alias should have available_externally, private, internal, linkonce, "
+ "weak, linkonce_odr, "
"weak_odr, or external linkage!",
&GA);
const Constant *Aliasee = GA.getAliasee();
Index: llvm/include/llvm/IR/GlobalAlias.h
===================================================================
--- llvm/include/llvm/IR/GlobalAlias.h
+++ llvm/include/llvm/IR/GlobalAlias.h
@@ -93,8 +93,8 @@
}
static bool isValidLinkage(LinkageTypes L) {
- return isExternalLinkage(L) || isLocalLinkage(L) ||
- isWeakLinkage(L) || isLinkOnceLinkage(L);
+ return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
+ isLinkOnceLinkage(L) || isAvailableExternallyLinkage(L);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -886,8 +886,9 @@
[, partition "name"]
The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
-``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
-might not correctly handle dropping a weak symbol that is aliased.
+``linkonce_odr``, ``weak_odr``, ``external``, ``available_externally``. Note
+that some system linkers might not correctly handle dropping a weak symbol that
+is aliased.
Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137441.473267.patch
Type: text/x-patch
Size: 3315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/836db38e/attachment.bin>
More information about the llvm-commits
mailing list