From 5e4ec53b8efaa2a5215dd68f970d3c913ce07a20 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Mon, 16 Oct 2023 10:41:20 -0700 Subject: [PATCH] [llc][PPC] Move PIC check into TargetMachine (#66727) Matches other code like the code model checking. --- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp | 5 +++-- llvm/test/tools/llc/aix-pic-setting.ll | 2 +- llvm/tools/llc/llc.cpp | 14 -------------- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp index 42f052cb15d5cd..b09975172bf5ec 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -265,8 +265,9 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, static Reloc::Model getEffectiveRelocModel(const Triple &TT, std::optional RM) { - assert((!TT.isOSAIX() || !RM || *RM == Reloc::PIC_) && - "Invalid relocation model for AIX."); + if (TT.isOSAIX() && RM && *RM != Reloc::PIC_) + report_fatal_error("invalid relocation model, AIX only supports PIC", + false); if (RM) return *RM; diff --git a/llvm/test/tools/llc/aix-pic-setting.ll b/llvm/test/tools/llc/aix-pic-setting.ll index 70e08e2513eeb9..3537baf1cdebec 100644 --- a/llvm/test/tools/llc/aix-pic-setting.ll +++ b/llvm/test/tools/llc/aix-pic-setting.ll @@ -6,4 +6,4 @@ ; RUN: not llc -mtriple=powerpc64-ibm-aix --relocation-model=ropi-rwpi < %s 2>&1 | FileCheck --check-prefix=CHECK-NON-PIC %s ; CHECK-NOT: {{.}} -; CHECK-NON-PIC: error: '': invalid relocation model, AIX only supports PIC +; CHECK-NON-PIC: invalid relocation model, AIX only supports PIC diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 0ca06cda20b6e6..0b174afc22ddce 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -558,12 +558,6 @@ static int compileModule(char **argv, LLVMContext &Context) { exit(1); } - // On AIX, setting the relocation model to anything other than PIC is - // considered a user error. - if (TheTriple.isOSAIX() && RM && *RM != Reloc::PIC_) - reportError("invalid relocation model, AIX only supports PIC", - InputFilename); - InitializeOptions(TheTriple); Target = std::unique_ptr(TheTarget->createTargetMachine( TheTriple.getTriple(), CPUStr, FeaturesStr, Options, RM, CM, OLvl)); @@ -607,14 +601,6 @@ static int compileModule(char **argv, LLVMContext &Context) { return 1; } - // On AIX, setting the relocation model to anything other than PIC is - // considered a user error. - if (TheTriple.isOSAIX() && RM && *RM != Reloc::PIC_) { - WithColor::error(errs(), argv[0]) - << "invalid relocation model, AIX only supports PIC.\n"; - return 1; - } - InitializeOptions(TheTriple); Target = std::unique_ptr(TheTarget->createTargetMachine( TheTriple.getTriple(), CPUStr, FeaturesStr, Options, RM, CM, OLvl));