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

Improve handling of LLVM function attributes #49597

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 2 additions & 7 deletions src/llvm-remove-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)

Function *NF = Function::Create(
NFTy, F->getLinkage(), F->getAddressSpace(), Name, &M);
NF->copyAttributesFrom(F);
// no need to copy attributes here, that's done by CloneFunctionInto
VMap[F] = NF;
}

Expand Down Expand Up @@ -356,11 +356,9 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)

// Similarly, copy over and rewrite function bodies
for (Function *F : Functions) {
if (F->isDeclaration())
continue;

Function *NF = cast<Function>(VMap[F]);
LLVM_DEBUG(dbgs() << "Processing function " << NF->getName() << "\n");
// we also need this to run for declarations, or attributes won't be copied

Function::arg_iterator DestI = NF->arg_begin();
for (Function::const_arg_iterator I = F->arg_begin(); I != F->arg_end();
Expand Down Expand Up @@ -410,9 +408,6 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
}
NF->setAttributes(Attrs);

if (F->hasPersonalityFn())
NF->setPersonalityFn(MapValue(F->getPersonalityFn(), VMap));
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this was indeed fixed 8 years ago llvm/llvm-project@2ac0c27


copyComdat(NF, F);

RemoveNoopAddrSpaceCasts(NF);
Expand Down
2 changes: 1 addition & 1 deletion test/llvmpasses/remove-addrspaces.ll
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
}


; COM: check that other function attributes are preserved
; COM: check that function attributes are preserved on declarations too
declare void @convergent_function() #0
attributes #0 = { convergent }
; CHECK: attributes #0 = { convergent }