[PATCH] D71441: [Clang FE, SystemZ] Recognize -mpacked-stack CL option
Jonas Paulsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 12 16:16:53 PST 2019
jonpa created this revision.
jonpa added reviewers: uweigand, bkramer.
Recognize -mpacked-stack from the command line and add a function attribute "mpacked-stack"="true" when passed.
I compared building benchmarks with -mpacked-stack vs master with this change in SystemZFrameLowering.cpp:
static bool usePackedStack(MachineFunction &MF) {
- bool HasPackedStackAttr = MF.getFunction().hasFnAttribute("packed-stack");
+ bool HasPackedStackAttr = true; //MF.getFunction().hasFnAttribute("packed-stack");
bool IsVarArg = MF.getFunction().isVarArg();
I found that all files look the same, except for all those who contain the __clang_call_terminate function, which gets the default stack layout even when -mpacked-stack is passed. This seems to relate to exceptions, and my guess is this doesn't need to be handled, but it probably could get the "packed-stack" attribute added somewhere in clang/lib/CodeGen if needed...
Would we need to check in the backend that we don't have the attribute "packed-stack"="false", in case somebody would edit that by hand?
https://reviews.llvm.org/D71441
Files:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/packed-stack.c
Index: clang/test/CodeGen/packed-stack.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/packed-stack.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -mpacked-stack -triple s390x-ibm-linux -emit-llvm \
+// RUN: -o - %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -mpacked-stack -triple x86_64-linux-gnu \
+// RUN: -emit-llvm -o - %s 2>&1 | FileCheck -check-prefix=X86 %s
+
+int foo(void) {
+ return 0;
+}
+
+//CHECK: attributes #0 = { {{.*}}"packed-stack"="true"{{.*}} }
+//X86: error: option '-mpacked-stack' cannot be specified on this target
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1104,6 +1104,7 @@
Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
Opts.CallFEntry = Args.hasArg(OPT_mfentry);
Opts.MNopMCount = Args.hasArg(OPT_mnop_mcount);
+ Opts.PackedStack = Args.hasArg(OPT_mpacked_stack);
Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5014,6 +5014,8 @@
if (TC.SupportsProfiling())
Args.AddLastArg(CmdArgs, options::OPT_mnop_mcount);
+ Args.AddLastArg(CmdArgs, options::OPT_mpacked_stack);
+
if (Args.getLastArg(options::OPT_fapple_kext) ||
(Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
CmdArgs.push_back("-fapple-kext");
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -971,6 +971,14 @@
}
}
+ if (CGM.getCodeGenOpts().PackedStack) {
+ if (getContext().getTargetInfo().getTriple().getArch() !=
+ llvm::Triple::systemz)
+ CGM.getDiags().Report(diag::err_opt_not_valid_on_target)
+ << "-mpacked-stack";
+ Fn->addFnAttr("packed-stack", "true");
+ }
+
if (RetTy->isVoidType()) {
// Void type; nothing to return.
ReturnValue = Address::invalid();
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2474,6 +2474,8 @@
Flags<[CC1Option]>, Group<m_Group>;
def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate mcount/__fentry__ calls as nops. To activate they need to be patched in.">,
Flags<[CC1Option]>, Group<m_Group>;
+def mpacked_stack : Flag<["-"], "mpacked-stack">, HelpText<"Use packed stack layout (SystemZ only).">,
+ Flags<[CC1Option]>, Group<m_Group>;
def mips16 : Flag<["-"], "mips16">, Group<m_mips_Features_Group>;
def mno_mips16 : Flag<["-"], "mno-mips16">, Group<m_mips_Features_Group>;
def mmicromips : Flag<["-"], "mmicromips">, Group<m_mips_Features_Group>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -113,6 +113,7 @@
CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled.
CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled.
+CODEGENOPT(PackedStack , 1, 0) ///< Set when -mpacked-stack is enabled.
CODEGENOPT(LessPreciseFPMAD , 1, 0) ///< Enable less precise MAD instructions to
///< be generated.
CODEGENOPT(PrepareForLTO , 1, 0) ///< Set when -flto is enabled on the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71441.233703.patch
Type: text/x-patch
Size: 3859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191213/083374f3/attachment.bin>
More information about the llvm-commits
mailing list