[PATCH] D92912: [lld-macho] Add support for -code-model in LTO

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 22:28:21 PST 2020


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added subscribers: steven_wu, hiraditya, inglorion.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Cribbed a similar test from LLD-ELF.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92912

Files:
  lld/MachO/LTO.cpp
  lld/test/MachO/codemodel.ll


Index: lld/test/MachO/codemodel.ll
===================================================================
--- /dev/null
+++ lld/test/MachO/codemodel.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -lSystem %t.o -o %ts -mllvm -code-model=small
+; RUN: %lld -lSystem %t.o -o %tl -mllvm -code-model=large
+; RUN: llvm-objdump -d %ts | FileCheck %s --check-prefix=CHECK-SMALL
+; RUN: llvm-objdump -d %tl | FileCheck %s --check-prefix=CHECK-LARGE
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+ at data = internal constant [0 x i32] []
+
+define i32* @main() nounwind readonly {
+entry:
+; CHECK-SMALL-LABEL: <_main>:
+; CHECK-SMALL:       leaq    [[#]](%rip), %rax
+; CHECK-LARGE-LABEL: <_main>:
+; CHECK-LARGE:       movabsq $[[#]], %rax
+    ret i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0)
+}
Index: lld/MachO/LTO.cpp
===================================================================
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -27,6 +27,7 @@
 static lto::Config createConfig() {
   lto::Config c;
   c.Options = initTargetOptionsFromCodeGenFlags();
+  c.CodeModel = getCodeModelFromCMModel();
   c.CPU = getCPUStr();
   c.MAttrs = getMAttrs();
   return c;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92912.310420.patch
Type: text/x-patch
Size: 1294 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201209/0006e9cf/attachment.bin>


More information about the llvm-commits mailing list