aboutsummaryrefslogtreecommitdiff
path: root/llvm/docs/LangRef.rst
diff options
context:
space:
mode:
authorhev <wangrui@loongson.cn>2023-12-05 10:42:53 +0900
committerGitHub <noreply@github.com>2023-12-05 09:42:53 +0800
commita8874cf50bb676facb4429234dff7774e579faef (patch)
tree6be8c35a41ca83803dcbf9efc37457ab014c9945 /llvm/docs/LangRef.rst
parent192439db6e3fcccf98c850bda1b970a11c590bbb (diff)
downloadllvm-a8874cf50bb676facb4429234dff7774e579faef.zip
llvm-a8874cf50bb676facb4429234dff7774e579faef.tar.gz
llvm-a8874cf50bb676facb4429234dff7774e579faef.tar.bz2
[llvm][IR] Add per-global code model attribute (#72077)
This adds a per-global code model attribute, which can override the target's code model to access global variables. Suggested-by: Arthur Eubanks <aeubanks@google.com> Link: https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816 Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
Diffstat (limited to 'llvm/docs/LangRef.rst')
-rw-r--r--llvm/docs/LangRef.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 4bd19a3..cf9b33a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -705,6 +705,13 @@ information. Attaching section information to an external declaration is an
assertion that its definition is located in the specified section. If the
definition is located in a different section, the behavior is undefined.
+LLVM allows an explicit code model to be specified for globals. If the
+target supports it, it will emit globals in the code model specified,
+overriding the code model used to compile the translation unit.
+The allowed values are "tiny", "small", "kernel", "medium", "large".
+This may be extended in the future to specify global data layout that
+doesn't cleanly fit into a specific code model.
+
By default, global initializers are optimized by assuming that global
variables defined within the module are not modified from their
initial values before the start of the global initializer. This is
@@ -761,6 +768,7 @@ Syntax::
<global | constant> <Type> [<InitializerConstant>]
[, section "name"] [, partition "name"]
[, comdat [($name)]] [, align <Alignment>]
+ [, code_model "model"]
[, no_sanitize_address] [, no_sanitize_hwaddress]
[, sanitize_address_dyninit] [, sanitize_memtag]
(, !name !N)*
@@ -778,6 +786,13 @@ The following example just declares a global variable
@G = external global i32
+The following example defines a global variable with the
+``large`` code model:
+
+.. code-block:: llvm
+
+ @G = internal global i32 0, code_model "large"
+
The following example defines a thread-local global with the
``initialexec`` TLS model: