[llvm] [RISCV][docs] GP Relaxation and Small Data Limit (PR #108592)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 09:15:49 PDT 2024
================
@@ -431,3 +431,26 @@ line. This currently applies to the following extensions:
* ``Zvksg``
* ``Zvksh``
* ``Zvkt``
+
+Global Pointer (GP) Relaxation and the Small Data Limit
+=======================================================
+
+Some of the RISC-V psABIs reserve ``gp`` (``x3``) for use as a "Global Pointer", to make generating data addresses more efficient.
+
+To use this functionality, you need to:
+* not be using the ``gp`` register for any other uses -- some platforms use it for other things;
+* compile your objects with Clang's ``-mrelax`` option, to enable relaxation annotations on relocatable objects; and
+* be compiling for an executable (not a shared library); and
+* use LLD's ``--relax-gp`` option.
+
+LLD will relax (rewrite) any code sequences that materialize an address within 2048 bytes of this ``__global_pointer$`` (which will be defined if it does not already exist) to instead generate the address using ``gp`` and the correct (signed) 12-bit immediate. This usually saves at least one instruction compared to materialising a full 32-bit address value.
----------------
michaelmaitland wrote:
> this ``__global_pointer$``
I think this this the first time you mention `__global_pointer$` but the word `this` assumes that you had mentioned it before. Are you missing the introduction of this variable in the explanation?
https://github.com/llvm/llvm-project/pull/108592
More information about the llvm-commits
mailing list