Skip to content

Commit c9dee81

Browse files
VoxSciurorumneboat
authored andcommitted
Increase __cilkrts_stack_frame alignment to ABI alignment of stack pointer.
All the __cilkrts_stack_frame objects are aligned on the stack. There is no cost to increasing their alignment and the compiler might generate better code. This alignment is only used within a module. The runtime will use whatever value is declared in C code.
1 parent 21d8fe4 commit c9dee81

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ class OpenCilkABI final : public TapirTarget {
6060
FunctionCallee CilkRTSCilkForGrainsize32 = nullptr;
6161
FunctionCallee CilkRTSCilkForGrainsize64 = nullptr;
6262

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

6570
// Accessors for CilkRTS ABI functions. When a bitcode file is loaded, these
6671
// functions should return the function defined in the bitcode file.

llvm/lib/Transforms/Tapir/OpenCilkABI.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ void OpenCilkABI::prepareModule() {
309309
}
310310
if (GlobalVariable *AlignVar =
311311
M.getGlobalVariable("__cilkrts_stack_frame_align", true)) {
312+
// StackFrameAlign is undefined here.
312313
StackFrameAlign = AlignVar->getAlign();
313314
// Mark this variable with private linkage, to avoid linker failures when
314315
// compiling with no optimizations.
@@ -328,6 +329,12 @@ void OpenCilkABI::prepareModule() {
328329
if (StackFrameTy->isOpaque()) {
329330
// Create a dummy __cilkrts_stack_frame structure
330331
StackFrameTy->setBody(Int64Ty);
332+
} else {
333+
// Promote the stack frame structure alignment to the largest convenient
334+
// value given the ABI.
335+
Align ABIStackAlign = M.getDataLayout().getStackAlignment();
336+
if (ABIStackAlign > StackFrameAlign.valueOrOne())
337+
StackFrameAlign = ABIStackAlign;
331338
}
332339
// Create declarations of all CilkRTS functions, and add basic attributes to
333340
// those declarations.
@@ -875,9 +882,9 @@ void OpenCilkABI::processSubTaskCall(TaskOutlineInfo &TOI, DominatorTree &DT) {
875882
ConstantPointerNull::get(PointerType::getUnqual(C)));
876883
ReplCall->setOperand(ParentSFArgNum, SF);
877884
Argument *ParentSFArg = TOI.Outline->getArg(ParentSFArgNum);
878-
ParentSFArg->addAttr(
879-
Attribute::getWithAlignment(C, StackFrameAlign.valueOrOne()));
880-
885+
if (StackFrameAlign)
886+
ParentSFArg->addAttr(
887+
Attribute::getWithAlignment(C, StackFrameAlign.value()));
881888
// Split the basic block containing the detach replacement just before the
882889
// start of the detach-replacement instructions.
883890
BasicBlock *DetBlock = ReplStart->getParent();

0 commit comments

Comments
 (0)