Stack realignment is a tristate. Add -mno-stackrealign to turn off all stack

realignment, even with locals with alignment exceeding the ABI guarantee.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145909 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2011-12-06 03:33:03 +00:00
Родитель 68805fef77
Коммит 4e785c908a
6 изменённых файлов: 29 добавлений и 10 удалений

Просмотреть файл

@ -583,6 +583,7 @@ def mno_red_zone : Flag<"-mno-red-zone">, Group<m_Group>;
def mno_relax_all : Flag<"-mno-relax-all">, Group<m_Group>; def mno_relax_all : Flag<"-mno-relax-all">, Group<m_Group>;
def mno_rtd: Flag<"-mno-rtd">, Group<m_Group>; def mno_rtd: Flag<"-mno-rtd">, Group<m_Group>;
def mno_soft_float : Flag<"-mno-soft-float">, Group<m_Group>; def mno_soft_float : Flag<"-mno-soft-float">, Group<m_Group>;
def mno_stackrealign : Flag<"-mno-stackrealign">, Group<m_Group>;
def mno_sse2 : Flag<"-mno-sse2">, Group<m_x86_Features_Group>; def mno_sse2 : Flag<"-mno-sse2">, Group<m_x86_Features_Group>;
def mno_sse3 : Flag<"-mno-sse3">, Group<m_x86_Features_Group>; def mno_sse3 : Flag<"-mno-sse3">, Group<m_x86_Features_Group>;
def mno_sse4a : Flag<"-mno-sse4a">, Group<m_x86_Features_Group>; def mno_sse4a : Flag<"-mno-sse4a">, Group<m_x86_Features_Group>;

Просмотреть файл

@ -105,8 +105,8 @@ public:
unsigned VerifyModule : 1; /// Control whether the module should be run unsigned VerifyModule : 1; /// Control whether the module should be run
/// through the LLVM Verifier. /// through the LLVM Verifier.
unsigned RealignStack : 1; /// Controls whether stack frame should be unsigned StackRealignment : 1; /// Control whether to permit stack
/// readjusted to the desired alignment. /// realignment.
unsigned StackAlignment; /// Overrides default stack alignment, unsigned StackAlignment; /// Overrides default stack alignment,
/// if not 0. /// if not 0.

Просмотреть файл

@ -289,11 +289,6 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
llvm::TargetOptions Options; llvm::TargetOptions Options;
if (CodeGenOpts.RealignStack)
Options.RealignStack = true;
if (CodeGenOpts.StackAlignment)
Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
// Set frame pointer elimination mode. // Set frame pointer elimination mode.
if (!CodeGenOpts.DisableFPElim) { if (!CodeGenOpts.DisableFPElim) {
Options.NoFramePointerElim = false; Options.NoFramePointerElim = false;
@ -322,6 +317,8 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS; Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath; Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
Options.UseSoftFloat = CodeGenOpts.SoftFloat; Options.UseSoftFloat = CodeGenOpts.SoftFloat;
Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
Options.RealignStack = CodeGenOpts.StackRealignment;
TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU, TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU,
FeaturesStr, Options, FeaturesStr, Options,

Просмотреть файл

@ -1796,8 +1796,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel))); CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
} }
if (Args.hasArg(options::OPT_mstackrealign)) // Translate -mstackrealign
CmdArgs.push_back("-mstackrealign"); if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
false)) {
CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-force-align-stack");
}
if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign,
false)) {
CmdArgs.push_back(Args.MakeArgString("-mstackrealign"));
}
if (Args.hasArg(options::OPT_mstack_alignment)) { if (Args.hasArg(options::OPT_mstack_alignment)) {
StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment));

Просмотреть файл

@ -1114,7 +1114,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file);
Opts.RealignStack = Args.hasArg(OPT_mstackrealign); Opts.StackRealignment = Args.hasArg(OPT_mstackrealign);
if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) { if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) {
StringRef Val = A->getValue(Args); StringRef Val = A->getValue(Args);
Val.getAsInteger(10, Opts.StackAlignment); Val.getAsInteger(10, Opts.StackAlignment);

Просмотреть файл

@ -0,0 +1,12 @@
// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=NORMAL
// NORMAL-NOT: -force-align-stack
// NORMAL: -mstackrealign
// RUN: %clang -### -mstackrealign %s 2>&1 | FileCheck %s -check-prefix=MREALIGN
// MREALIGN: -force-align-stack
// MREALIGN: -mstackrealign
// RUN: %clang -### -mno-stackrealign %s 2>&1 | \
// RUN: FileCheck %s -check-prefix=MNOREALIGN
// MNOREALIGN-NOT: -force-align-stack
// MNOREALIGN-NOT: -mstackrealign