diff --git a/llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h b/llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h index 24cccd19130e..217cce173daf 100644 --- a/llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h +++ b/llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h @@ -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. diff --git a/llvm/lib/Transforms/Tapir/OpenCilkABI.cpp b/llvm/lib/Transforms/Tapir/OpenCilkABI.cpp index 7a3e11c3ca31..6fe6cdc8a151 100644 --- a/llvm/lib/Transforms/Tapir/OpenCilkABI.cpp +++ b/llvm/lib/Transforms/Tapir/OpenCilkABI.cpp @@ -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. @@ -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. @@ -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();