[llvm] [RISCV][docs] GP Relaxation and Small Data Limit (PR #108592)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 10:24:46 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.
----------------
lenary wrote:

I rewrote this several times, and i think the "this" just got left in. I think the sentence is clear enough without it, but I've also updated some later references to `__global_pointer$` with clarifications as well.

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


More information about the llvm-commits mailing list