Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't partition alwaysinline functions #50766

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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