[flang-commits] [flang] [clang] [Flang][Clang] Add support for frame pointers in Flang (PR #72146)

via flang-commits flang-commits at lists.llvm.org
Mon Nov 13 10:18:17 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff ad20a9e1a15d1694f7ab3d878bcfaab3d52c5abf 0b0f02eab4dc02adf79461bc865be6f7580938cf -- clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Flang.cpp flang/include/flang/Frontend/CodeGenOptions.h flang/include/flang/Tools/CrossToolHelpers.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Frontend/FrontendActions.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f81bca1436..f72aa839b5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -123,7 +123,7 @@ static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args,
     return !clang::driver::tools::areOptimizationsEnabled(Args);
   }
 
-  //if (Triple.isOSLinux() || Triple.getOS() == llvm::Triple::CloudABI ||
+  // if (Triple.isOSLinux() || Triple.getOS() == llvm::Triple::CloudABI ||
   if (Triple.isOSLinux() || Triple.isOSHurd()) {
     switch (Triple.getArch()) {
     // Don't use a frame pointer on linux if optimizing for certain targets.
@@ -176,7 +176,7 @@ static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
   }
 }
 
-clang::CodeGenOptions::FramePointerKind 
+clang::CodeGenOptions::FramePointerKind
 getFramePointerKind(const llvm::opt::ArgList &Args,
                     const llvm::Triple &Triple) {
   // We have 4 states:
@@ -211,7 +211,6 @@ getFramePointerKind(const llvm::opt::ArgList &Args,
   return clang::CodeGenOptions::FramePointerKind::None;
 }
 
-
 static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs,
                                const StringRef PluginOptPrefix) {
   if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h
index abe8948c53..25d68345a9 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -216,7 +216,7 @@ void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
 } // end namespace driver
 } // end namespace clang
 
-clang::CodeGenOptions::FramePointerKind getFramePointerKind(
-    const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
+clang::CodeGenOptions::FramePointerKind
+getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
 
 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index d53bed8e6c..0b584941ec 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -608,7 +608,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
 
   CodeGenOptions::FramePointerKind FPKeepKind =
-    getFramePointerKind(Args, Triple);
+      getFramePointerKind(Args, Triple);
 
   const char *FPKeepKindStr = nullptr;
   switch (FPKeepKind) {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h
index 9ccd567678..8caf8c7059 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -49,12 +49,12 @@ protected:
 class CodeGenOptions : public CodeGenOptionsBase {
 
 public:
-  //Added
+  // Added
   ///*
   enum class FramePointerKind {
-    None,        // Omit all frame pointers.
-    NonLeaf,     // Keep non-leaf frame pointers.
-    All,         // Keep all frame pointers.
+    None,    // Omit all frame pointers.
+    NonLeaf, // Keep non-leaf frame pointers.
+    All,     // Keep all frame pointers.
   };
 
   static llvm::StringRef getFramePointerKindName(FramePointerKind Kind) {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 4340981ae9..ca000370c8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -250,14 +250,13 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   if (const llvm::opt::Arg *a =
           args.getLastArg(clang::driver::options::OPT_mframe_pointer_EQ)) {
     llvm::StringRef s = a->getValue();
-    assert(s == "none" || s == "non-leaf"|| s == "all");
+    assert(s == "none" || s == "non-leaf" || s == "all");
     if (s == "none")
       opts.setFramePointer(CodeGenOptions::FramePointerKind::None);
+    else if (s == "non-leaf")
+      opts.setFramePointer(CodeGenOptions::FramePointerKind::NonLeaf);
     else
-      if (s == "non-leaf")
-        opts.setFramePointer(CodeGenOptions::FramePointerKind::NonLeaf);
-      else
-        opts.setFramePointer(CodeGenOptions::FramePointerKind::All);
+      opts.setFramePointer(CodeGenOptions::FramePointerKind::All);
   }
 
   for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 06273a07e8..56969dd914 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -783,11 +783,10 @@ void CodeGenAction::generateLLVMIR() {
       llvmModule->setPIELevel(
           static_cast<llvm::PIELevel::Level>(opts.PICLevel));
   }
-  
+
   // Set FramePointer LLVM module flag.
   llvmModule->setFramePointer(
-    static_cast<llvm::FramePointerKind>(opts.getFramePointer()));
-
+      static_cast<llvm::FramePointerKind>(opts.getFramePointer()));
 }
 
 bool CodeGenAction::setUpTargetMachine() {

``````````

</details>


https://github.com/llvm/llvm-project/pull/72146


More information about the flang-commits mailing list