Skip to content

Commit

Permalink
Don't partition alwaysinline functions (#50766)
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi authored Aug 2, 2023
1 parent d64d336 commit bea8c44
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,18 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
gvars[gvar.second] = i+1;
}
}
for (auto &GV : M.globals()) {
for (auto &GV : M.global_values()) {
if (GV.isDeclaration()) {
if (GVNames.count(GV.getName())) {
bad = true;
dbgs() << "Global " << GV.getName() << " is a declaration but is in partition " << GVNames[GV.getName()] << "\n";
}
} else {
if (auto F = dyn_cast<Function>(&GV)) {
// Ignore alwaysinline functions
if (F->hasFnAttribute(Attribute::AlwaysInline))
continue;
}
if (!GVNames.count(GV.getName())) {
bad = true;
dbgs() << "Global " << GV << " not in any partition\n";
Expand Down Expand Up @@ -809,8 +814,12 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
for (auto &G : M.global_values()) {
if (G.isDeclaration())
continue;
if (isa<Function>(G)) {
partitioner.make(&G, getFunctionWeight(cast<Function>(G)).weight);
if (auto F = dyn_cast<Function>(&G)) {
// alwaysinline functions cannot be partitioned,
// they must remain in every module in order to be inlined
if (F->hasFnAttribute(Attribute::AlwaysInline))
continue;
partitioner.make(&G, getFunctionWeight(*F).weight);
} else {
partitioner.make(&G, 1);
}
Expand Down Expand Up @@ -1109,6 +1118,12 @@ static void materializePreserved(Module &M, Partition &partition) {
for (auto &F : M.functions()) {
if (!F.isDeclaration()) {
if (!Preserve.contains(&F)) {
if (F.hasFnAttribute(Attribute::AlwaysInline)) {
F.setLinkage(GlobalValue::InternalLinkage);
F.setVisibility(GlobalValue::DefaultVisibility);
F.setDSOLocal(true);
continue;
}
F.deleteBody();
F.setLinkage(GlobalValue::ExternalLinkage);
F.setVisibility(GlobalValue::HiddenVisibility);
Expand Down

0 comments on commit bea8c44

Please sign in to comment.