@@ -723,13 +723,18 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
723
723
gvars[gvar.second ] = i+1 ;
724
724
}
725
725
}
726
- for (auto &GV : M.globals ()) {
726
+ for (auto &GV : M.global_values ()) {
727
727
if (GV.isDeclaration ()) {
728
728
if (GVNames.count (GV.getName ())) {
729
729
bad = true ;
730
730
dbgs () << " Global " << GV.getName () << " is a declaration but is in partition " << GVNames[GV.getName ()] << " \n " ;
731
731
}
732
732
} else {
733
+ if (auto F = dyn_cast<Function>(&GV)) {
734
+ // Ignore alwaysinline functions
735
+ if (F->hasFnAttribute (Attribute::AlwaysInline))
736
+ continue ;
737
+ }
733
738
if (!GVNames.count (GV.getName ())) {
734
739
bad = true ;
735
740
dbgs () << " Global " << GV << " not in any partition\n " ;
@@ -809,8 +814,12 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
809
814
for (auto &G : M.global_values ()) {
810
815
if (G.isDeclaration ())
811
816
continue ;
812
- if (isa<Function>(G)) {
813
- partitioner.make (&G, getFunctionWeight (cast<Function>(G)).weight );
817
+ if (auto F = dyn_cast<Function>(&G)) {
818
+ // alwaysinline functions cannot be partitioned,
819
+ // they must remain in every module in order to be inlined
820
+ if (F->hasFnAttribute (Attribute::AlwaysInline))
821
+ continue ;
822
+ partitioner.make (&G, getFunctionWeight (*F).weight );
814
823
} else {
815
824
partitioner.make (&G, 1 );
816
825
}
@@ -1109,6 +1118,12 @@ static void materializePreserved(Module &M, Partition &partition) {
1109
1118
for (auto &F : M.functions ()) {
1110
1119
if (!F.isDeclaration ()) {
1111
1120
if (!Preserve.contains (&F)) {
1121
+ if (F.hasFnAttribute (Attribute::AlwaysInline)) {
1122
+ F.setLinkage (GlobalValue::InternalLinkage);
1123
+ F.setVisibility (GlobalValue::DefaultVisibility);
1124
+ F.setDSOLocal (true );
1125
+ continue ;
1126
+ }
1112
1127
F.deleteBody ();
1113
1128
F.setLinkage (GlobalValue::ExternalLinkage);
1114
1129
F.setVisibility (GlobalValue::HiddenVisibility);
0 commit comments