[llvm] [X86] Treat all data under large code model as large (PR #70265)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 15:25:11 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: Arthur Eubanks (aeubanks)

<details>
<summary>Changes</summary>

This allows better interoperability mixing small/medium/large code model
code since small code model data won't be mixed with large code model
data.


---
Full diff: https://github.com/llvm/llvm-project/pull/70265.diff


2 Files Affected:

- (modified) llvm/lib/Target/TargetMachine.cpp (+13-6) 
- (modified) llvm/test/CodeGen/X86/code-model-elf-sections.ll (+5-2) 


``````````diff
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 45fb612cb91da19..e11355de2eed3b5 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -42,13 +42,20 @@ TargetMachine::~TargetMachine() = default;
 bool TargetMachine::isLargeData(const GlobalVariable *GV) const {
   if (getTargetTriple().getArch() != Triple::x86_64 || GV->isThreadLocal())
     return false;
-  // Large data under the large code model still needs to be thought about, so
-  // restrict this to medium.
-  if (getCodeModel() != CodeModel::Medium)
+
+  switch (getCodeModel()) {
+  case CodeModel::Large: {
+    return true;
+  }
+  case CodeModel::Medium: {
+    const DataLayout &DL = GV->getParent()->getDataLayout();
+    uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
+    return Size == 0 || Size > LargeDataThreshold;
+  }
+  default: {
     return false;
-  const DataLayout &DL = GV->getParent()->getDataLayout();
-  uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
-  return Size == 0 || Size > LargeDataThreshold;
+  }
+  }
 }
 
 bool TargetMachine::isPositionIndependent() const {
diff --git a/llvm/test/CodeGen/X86/code-model-elf-sections.ll b/llvm/test/CodeGen/X86/code-model-elf-sections.ll
index fe659fa9a46e727..5d02fed05814039 100644
--- a/llvm/test/CodeGen/X86/code-model-elf-sections.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf-sections.ll
@@ -7,14 +7,17 @@
 ; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=80 -o %t
 ; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL
 ; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=large -o %t
-; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL
+; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE
+; Check that the large code model ignores -large-data-threshold.
+; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=large -large-data-threshold=800 -o %t
+; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE
 
 ; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=small -data-sections -o %t
 ; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL-DS
 ; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -data-sections -o %t
 ; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE-DS
 ; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=large -data-sections -o %t
-; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL-DS
+; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE-DS
 
 ; SMALL: .data {{.*}} WA {{.*}}
 ; SMALL: foo {{.*}} WA {{.*}}

``````````

</details>


https://github.com/llvm/llvm-project/pull/70265


More information about the llvm-commits mailing list