-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[X86] Place data in large sections for large code model #70265
Conversation
@llvm/pr-subscribers-backend-x86 Author: Arthur Eubanks (aeubanks) ChangesThis allows better interoperability mixing small/medium/large code model Full diff: https://github.com/llvm/llvm-project/pull/70265.diff 2 Files Affected:
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 {{.*}}
|
I have recently changed GCC https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html |
Consider adding a link to https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU |
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.
I'm still of the opinion that large code model data should never contribute toward relocation pressure, but I'll follow gcc here. |
ping |
// restrict this to medium. | ||
if (getCodeModel() != CodeModel::Medium) | ||
|
||
if (getCodeModel() != CodeModel::Medium && getCodeModel() != CodeModel::Large) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What controls the default for the large data size threshold, under the large code model? I think we discussed making it zero, so effectively all globals will be large data under the large code model, which sounds like the right behavior. I don't know which way GCC went on that.
I think we want to keep the .bss/.data/.rodata prefix checks, even under the large code model. I expect folks to mix large and small code, and we don't want to accidentally make small sections large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're relying on the frontend to set the large data threshold in TargetMachine
, otherwise it's just 0
gcc currently defaults to 65536 as the large data threshold for the large code model
The decision is deliberate. Some users may expect |
This allows better interoperability mixing small/medium/large code model code since large code model data can be put into separate large sections. And respect large data threshold under large code model. gcc also does this: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html. See https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU.
This allows better interoperability mixing small/medium/large code model code since large code model data can be put into separate large sections. And respect large data threshold under large code model. gcc also does this: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html. See https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU.
This allows better interoperability mixing small/medium/large code model
code since large code model data can be put into separate large sections.
And respect large data threshold under large code model.
gcc also does this: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html.
See https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU.