Skip to content

Commit bea8c44

Browse files
Don't partition alwaysinline functions (#50766)
1 parent d64d336 commit bea8c44

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/aotcompile.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,18 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
723723
gvars[gvar.second] = i+1;
724724
}
725725
}
726-
for (auto &GV : M.globals()) {
726+
for (auto &GV : M.global_values()) {
727727
if (GV.isDeclaration()) {
728728
if (GVNames.count(GV.getName())) {
729729
bad = true;
730730
dbgs() << "Global " << GV.getName() << " is a declaration but is in partition " << GVNames[GV.getName()] << "\n";
731731
}
732732
} else {
733+
if (auto F = dyn_cast<Function>(&GV)) {
734+
// Ignore alwaysinline functions
735+
if (F->hasFnAttribute(Attribute::AlwaysInline))
736+
continue;
737+
}
733738
if (!GVNames.count(GV.getName())) {
734739
bad = true;
735740
dbgs() << "Global " << GV << " not in any partition\n";
@@ -809,8 +814,12 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
809814
for (auto &G : M.global_values()) {
810815
if (G.isDeclaration())
811816
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);
814823
} else {
815824
partitioner.make(&G, 1);
816825
}
@@ -1109,6 +1118,12 @@ static void materializePreserved(Module &M, Partition &partition) {
11091118
for (auto &F : M.functions()) {
11101119
if (!F.isDeclaration()) {
11111120
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+
}
11121127
F.deleteBody();
11131128
F.setLinkage(GlobalValue::ExternalLinkage);
11141129
F.setVisibility(GlobalValue::HiddenVisibility);

0 commit comments

Comments
 (0)