[llvm] be646e3 - llvm-lto: default Relocation Model should be selected by the TargetMachine.

David Tenty via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 10 14:31:40 PST 2021


Author: Wael Yehia
Date: 2021-03-10T17:31:26-05:00
New Revision: be646e31487b22f7f546fe91a978283581cc6dbb

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

LOG: llvm-lto: default Relocation Model should be selected by the TargetMachine.

Right now, the createTargetMachine function in LTOBackend.cpp (used by llvm-lto, and other components) selects the default Relocation Model when none is specified in the module.
Other components (such as opt and llc) that construct a TargetMachine delegate the decision on the default value to the polymorphic TargetMachine's constructor.

This commit aligns llvm-lto with other components.

Reviewed By: daltenty, fhahn

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

Added: 
    test/tools/llvm-lto/aix.ll

Modified: 
    llvm/lib/LTO/LTOBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 954aa2b85af8b..d49cdd596fee0 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -184,10 +184,10 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
   for (const std::string &A : Conf.MAttrs)
     Features.AddFeature(A);
 
-  Reloc::Model RelocModel;
+  Optional<Reloc::Model> RelocModel = None;
   if (Conf.RelocModel)
     RelocModel = *Conf.RelocModel;
-  else
+  else if (M.getModuleFlag("PIC Level"))
     RelocModel =
         M.getPICLevel() == PICLevel::NotPIC ? Reloc::Static : Reloc::PIC_;
 

diff  --git a/test/tools/llvm-lto/aix.ll b/test/tools/llvm-lto/aix.ll
new file mode 100644
index 0000000000000..6efd98ed9f701
--- /dev/null
+++ b/test/tools/llvm-lto/aix.ll
@@ -0,0 +1,12 @@
+; REQUIRES: powerpc-registered-target
+; RUN: llvm-as < %s > %t1
+; RUN: llvm-lto %t1 | FileCheck %s
+
+target triple = "powerpc-ibm-aix"
+
+define i32 @main() {
+entry:
+  ret i32 42
+}
+; CHECK: Wrote native object file
+


        


More information about the llvm-commits mailing list