Author: Qiongsi Wu
Date: 2023-07-12T13:22:02-04:00
New Revision: 41447f6fdfe4d67bbd130bc6035e66f3fa1ebeff

URL: 
https://github.com/llvm/llvm-project/commit/41447f6fdfe4d67bbd130bc6035e66f3fa1ebeff
DIFF: 
https://github.com/llvm/llvm-project/commit/41447f6fdfe4d67bbd130bc6035e66f3fa1ebeff.diff

LOG: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

`libLTO` currently ignores the `-f[no-]integrated-as` flags. This patch teaches 
`libLTO` to respect them on AIX.

The implementation consists of two parts:

  # Migrate `llc`'s `-no-integrated-as` option to a codegen option so that the 
option is available to `libLTO`/`lld`/`gold`.
  # Teach `clang` to pass `-no-integrated-as` accordingly to `libLTO` depending 
on the `-f[no-]integrated-as` flags.

On platforms other than AIX, the `-f[no-]integrated-as` flags are ignored.

Reviewed By: MaskRay, steven_wu

Differential Revision: https://reviews.llvm.org/D152924

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/CommonArgs.cpp
    clang/test/Driver/lto-aix.c
    llvm/include/llvm/CodeGen/CommandFlags.h
    llvm/lib/CodeGen/CommandFlags.cpp
    llvm/lib/LTO/LTOCodeGenerator.cpp
    llvm/test/tools/llvm-lto/aix.ll
    llvm/tools/llc/llc.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 649d7ddcf8997a..496d4f5e82a663 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -692,6 +692,10 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
   }
 
   if (IsOSAIX) {
+    if (!ToolChain.useIntegratedAs())
+      CmdArgs.push_back(
+          Args.MakeArgString(Twine(PluginOptPrefix) + "-no-integrated-as=1"));
+
     // On AIX, clang assumes strict-dwarf is true if any debug option is
     // specified, unless it is told explicitly not to assume so.
     Arg *A = Args.getLastArg(options::OPT_g_Group);

diff  --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c
index c960d2f9a77755..a07dbd759fa5ff 100644
--- a/clang/test/Driver/lto-aix.c
+++ b/clang/test/Driver/lto-aix.c
@@ -4,7 +4,7 @@
 //
 // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}"
 // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3"
-//
+
 // More opt level option tests
 // RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
 // RUN:   -fuse-ld=ld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s
@@ -26,7 +26,7 @@
 // O1: "-bplugin_opt:-O1"
 // O2: "-bplugin_opt:-O2"
 // O3: "-bplugin_opt:-O3"
-//
+
 // vec-extabi option
 // RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
 // RUN:   -fuse-ld=ld -flto -mabi=vec-extabi -### 2>&1 \
@@ -36,7 +36,7 @@
 //
 // VECEXTABI: "-bplugin_opt:-vec-extabi"
 // NOVECEXTABI-NOT: "-bplugin_opt:-vec-extabi"
-//
+
 // Test debugging options
 // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
 // RUN:   | FileCheck -check-prefix=DBX %s
@@ -67,9 +67,20 @@
 //
 // STRICT:       "-bplugin_opt:-strict-dwarf=true"
 // NOSTRICT-NOT: "-bplugin_opt:-strict-dwarf=true"
-//
+
 // Test cspgo options
 // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld \
 // RUN:   -fcs-profile-generate 2>&1 | FileCheck -check-prefix=CSPGO %s
 //
 // CSPGO: "-bplugin_opt:-cs-profile-generate" 
"-bplugin_opt:-cs-profile-path=default_%m.profraw"
+
+// Test integrated assembler options
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fno-integrated-as \
+// RUN:   -fintegrated-as 2>&1 | FileCheck --check-prefix=INTAS %s
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fintegrated-as \
+// RUN:   -fno-integrated-as 2>&1 | FileCheck --check-prefix=NOINTAS %s
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto 2>&1 \
+// RUN:   | FileCheck --check-prefix=INTAS %s
+//
+// NOINTAS: "-bplugin_opt:-no-integrated-as=1"
+// INTAS-NOT: "-bplugin_opt:-no-integrated-as"

diff  --git a/llvm/include/llvm/CodeGen/CommandFlags.h 
b/llvm/include/llvm/CodeGen/CommandFlags.h
index 27794eb63de0b3..fa10ddd4447dc9 100644
--- a/llvm/include/llvm/CodeGen/CommandFlags.h
+++ b/llvm/include/llvm/CodeGen/CommandFlags.h
@@ -94,6 +94,8 @@ std::string getTrapFuncName();
 
 bool getUseCtors();
 
+bool getDisableIntegratedAS();
+
 bool getRelaxELFRelocations();
 
 bool getDataSections();

diff  --git a/llvm/lib/CodeGen/CommandFlags.cpp 
b/llvm/lib/CodeGen/CommandFlags.cpp
index 59b5decbc808c2..c34a52a6f2de90 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -81,6 +81,7 @@ CGOPT(bool, StackSymbolOrdering)
 CGOPT(bool, StackRealign)
 CGOPT(std::string, TrapFuncName)
 CGOPT(bool, UseCtors)
+CGOPT(bool, DisableIntegratedAS)
 CGOPT(bool, RelaxELFRelocations)
 CGOPT_EXP(bool, DataSections)
 CGOPT_EXP(bool, FunctionSections)
@@ -487,6 +488,11 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
       cl::init(false));
   CGBINDOPT(XCOFFReadOnlyPointers);
 
+  static cl::opt<bool> DisableIntegratedAS(
+      "no-integrated-as", cl::desc("Disable integrated assembler"),
+      cl::init(false));
+  CGBINDOPT(DisableIntegratedAS);
+
 #undef CGBINDOPT
 
   mc::RegisterMCTargetOptionsFlags();
@@ -540,6 +546,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple 
&TheTriple) {
   Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
   Options.StackSymbolOrdering = getStackSymbolOrdering();
   Options.UseInitArray = !getUseCtors();
+  Options.DisableIntegratedAS = getDisableIntegratedAS();
   Options.RelaxELFRelocations = getRelaxELFRelocations();
   Options.DataSections =
       getExplicitDataSections().value_or(TheTriple.hasDefaultDataSections());

diff  --git a/llvm/lib/LTO/LTOCodeGenerator.cpp 
b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 1c955d664b92f1..1402da7fbbd277 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -244,7 +244,7 @@ bool LTOCodeGenerator::writeMergedModules(StringRef Path) {
 
 bool LTOCodeGenerator::useAIXSystemAssembler() {
   const auto &Triple = TargetMach->getTargetTriple();
-  return Triple.isOSAIX();
+  return Triple.isOSAIX() && Config.Options.DisableIntegratedAS;
 }
 
 bool LTOCodeGenerator::runAIXSystemAssembler(SmallString<128> &AssemblyFile) {

diff  --git a/llvm/test/tools/llvm-lto/aix.ll b/llvm/test/tools/llvm-lto/aix.ll
index fa1c3b05032486..3d3dd1e53d7236 100644
--- a/llvm/test/tools/llvm-lto/aix.ll
+++ b/llvm/test/tools/llvm-lto/aix.ll
@@ -1,7 +1,11 @@
-; REQUIRES: system-aix
+; REQUIRES: powerpc-registered-target
+; RUN: rm -rf %t && mkdir %t && cd %t
 ; RUN: llvm-as < %s > %t1
 ; RUN: llvm-lto %t1 | FileCheck %s
 
+; Test system assembler.
+; RUN: %if system-aix %{ llvm-lto -no-integrated-as=1 %t1 | FileCheck %s %}
+
 target triple = "powerpc-ibm-aix"
 
 define i32 @main() {
@@ -9,4 +13,3 @@ entry:
   ret i32 42
 }
 ; CHECK: Wrote native object file
-

diff  --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index a034fda776f194..8934130f99133c 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -106,10 +106,6 @@ static cl::opt<std::string>
                              "'none' means that all ELF features can be used, "
                              "regardless of binutils support"));
 
-static cl::opt<bool>
-NoIntegratedAssembler("no-integrated-as", cl::Hidden,
-                      cl::desc("Disable integrated assembler"));
-
 static cl::opt<bool>
     PreserveComments("preserve-as-comments", cl::Hidden,
                      cl::desc("Preserve Comments in outputted assembly"),
@@ -517,7 +513,6 @@ static int compileModule(char **argv, LLVMContext &Context) 
{
 
     Options.BinutilsVersion =
         TargetMachine::parseBinutilsVersion(BinutilsVersion);
-    Options.DisableIntegratedAS = NoIntegratedAssembler;
     Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
     Options.MCOptions.AsmVerbose = AsmVerbose;
     Options.MCOptions.PreserveAsmComments = PreserveComments;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to