[PATCH] D100498: [ThinLTO] Copy UnnamedAddr when spliting module.
Zequan Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 14 18:29:21 PDT 2021
zequanwu updated this revision to Diff 337600.
zequanwu added a comment.
- Copy function attributes and remove ret/param attributes.
- Add a test case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100498/new/
https://reviews.llvm.org/D100498
Files:
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc.ll
Index: llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc.ll
===================================================================
--- llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc.ll
+++ llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc.ll
@@ -2,9 +2,9 @@
; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s
-; M0: @g = external constant [9 x i8*]{{$}}
-; M1: @g = constant [9 x i8*]
- at g = constant [9 x i8*] [
+; M0: @g = external constant [10 x i8*]{{$}}
+; M1: @g = constant [10 x i8*]
+ at g = constant [10 x i8*] [
i8* bitcast (i64 (i8*)* @ok1 to i8*),
i8* bitcast (i64 (i8*, i64)* @ok2 to i8*),
i8* bitcast (void (i8*)* @wrongtype1 to i8*),
@@ -13,7 +13,8 @@
i8* bitcast (i64 (i8*, i8*)* @wrongtype4 to i8*),
i8* bitcast (i64 (i8*, i128)* @wrongtype5 to i8*),
i8* bitcast (i64 (i8*)* @usesthis to i8*),
- i8* bitcast (i8 (i8*)* @reads to i8*)
+ i8* bitcast (i8 (i8*)* @reads to i8*),
+ i8* bitcast (i8* (i8*, i8)* @attributedFunc to i8*)
], !type !0
; M0: define i64 @ok1
@@ -76,4 +77,11 @@
ret i8 %l
}
+; Check function attributes are copied over splitted module
+; M0: declare dso_local noundef i8* @attributedFunc(i8* noalias, i8 zeroext) unnamed_addr #[[ATTR0:[0-9]+]]
+; M1: declare dso_local void @attributedFunc() unnamed_addr #[[ATTR1:[0-9]+]]
+declare dso_local noundef i8* @attributedFunc(i8* noalias, i8 zeroext) unnamed_addr alwaysinline willreturn
+; M0: attributes #[[ATTR0]] = { alwaysinline willreturn }
+; M1: attributes #[[ATTR1]] = { alwaysinline willreturn }
+
!0 = !{i32 0, !"typeid"}
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===================================================================
--- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -158,7 +158,14 @@
Function *NewF =
Function::Create(EmptyFT, GlobalValue::ExternalLinkage,
F.getAddressSpace(), "", &M);
- NewF->setVisibility(F.getVisibility());
+ // Only copy function attribtues.
+ NewF->copyAttributesFrom(&F);
+ auto Attrs = F.getAttributes();
+ for (unsigned i = 0; i < F.arg_size(); ++i) {
+ NewF->removeParamAttrs(i, Attrs.getParamAttributes(i));
+ }
+ NewF->removeAttributes(AttributeList::ReturnIndex,
+ Attrs.getRetAttributes());
NewF->takeName(&F);
F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
F.eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100498.337600.patch
Type: text/x-patch
Size: 2578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210415/bcf1e08b/attachment.bin>
More information about the llvm-commits
mailing list