[clang] [FatLTO] output of -ffat-lto-objects -S should be assembly. (PR #79041)

Sean Fertile via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 11:32:07 PST 2024


https://github.com/mandlebug created https://github.com/llvm/llvm-project/pull/79041

Fat lto with -c compiles to an object file with the IR embedded in a section of the object, the combination of fat-lto with -S should then produce an assembly file equivalent of that. The IR output can still be genreated by using both -S and -emit-llvm.

>From d81d2e0f03ca50ceb1b7f7050291d00c0c8c3925 Mon Sep 17 00:00:00 2001
From: Sean Fertile <sd.fertile at gmail.com>
Date: Fri, 19 Jan 2024 15:39:57 -0500
Subject: [PATCH] [FatLTO] output of -ffat-lto-objects -S should be assembly.

Fat lto with -c compiles to an object file with the IR embedded
in a section of the object, the combination of fat-lto with -S should
then produce an assembly file equivalent of that. The IR output can
still be genreated by using both -S and -emit-llvm.
---
 clang/lib/Driver/Driver.cpp         |  7 ++++---
 clang/test/Driver/fat-lto-objects.c | 19 ++++++++++++++++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index da27ca2d28e91a4..7109faa1072de5f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4764,10 +4764,11 @@ Action *Driver::ConstructPhaseAction(
   case phases::Backend: {
     if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
       types::ID Output;
-      if (Args.hasArg(options::OPT_S))
+      if (Args.hasArg(options::OPT_ffat_lto_objects))
+        Output = Args.hasArg(options::OPT_emit_llvm) ? types::TY_LTO_IR
+                                                     : types::TY_PP_Asm;
+      else if (Args.hasArg(options::OPT_S))
         Output = types::TY_LTO_IR;
-      else if (Args.hasArg(options::OPT_ffat_lto_objects))
-        Output = types::TY_PP_Asm;
       else
         Output = types::TY_LTO_BC;
       return C.MakeAction<BackendJobAction>(Input, Output);
diff --git a/clang/test/Driver/fat-lto-objects.c b/clang/test/Driver/fat-lto-objects.c
index e02359db3f0ae0d..203175d61b73d72 100644
--- a/clang/test/Driver/fat-lto-objects.c
+++ b/clang/test/Driver/fat-lto-objects.c
@@ -12,14 +12,27 @@
 // CHECK-CC-S-NOT: -emit-llvm
 // CHECK-CC-S-NOT: -ffat-lto-objects
 
-/// When LTO is enabled, we expect LLVM IR output and -ffat-lto-objects to be passed to cc1.
+/// When fat LTO is enabled with -S, we expect asm output and -ffat-lto-objects to be passed to cc1.
 // RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
-// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
 // CHECK-CC-S-LTO: -cc1
 // CHECK-CC-S-LTO-SAME: -funified-lto
-// CHECK-CC-S-LTO-SAME: -emit-llvm
+// CHECK-CC-S-NOT: -emit-llvm
 // CHECK-CC-S-LTO-SAME: -ffat-lto-objects
 
+/// When fat LTO is enabled with -S and -emit-llvm, we expect IR output and -ffat-lto-objects to be passed to cc1.
+// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-EL-LTO
+// CHECK-CC-S-EL-LTO: -cc1
+// CHECK-CC-S-EL-LTO-SAME: -funified-lto
+// CHECK-CC-S-EL-LTO-SAME: -emit-llvm
+// CHECK-CC-S-EL-LTO-SAME: -ffat-lto-objects
+
+/// When fat LTO is enabled wihtout -S we expect native object output and -ffat-lto-object to be passed to cc1.
+// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-C-LTO
+// CHECK-CC-C-LTO: -cc1
+// CHECK-CC-C-LTO: -funified-lto
+// CHECK-CC-C-LTO: -emit-obj
+// CHECK-CC-C-LTO: -ffat-lto-objects
+
 /// Make sure we don't have a warning for -ffat-lto-objects being unused
 // RUN: %clang --target=x86_64-unknown-linux-gnu -ffat-lto-objects -fdriver-only -Werror -v %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
 // CHECK-CC-NOLTO: -cc1



More information about the cfe-commits mailing list