[llvm] [llc][PPC] Move PIC check into TargetMachine (PR #66727)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 18:34:03 PDT 2023


https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/66727

Matches other code like the code model checking.


>From 226b0fd27b9cee2141aca362439d08bc6df215cd Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Mon, 18 Sep 2023 18:33:05 -0700
Subject: [PATCH] [llc][PPC] Move PIC check into TargetMachine

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 42f052cb15d5cd7..b09975172bf5ecb 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<Reloc::Model> 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 70e08e2513eeb9f..3537baf1cdebecd 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: '<stdin>': 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 0ca06cda20b6e66..0b174afc22ddced 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<TargetMachine>(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<TargetMachine>(TheTarget->createTargetMachine(
         TheTriple.getTriple(), CPUStr, FeaturesStr, Options, RM, CM, OLvl));



More information about the llvm-commits mailing list