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

Increase __cilkrts_stack_frame alignment to ABI stack alignment #261

Merged
merged 1 commit into from
Aug 25, 2024
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
7 changes: 6 additions & 1 deletion llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ class OpenCilkABI final : public TapirTarget {
FunctionCallee CilkRTSCilkForGrainsize32 = nullptr;
FunctionCallee CilkRTSCilkForGrainsize64 = nullptr;

MaybeAlign StackFrameAlign{8};
// The alignment of __cilkrts_stack_frame. This value will be increased
// to the ABI-prescribed stack pointer alignment of the module. This has
// no runtime cost. The bitcode file may request even greater alignment
// by defining a variable __cilkrts_stack_frame_align. This may have a
// runtime cost by forcing overalignment of stack pointers.
MaybeAlign StackFrameAlign;

// Accessors for CilkRTS ABI functions. When a bitcode file is loaded, these
// functions should return the function defined in the bitcode file.
Expand Down
13 changes: 10 additions & 3 deletions llvm/lib/Transforms/Tapir/OpenCilkABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void OpenCilkABI::prepareModule() {
}
if (GlobalVariable *AlignVar =
M.getGlobalVariable("__cilkrts_stack_frame_align", true)) {
// StackFrameAlign is undefined here.
StackFrameAlign = AlignVar->getAlign();
// Mark this variable with private linkage, to avoid linker failures when
// compiling with no optimizations.
Expand All @@ -328,6 +329,12 @@ void OpenCilkABI::prepareModule() {
if (StackFrameTy->isOpaque()) {
// Create a dummy __cilkrts_stack_frame structure
StackFrameTy->setBody(Int64Ty);
} else {
// Promote the stack frame structure alignment to the largest convenient
// value given the ABI.
Align ABIStackAlign = M.getDataLayout().getStackAlignment();
if (ABIStackAlign > StackFrameAlign.valueOrOne())
StackFrameAlign = ABIStackAlign;
}
// Create declarations of all CilkRTS functions, and add basic attributes to
// those declarations.
Expand Down Expand Up @@ -875,9 +882,9 @@ void OpenCilkABI::processSubTaskCall(TaskOutlineInfo &TOI, DominatorTree &DT) {
ConstantPointerNull::get(PointerType::getUnqual(C)));
ReplCall->setOperand(ParentSFArgNum, SF);
Argument *ParentSFArg = TOI.Outline->getArg(ParentSFArgNum);
ParentSFArg->addAttr(
Attribute::getWithAlignment(C, StackFrameAlign.valueOrOne()));

if (StackFrameAlign)
ParentSFArg->addAttr(
Attribute::getWithAlignment(C, StackFrameAlign.value()));
// Split the basic block containing the detach replacement just before the
// start of the detach-replacement instructions.
BasicBlock *DetBlock = ReplStart->getParent();
Expand Down
Loading