Skip to content

Commit

Permalink
[libLTO][AIX] Respect -f[no]-integrated-as on AIX
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
qiongsiwu committed Jul 12, 2023
1 parent 1ba514c commit 41447f6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 15 additions & 4 deletions clang/test/Driver/lto-aix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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"
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/CommandFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ std::string getTrapFuncName();

bool getUseCtors();

bool getDisableIntegratedAS();

bool getRelaxELFRelocations();

bool getDataSections();
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/CodeGen/CommandFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions llvm/test/tools/llvm-lto/aix.ll
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
; 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() {
entry:
ret i32 42
}
; CHECK: Wrote native object file

5 changes: 0 additions & 5 deletions llvm/tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 41447f6

Please sign in to comment.