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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 15:23:58 PDT 2023


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

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.


>From e9afa7dcf535a9b26be86bfea900c50499463f8d Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Wed, 25 Oct 2023 15:00:06 -0700
Subject: [PATCH] [X86] Treat all data under large code model as large

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.
---
 llvm/lib/Target/TargetMachine.cpp             | 19 +++++++++++++------
 .../CodeGen/X86/code-model-elf-sections.ll    |  7 +++++--
 2 files changed, 18 insertions(+), 8 deletions(-)

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 {{.*}}



More information about the llvm-commits mailing list